public class MidicaPLExporter extends Decompiler
This class is used to export the currently loaded MIDI sequence as a MidicaPL source file.
ALDA, BLOCK, CHORD_NOTE_OFF_TOLERANCE, CHORD_NOTE_ON_TOLERANCE, CHORD_VELOCITY_TOLERANCE, chordCount, chords, chordsByBaseNote, commentHistory, DEFAULT_CHORD_NOTE_OFF_TOLERANCE, DEFAULT_CHORD_NOTE_ON_TOLERANCE, DEFAULT_CHORD_VELOCITY_TOLERANCE, DEFAULT_DURATION_RATIO_TOLERANCE, DEFAULT_EXTRA_GLOBALS_STR, DEFAULT_KARAOKE_ONE_CHANNEL, DEFAULT_LENGTH_STRATEGY, DEFAULT_LENGTH_TICK_TOLERANCE, DEFAULT_MAX_TARGET_TICKS_ON, DEFAULT_MIN_DURATION_TO_KEEP, 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_USE_DOTTED_NOTES, DEFAULT_USE_DOTTED_RESTS, DEFAULT_USE_PRE_DEFINED_CHORDS, DEFAULT_USE_TRIPLETTED_NOTES, DEFAULT_USE_TRIPLETTED_RESTS, DURATION_RATIO_TOLERANCE, ET_INSTR, ET_NOTES, exportResult, EXTRA_GLOBALS, format, INLINE, instrumentHistory, instrumentsByChannel, instrumentsByName, isSoftKaraoke, KARAOKE_ONE_CHANNEL, LENGTH_STRATEGY, LENGTH_TICK_TOLERANCE, lyricsChannels, lyricsSyllables, MAX_SOURCE_TICKS_ON, MAX_TARGET_TICKS_ON, MIDICA, MIN_DURATION_TO_KEEP, 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, restLength, slices, sourceResolution, 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, targetResolution, USE_DOTTED_NOTES, USE_DOTTED_RESTS, 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 java.lang.String |
createChordDefinitions()
Creates the CHORD definitions.
|
private java.lang.String |
createCommandsFromTimeline(Slice slice,
byte channel)
Creates channel commands and instrument changes from a slice’s timeline.
|
private java.lang.String |
createGlobalCommands(Slice slice)
Creates a string with global commands for the given slice.
|
private java.lang.String |
createInitialInstrumentsBlock()
Creates the initial INSTRUMENTS block.
|
private java.lang.String |
createInstrLine(long tick,
byte channel)
Creates one line inside an INSTRUMENTS block or one single instrument change line.
|
private java.lang.String |
createInstrumentChange(byte channel,
long tick)
Creates one INSTRUMENT line for an instrument change in the given channel and tick.
|
private java.lang.String |
createMetaBlock()
Creates the META block, if the sequence contains any META information.
|
private java.lang.String |
createNoteLines(Slice slice,
byte channel,
long tick,
java.util.TreeMap<java.lang.String,java.util.TreeMap<java.lang.Byte,java.lang.String>> events)
Creates lines for all notes or chords that are played in a certain channel and begin at a certain tick.
|
java.lang.String |
createOutput()
Creates the MidicaPL string to be written into the export file.
|
protected java.lang.String |
createRest(byte channel,
long ticks,
long beginTick,
java.lang.String syllable)
Creates a channel command with a rest.
|
private java.lang.String |
createSingleNoteLine(byte channel,
java.lang.String noteName,
java.util.TreeMap<java.lang.Byte,java.lang.String> noteOrCrd,
long tick)
Prints a single channel command for a note or chord.
|
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 java.lang.String |
createSyllableRestsBlock(Slice slice)
Creates a nestable block containing all rests with syllables that have no corresponting Note-ON event.
|
private java.lang.String |
createTickComment(long tick,
boolean mustAppend)
Creates a comment giving the current tick - if configured accordingly.
|
private java.lang.String |
escapeSyllable(java.lang.String syllable)
Escapes special characters in syllables.
|
void |
init()
Initializes MidicaPL 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.
|
calculateTicks, createConfig, createQualityStats, createRestBeforeSlice, createStrategyStats, export, getFurthestInstrument, getLengthsForSum, getNoteLengthProperties, incrementStats
createFile
public void init()
Initializes MidicaPL specific data structures.
init
in class Decompiler
public java.lang.String createOutput()
Creates the MidicaPL string to be written into the export file.
createOutput
in class Decompiler
private java.lang.String createSyllableRestsBlock(Slice slice)
Creates a nestable block containing all rests with syllables that have no corresponting Note-ON event.
slice
- the sequence sliceprivate java.lang.String createCommandsFromTimeline(Slice slice, byte channel)
Creates channel commands and instrument changes from a slice’s timeline.
Steps:
slice
- the sequence slicechannel
- MIDI channelprivate java.lang.String createMetaBlock()
Creates the META block, if the sequence contains 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 java.lang.String createInitialInstrumentsBlock()
Creates the initial INSTRUMENTS block.
private java.lang.String createInstrumentChange(byte channel, long tick)
Creates one INSTRUMENT line for an instrument change in the given channel and tick.
channel
- MIDI channeltick
- MIDI tickprivate java.lang.String 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.
Returns an empty string, 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 java.lang.String createChordDefinitions()
Creates the CHORD definitions.
private java.lang.String createGlobalCommands(Slice slice)
Creates a string with global commands for the given slice.
slice
- the sequence sliceprivate java.lang.String createNoteLines(Slice slice, byte channel, long tick, java.util.TreeMap<java.lang.String,java.util.TreeMap<java.lang.Byte,java.lang.String>> events)
Creates lines 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 java.lang.String createSingleNoteLine(byte channel, java.lang.String noteName, java.util.TreeMap<java.lang.Byte,java.lang.String> noteOrCrd, long tick)
Prints a single channel command for a note or chord. (Or a rest with a syllable, if orphaned syllables are configured as INLINE.)
channel
- MIDI channelnoteName
- note or chord namenoteOrCrd
- note properties (from the slice’s timeline)tick
- MIDI tickstamp.protected java.lang.String createRest(byte channel, long ticks, long beginTick, java.lang.String syllable)
Creates a channel command with a rest.
createRest
in class Decompiler
channel
- MIDI channelticks
- tick length of the rest to createbeginTick
- used for the tick comment (negative value: don’t include a tick comment)syllable
- a lyrics syllable or (in most cases): nullprivate 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)
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 will contain a view 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 java.lang.String createTickComment(long tick, boolean mustAppend)
Creates a comment giving the current tick - if configured accordingly.
Adds a line break, if must_append is true.
tick
- MIDI tickstamp.mustAppend
- true for a comment to be appended to a line; false for a full-line comment.