public class MidicaPLExporter extends Decompiler
This class is used to export the currently loaded MIDI sequence as a MidicaPL source file.
Modifier and Type | Field and Description |
---|---|
private int |
elementsInCurrentLine |
private java.lang.String |
FORMAT_CH_CMD_CHANNEL |
private java.lang.String |
FORMAT_CH_CMD_CRD |
private java.lang.String |
FORMAT_CH_CMD_LENGTH |
private boolean |
isCompactSyntax |
private boolean |
isInBlock |
private boolean |
isLowlevelSyntax |
private java.lang.Long |
lineBeginTickSrc |
private java.lang.Long |
lineBeginTickTgt |
private java.util.HashSet<java.lang.Byte> |
usedInSlice |
ALDA, ALL_SYLLABLES_ORPHANED, BLOCK_INDENT, CHORD_NOTE_OFF_TOLERANCE, CHORD_NOTE_ON_TOLERANCE, CHORD_VELOCITY_TOLERANCE, chordCount, chords, chordsByBaseNote, commentHistory, CTRL_CHANGE_MODE, DEFAULT_ALL_SYLLABLES_ORPHANED, DEFAULT_CHORD_NOTE_OFF_TOLERANCE, DEFAULT_CHORD_NOTE_ON_TOLERANCE, DEFAULT_CHORD_VELOCITY_TOLERANCE, DEFAULT_CTRL_CHANGE_MODE, DEFAULT_DURATION_RATIO_TOLERANCE, DEFAULT_ELEMENTS_PER_LINE, DEFAULT_EXTRA_GLOBALS_STR, DEFAULT_KARAOKE_ONE_CHANNEL, DEFAULT_LENGTH_STRATEGY, DEFAULT_LENGTH_TICK_TOLERANCE, DEFAULT_MAX_BARLINE_TOL, DEFAULT_MAX_DURATION_TO_KEEP, DEFAULT_MAX_TICKS_ON_AT_480, DEFAULT_MIN_DURATION_TO_KEEP, DEFAULT_MIN_TICKS_ON_AT_480, DEFAULT_MUST_ADD_CONFIG, DEFAULT_MUST_ADD_QUALITY_SCORE, DEFAULT_MUST_ADD_STATISTICS, DEFAULT_MUST_ADD_STRATEGY_STAT, DEFAULT_MUST_ADD_TICK_COMMENTS, DEFAULT_ORPHANED_SYLLABLES, DEFAULT_SYNTAX_TYPE, DEFAULT_USE_BARLINES, DEFAULT_USE_DOTTED_NOTES, DEFAULT_USE_DOTTED_RESTS, DEFAULT_USE_KARAOKE, DEFAULT_USE_PRE_DEFINED_CHORDS, DEFAULT_USE_TRIPLETTED_NOTES, DEFAULT_USE_TRIPLETTED_RESTS, DURATION_RATIO_TOLERANCE, ELEMENTS_PER_LINE, ET_INLINE_BLK, ET_INSTR, ET_NOTES, exportResult, EXTRA_GLOBALS, format, INLINE_BLOCK, instrumentHistory, isSoftKaraoke, KARAOKE_ONE_CHANNEL, LENGTH_STRATEGY, LENGTH_TICK_TOLERANCE, LM_DOT, LM_NONE, LM_TRIPLET, lyricsChannels, lyricsSyllables, MAX_BARLINE_TOL, MAX_DURATION_TO_KEEP, MAX_SOURCE_TICKS_ON, MAX_TICKS_ON_AT_480, measureLengthHistory, MIDICA, MIN_DURATION_TO_KEEP, MIN_SOURCE_TICKS_ON, MIN_TICKS_ON_AT_480, MUST_ADD_CONFIG, MUST_ADD_QUALITY_SCORE, MUST_ADD_STATISTICS, MUST_ADD_STRATEGY_STAT, MUST_ADD_TICK_COMMENTS, NEW_LINE, noteHistory, noteLength, noteOnOff, NP_DURATION, NP_END_TICK, NP_LENGTH, NP_LYRICS, NP_MULTIPLE, NP_NOTE_NUM, NP_OFF_TICK, NP_VELOCITY, ORPHANED_SYLLABLES, output, restLength, SLICE_BEGIN_BLOCK, slices, sourceResolution, srcInstrByChannel, srcInstrByName, STAT_NOTE_DURATIONS, STAT_NOTE_MULTIPLE, STAT_NOTE_SUMMANDS, STAT_NOTE_TRIPLETS, STAT_NOTE_VELOCITIES, STAT_NOTES, STAT_REST_SKIPPED, STAT_REST_SUMMANDS, STAT_REST_TRIPLETS, STAT_RESTS, STAT_TOTAL, STRATEGY_DURATION_NEXT_PRESS, STRATEGY_DURATION_PRESS, STRATEGY_NEXT_DURATION_PRESS, STRATEGY_NEXT_PRESS, STRATEGY_PRESS, SYNTAX_COMPACT, SYNTAX_LOWLEVEL, SYNTAX_TYPE, targetResolution, tgtInstrByChannel, tgtInstrByName, USE_BARLINES, USE_DOTTED_NOTES, USE_DOTTED_RESTS, USE_KARAOKE, USE_PRE_DEFINED_CHORDS, USE_TRIPLETTED_NOTES, USE_TRIPLETTED_RESTS
Constructor and Description |
---|
MidicaPLExporter()
Creates a new MidicaPL exporter.
|
Modifier and Type | Method and Description |
---|---|
private void |
createBarlineIfNeeded(byte channel)
Creates a barline for the given channel, if needed.
|
private void |
createChordDefinitions()
Creates the CHORD definitions.
|
private void |
createCommandsFromTimeline(Slice slice,
byte channel)
Creates channel commands and instrument changes from a slice’s timeline.
|
private void |
createCompactElement(java.lang.String noteName,
byte channel,
java.lang.String length)
Creates a single compact element.
|
private void |
createCompactLineChangeIfNeeded(byte channel)
In compact syntax: returns the opening, closing or switching of a line for the given channel, if necessary.
|
private void |
createCompactLineClose(byte channel)
Closes a compact, if compact syntax is used.
|
private void |
createCompactLineCloseIfPossible(byte channel)
Closes a compact line, if one is open and compact syntax is used.
|
private void |
createGlobalCommands(Slice slice)
Creates the global commands for the given slice.
|
private void |
createInitialInstrumentsBlock()
Creates the initial INSTRUMENTS block.
|
private void |
createInlineBlock(byte channel,
long tick,
Slice slice)
Creates an inline block with a multiple option.
|
private void |
createInstrLine(long tick,
byte channel)
Creates one line inside an INSTRUMENTS block or one single instrument change line.
|
private void |
createInstrumentChange(byte channel,
long tick)
Creates one INSTRUMENT line for an instrument change in the given channel and tick.
|
private void |
createMetaBlock()
Creates the META block, if the sequence contains any META information.
|
private void |
createNotesAtTick(Slice slice,
byte channel,
long tick,
java.util.TreeMap<java.lang.String,java.util.TreeMap<java.lang.Byte,java.lang.String>> events)
Creates commands for all notes or chords that are played in a certain channel and begin at a certain tick.
|
java.lang.String |
createOutput()
Creates the format-specific string to be written to the exported file.
|
protected void |
createRest(byte channel,
long ticks,
java.lang.String syllable)
Creates a rest.
|
private void |
createSingleNoteOrChord(byte channel,
java.lang.String noteName,
java.util.TreeMap<java.lang.Byte,java.lang.String> noteOrCrd,
long tick)
Creates a single channel command for a note or chord.
|
private void |
createSliceBeginBlock(Slice slice,
byte channel)
Creates a nestable block with the ‘multiple’ option at the beginning of a slice.
|
private java.lang.String |
createSoftKaraokeBlock(java.util.HashMap<java.lang.String,java.lang.Object> karaokeInfo)
Creates the SOFT_KARAOKE block inside of the META block.
|
private void |
createTickComment(long srcTick,
long tgtTick)
Creates a tick comment, if tick comments are configured.
|
private java.lang.String |
escapeSyllable(java.lang.String syllable)
Escapes special characters in syllables.
|
private void |
incrementTargetTicks(byte channel,
java.lang.String length)
Increments the target channel by the amount of ticks of the given length value.
|
void |
init()
Initializes format-specific data structures.
|
java.util.TreeMap<java.lang.Long,java.lang.String> |
initLengths(boolean rest)
Calculates which tick length corresponds to which note or rest length.
|
addWarningRestSkipped, calculateTicks, createConfig, createQualityStats, createRestBeforeSlice, createSpacesBeforeComment, createStrategyStats, createTickDescription, createTickLineComment, export, getCommentSymbol, getFurthestInstrument, getLengthsForSum, getNoteLengthProperties, incrementStats, resetTickCommentLineLength
createFile
private java.lang.String FORMAT_CH_CMD_CHANNEL
private java.lang.String FORMAT_CH_CMD_CRD
private java.lang.String FORMAT_CH_CMD_LENGTH
private boolean isCompactSyntax
private boolean isLowlevelSyntax
private int elementsInCurrentLine
private java.util.HashSet<java.lang.Byte> usedInSlice
private java.lang.Long lineBeginTickSrc
private java.lang.Long lineBeginTickTgt
private boolean isInBlock
public void init()
Decompiler
Initializes format-specific data structures.
init
in class Decompiler
public java.lang.String createOutput()
Decompiler
Creates the format-specific string to be written to the exported file.
createOutput
in class Decompiler
private void createCommandsFromTimeline(Slice slice, byte channel)
Creates channel commands and instrument changes from a slice’s timeline.
Creates nothing, if the slice’s timeline doesn’t contain anything in the given channel.
Steps:
slice
- the sequence slicechannel
- MIDI channelprivate void createMetaBlock()
Creates the META block, if the sequence contains any META information. Creates nothing, if the sequence doesn’t contain any meta information.
private java.lang.String createSoftKaraokeBlock(java.util.HashMap<java.lang.String,java.lang.Object> karaokeInfo)
Creates the SOFT_KARAOKE block inside of the META block. This is called only if the sequence uses SOFT KARAOKE.
karaokeInfo
- Karaoke information extracted from the sequence.private void createInitialInstrumentsBlock()
Creates the initial INSTRUMENTS block.
private void createInstrumentChange(byte channel, long tick)
Creates one INSTRUMENT line for an instrument change in the given channel and tick.
channel
- MIDI channeltick
- MIDI tickprivate void createInstrLine(long tick, byte channel)
Creates one line inside an INSTRUMENTS block or one single instrument change line.
If tick is 0, a line inside a block is created. Otherwise it’s an instrument change line.
Creates nothing, if no instruments must be defined or changed in the given channel and tick.
At the beginning this method is called for each channel (0-15). This considers:
Afterwards this method is called for every tick and channel that contains one or more program changes at a tick higher than 0.
tick
- The tickstamp of the program change event; or 0 during initialization.channel
- The channel number.private void createChordDefinitions()
Creates the CHORD definitions.
private void createGlobalCommands(Slice slice)
Creates the global commands for the given slice.
slice
- the sequence sliceprivate void createSliceBeginBlock(Slice slice, byte channel)
Creates a nestable block with the ‘multiple’ option at the beginning of a slice.
This block doesn’t contain any notes. It may contain only:
slice
- the sequence slicechannel
- MIDI channelprivate void createInlineBlock(byte channel, long tick, Slice slice)
Creates an inline block with a multiple option.
Adds a rest before the block, if necessary.
channel
- MIDI channeltick
- MIDI tickslice
- the sequence sliceprivate void createNotesAtTick(Slice slice, byte channel, long tick, java.util.TreeMap<java.lang.String,java.util.TreeMap<java.lang.Byte,java.lang.String>> events)
Creates commands for all notes or chords that are played in a certain channel and begin at a certain tick.
Steps:
Strategy to choose the LAST note/chord command:
- no MULTIPLE option needed for the last note/chord
- no rests are necessary
- no MULTIPLE option needed for the last note/chord
- rests must be added LATER but not now
- no MULTIPLE option needed for the last note/chord
- rest(s) must be added
- all chords/notes need the MULTIPLE option, even the last one.
- rest(s) must be added
slice
- the sequence slicechannel
- MIDI channeltick
- MIDI tickevents
- All notes/chords with the same note-ON tick in the same channel (comes from the slice’s timeline)private void createSingleNoteOrChord(byte channel, java.lang.String noteName, java.util.TreeMap<java.lang.Byte,java.lang.String> noteOrCrd, long tick)
Creates a single channel command for a note or chord. (Lowlevel command or compact element plus options.)
channel
- MIDI channelnoteName
- note or chord namenoteOrCrd
- note properties (from the slice’s timeline)tick
- MIDI tickstamp.private void createCompactLineChangeIfNeeded(byte channel)
In compact syntax: returns the opening, closing or switching of a line for the given channel, if necessary. Returns an empty string if none is needed or in lowlevel mode.
channel
- MIDI channelprivate void createCompactLineCloseIfPossible(byte channel)
Closes a compact line, if one is open and compact syntax is used.
channel
- MIDI channelprivate void createCompactLineClose(byte channel)
Closes a compact, if compact syntax is used.
channel
- MIDI channelprivate void createBarlineIfNeeded(byte channel)
Creates a barline for the given channel, if needed.
channel
- MIDI channelprivate void createCompactElement(java.lang.String noteName, byte channel, java.lang.String length)
Creates a single compact element.
noteName
- note, chord or restchannel
- MIDI channellength
- note lengthprotected void createRest(byte channel, long ticks, java.lang.String syllable)
Decompiler
Creates a rest.
createRest
in class Decompiler
channel
- MIDI channelticks
- tick length of the rest to createsyllable
- a lyrics syllable or (in most cases): nullprivate void incrementTargetTicks(byte channel, java.lang.String length)
Increments the target channel by the amount of ticks of the given length value.
channel
- MIDI channellength
- note length in MPL syntaxprivate java.lang.String escapeSyllable(java.lang.String syllable)
Escapes special characters in syllables.
syllable
- The syllable to be escaped.public java.util.TreeMap<java.lang.Long,java.lang.String> initLengths(boolean rest)
Decompiler
Calculates which tick length corresponds to which note or rest length. That depends on the resolution of the current MIDI sequence.
The created rest lengths should contain a few more very short lengths. This is needed because rests should be less tolerant than notes.
This enables us to use more common lengths for notes but let the exported sequence be still as close as possible to the original one.
initLengths
in class Decompiler
rest
- true to initialize REST lengths, false for NOTE lengthsprivate void createTickComment(long srcTick, long tgtTick)
Creates a tick comment, if tick comments are configured.
srcTick
- MIDI tick in source resolutiontgtTick
- MIDI tick in target resolution