Skip to content

Commit

Permalink
enhanced decompiler
Browse files Browse the repository at this point in the history
- added decompile config options min_target_ticks_on and max_duration_to_keep
- removed 'multiple option' from the statistics in ALDA decompilation
- removed 'skipped rests' from quality score calculation (it's still in the statistics but without sub score)
- enhanced printing/ignoring of skipped rests in the output file, based on the configuration
- replaced tabs by spaces in MidicaPL decompilation
- treating text areas like text fields regarding printable key bindings
- renamed the decompile key bindings and made them configurable
- #58
  • Loading branch information
truj committed Jul 24, 2020
1 parent 77f06ae commit aaec96b
Show file tree
Hide file tree
Showing 9 changed files with 1,069 additions and 1,002 deletions.
Binary file modified midica.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/org/midica/Midica.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Midica {
public static final int VERSION_MINOR = 2;

/** UNIX timestamp of the last commit */
public static final int COMMIT_TIME = 1594050304;
public static final int COMMIT_TIME = 1595609859;

/** Branch name. Automatically changed by precommit.pl */
public static final String BRANCH = "decompile-optimization";
Expand Down
874 changes: 440 additions & 434 deletions src/org/midica/config/Config.java

Large diffs are not rendered by default.

1,018 changes: 515 additions & 503 deletions src/org/midica/config/Dict.java

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/org/midica/config/KeyBindingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ private void rememberTabBindings(String id) {
*
* A key must be ignored, if:
*
* - a text field is currently focused; and
* - a text field or text area is currently focused; and
* - the pressed key is printable; and
* - there are no modifiers or only SHIFT; and
* - the key is NOT the SPACE bar
Expand All @@ -723,9 +723,9 @@ private void rememberTabBindings(String id) {
*/
private boolean mustIgnore(ActionEvent e) {

// no text field is focused? - don't ignore
// no text field/area is focused? - don't ignore
Component focusOwner = window.getFocusOwner();
if ( ! (focusOwner instanceof JTextField) )
if (! (focusOwner instanceof JTextField || focusOwner instanceof JTextArea))
return false;

// special key pressed (e.g. F5)? - don't ignore
Expand Down
43 changes: 23 additions & 20 deletions src/org/midica/file/write/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ public abstract class Decompiler extends Exporter {
public static final boolean DEFAULT_MUST_ADD_STATISTICS = true;
public static final boolean DEFAULT_MUST_ADD_STRATEGY_STAT = true;
public static final byte DEFAULT_LENGTH_STRATEGY = STRATEGY_NEXT_DURATION_PRESS;
public static final long DEFAULT_MAX_TARGET_TICKS_ON = 3840; // 2 full notes
public static final float DEFAULT_MIN_DURATION_TO_KEEP = 0.05f;
public static final long DEFAULT_LENGTH_TICK_TOLERANCE = 2;
public static final float DEFAULT_DURATION_RATIO_TOLERANCE = 0.014f;
public static final long DEFAULT_MIN_TARGET_TICKS_ON = 60; // /32 (32th note)
public static final long DEFAULT_MAX_TARGET_TICKS_ON = 3840; // *2 (2 full notes)
public static final float DEFAULT_MIN_DURATION_TO_KEEP = 0.2f; // 20%
public static final float DEFAULT_MAX_DURATION_TO_KEEP = 1.1f; // 110%
public static final long DEFAULT_LENGTH_TICK_TOLERANCE = 5;
public static final float DEFAULT_DURATION_RATIO_TOLERANCE = 0.15f;
public static final boolean DEFAULT_USE_PRE_DEFINED_CHORDS = true;
public static final long DEFAULT_CHORD_NOTE_ON_TOLERANCE = 0;
public static final long DEFAULT_CHORD_NOTE_OFF_TOLERANCE = 0;
public static final long DEFAULT_CHORD_VELOCITY_TOLERANCE = 0;
public static final long DEFAULT_CHORD_NOTE_ON_TOLERANCE = 3;
public static final long DEFAULT_CHORD_NOTE_OFF_TOLERANCE = 20;
public static final long DEFAULT_CHORD_VELOCITY_TOLERANCE = 5;
public static final boolean DEFAULT_USE_DOTTED_NOTES = true;
public static final boolean DEFAULT_USE_DOTTED_RESTS = true;
public static final boolean DEFAULT_USE_TRIPLETTED_NOTES = true;
Expand All @@ -141,8 +143,11 @@ public abstract class Decompiler extends Exporter {
protected static boolean MUST_ADD_STRATEGY_STAT = DEFAULT_MUST_ADD_STRATEGY_STAT;
protected static byte LENGTH_STRATEGY = DEFAULT_LENGTH_STRATEGY;
protected static long MAX_TARGET_TICKS_ON = DEFAULT_MAX_TARGET_TICKS_ON;
protected static long MIN_TARGET_TICKS_ON = DEFAULT_MIN_TARGET_TICKS_ON;
protected static long MIN_SOURCE_TICKS_ON = 0L;
protected static long MAX_SOURCE_TICKS_ON = 0L;
protected static float MIN_DURATION_TO_KEEP = DEFAULT_MIN_DURATION_TO_KEEP;
protected static float MAX_DURATION_TO_KEEP = DEFAULT_MAX_DURATION_TO_KEEP;
protected static long LENGTH_TICK_TOLERANCE = DEFAULT_LENGTH_TICK_TOLERANCE;
protected static float DURATION_RATIO_TOLERANCE = DEFAULT_DURATION_RATIO_TOLERANCE;
protected static boolean USE_PRE_DEFINED_CHORDS = DEFAULT_USE_PRE_DEFINED_CHORDS;
Expand Down Expand Up @@ -363,8 +368,10 @@ private void refreshConfig() {
MUST_ADD_STATISTICS = Boolean.parseBoolean( sessionConfig.get(Config.DC_MUST_ADD_STATISTICS) );
MUST_ADD_STRATEGY_STAT = Boolean.parseBoolean( sessionConfig.get(Config.DC_MUST_ADD_STRATEGY_STAT) );
LENGTH_STRATEGY = Byte.parseByte( sessionConfig.get(Config.DC_LENGTH_STRATEGY) );
MIN_TARGET_TICKS_ON = Long.parseLong( sessionConfig.get(Config.DC_MIN_TARGET_TICKS_ON) );
MAX_TARGET_TICKS_ON = Long.parseLong( sessionConfig.get(Config.DC_MAX_TARGET_TICKS_ON) );
MIN_DURATION_TO_KEEP = Float.parseFloat( sessionConfig.get(Config.DC_MIN_DURATION_TO_KEEP) );
MAX_DURATION_TO_KEEP = Float.parseFloat( sessionConfig.get(Config.DC_MAX_DURATION_TO_KEEP) );
LENGTH_TICK_TOLERANCE = Long.parseLong( sessionConfig.get(Config.DC_LENGTH_TICK_TOLERANCE) );
DURATION_RATIO_TOLERANCE = Float.parseFloat( sessionConfig.get(Config.DC_DURATION_RATIO_TOLERANCE) );
USE_PRE_DEFINED_CHORDS = Boolean.parseBoolean( sessionConfig.get(Config.DC_USE_PRE_DEFINED_CHORDS) );
Expand All @@ -380,6 +387,7 @@ private void refreshConfig() {
EXTRA_GLOBALS = DecompileConfigController.getExtraGlobalTicks();

// apply indirect configuration
MIN_SOURCE_TICKS_ON = (MIN_TARGET_TICKS_ON * sourceResolution * 10 + 5) / (targetResolution * 10);
MAX_SOURCE_TICKS_ON = (MAX_TARGET_TICKS_ON * sourceResolution * 10 + 5) / (targetResolution * 10);
}

Expand Down Expand Up @@ -425,8 +433,6 @@ private void initStatistics() {
/**
* Initializes and resets the instruments structures so that
* their configurations can be tracked.
*
* Also removes instrument switches that are never used by any note-ONs.
*/
private void initInstruments() {
instrumentsByName = new TreeMap<>();
Expand Down Expand Up @@ -1333,7 +1339,7 @@ protected long[] getNoteLengthProperties(long onTick, long offTick, byte channel
float durationDiff = oldDuration > durationByDur ? oldDuration - durationByDur : durationByDur - oldDuration;
boolean canUseByDur = durationDiff < DURATION_RATIO_TOLERANCE;
durationByDur = oldDuration;
if (durationByDur < MIN_DURATION_TO_KEEP) {
if (durationByDur < MIN_DURATION_TO_KEEP || durationByDur > MAX_DURATION_TO_KEEP) {
canUseByDur = false;
}

Expand All @@ -1347,7 +1353,7 @@ protected long[] getNoteLengthProperties(long onTick, long offTick, byte channel
durationByOn = calculateDuration(noteTicksByOn, pressTicks);
}
boolean canUseNextOn = noteTicksByOn > 0 && durationByOn > 0;
if (noteTicksByOn > MAX_SOURCE_TICKS_ON) {
if (noteTicksByOn < MIN_SOURCE_TICKS_ON || noteTicksByOn > MAX_SOURCE_TICKS_ON) {
canUseNextOn = false;
}

Expand Down Expand Up @@ -1602,13 +1608,10 @@ private String createQualityStatsPart(TreeMap<Byte,Integer> subStat) {

if (rests > 0) {

// rests skipped
// rests skipped - only for information, no sub score
double restsSkipped = ((double) subStat.get(STAT_REST_SKIPPED)) / ((double) rests);
restsSkipped *= 100;
subScore = 100.0D - restsSkipped;
addQualityDetailsLine(stats, "Skipped:", subStat.get(STAT_REST_SKIPPED) + "", restsSkipped, subScore);
markerCount++;
markerSum += subScore;
addQualityDetailsLine(stats, "Skipped:", subStat.get(STAT_REST_SKIPPED) + "", restsSkipped, null);

// rest summands
int summands = subStat.get(STAT_REST_SUMMANDS);
Expand Down Expand Up @@ -1712,9 +1715,9 @@ private String createQualityStatsPart(TreeMap<Byte,Integer> subStat) {
* @param name which kind of sub score (e.g. Summands, Triplets, ...)
* @param count number of occurrences
* @param percentage percentage of occurrences
* @param subScore sub score to be added
* @param subScore sub score to be added (or **null**, if no sub score is used)
*/
private void addQualityDetailsLine(StringBuilder stats, String name, String count, double percentage, double subScore) {
private void addQualityDetailsLine(StringBuilder stats, String name, String count, double percentage, Double subScore) {
if (! MUST_ADD_STATISTICS)
return;

Expand All @@ -1728,7 +1731,7 @@ private void addQualityDetailsLine(StringBuilder stats, String name, String coun
)
);

if (MUST_ADD_QUALITY_SCORE) {
if (MUST_ADD_QUALITY_SCORE && subScore != null) {
stats.append(" Sub Score: "
+ String.format(
"%1$10s",
Expand Down Expand Up @@ -1873,7 +1876,7 @@ protected String createTickDescription(long tick, boolean withCommentSymbol) {
*
* @return comment symbol.
*/
private String getCommentSymbol() {
protected String getCommentSymbol() {
if (ALDA == format)
return "#";
return MidicaPLParser.COMMENT;
Expand Down
4 changes: 4 additions & 0 deletions src/org/midica/file/write/MidicaPLExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ protected String createRest(byte channel, long ticks, long beginTick, String syl
else {
addWarningRestSkipped(beginTick, ticks, channel);
incrementStats(STAT_REST_SKIPPED, channel);
if (MUST_ADD_TICK_COMMENTS)
line.append(getCommentSymbol() + " " + Dict.get(Dict.WARNING_REST_SKIPPED));
else
return ""; // no line needed
}

// add lyrics option, if needed
Expand Down
4 changes: 3 additions & 1 deletion src/org/midica/ui/file/DecompileConfigController.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ private void initSessionConfig(boolean fromConfig) {
initWidgetConfig( Config.DC_MUST_ADD_STATISTICS, view.cbxAddStatistics, Boolean.class, fromConfig );
initWidgetConfig( Config.DC_MUST_ADD_STRATEGY_STAT, view.cbxAddStrategyStat, Boolean.class, fromConfig );
initWidgetConfig( Config.DC_LENGTH_STRATEGY, view.cbxLengthStrategy, Integer.class, fromConfig );
initWidgetConfig( Config.DC_MIN_TARGET_TICKS_ON, view.cbxMinTargetTicksOn, Integer.class, fromConfig );
initWidgetConfig( Config.DC_MAX_TARGET_TICKS_ON, view.cbxMaxTargetTicksOn, Integer.class, fromConfig );
initWidgetConfig( Config.DC_MIN_DURATION_TO_KEEP, view.fldMinDurToKeep, Float.class, fromConfig );
initWidgetConfig( Config.DC_MAX_DURATION_TO_KEEP, view.fldMaxDurToKeep, Float.class, fromConfig );
initWidgetConfig( Config.DC_LENGTH_TICK_TOLERANCE, view.fldLengthTickTolerance, Integer.class, fromConfig );
initWidgetConfig( Config.DC_DURATION_RATIO_TOLERANCE, view.fldDurationRatioTolerance, Float.class, fromConfig );
initWidgetConfig( Config.DC_USE_PRE_DEFINED_CHORDS, view.cbxPredefinedChords, Boolean.class, fromConfig );
Expand Down Expand Up @@ -679,7 +681,7 @@ else if (Config.DC_ORPHANED_SYLLABLES.equals(id)) {

return model;
}
else if (Config.DC_MAX_TARGET_TICKS_ON.equals(id)) {
else if (Config.DC_MAX_TARGET_TICKS_ON.equals(id) || Config.DC_MIN_TARGET_TICKS_ON.equals(id)) {
String noteLengths[] = {
Dict.SYNTAX_32, Dict.SYNTAX_16, Dict.SYNTAX_8, Dict.SYNTAX_4, Dict.SYNTAX_2, Dict.SYNTAX_1,
Dict.SYNTAX_M2, Dict.SYNTAX_M4, Dict.SYNTAX_M8, Dict.SYNTAX_M16, Dict.SYNTAX_M32,
Expand Down
Loading

0 comments on commit aaec96b

Please sign in to comment.