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 java.lang.String |
FORMAT_CH_CMD_CHANNEL |
private java.lang.String |
FORMAT_CH_CMD_CRD |
private java.lang.String |
FORMAT_CH_CMD_LENGTH |
ALDA, ALL_SYLLABLES_ORPHANED, 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_EXTRA_GLOBALS_STR, DEFAULT_KARAOKE_ONE_CHANNEL, DEFAULT_LENGTH_STRATEGY, DEFAULT_LENGTH_TICK_TOLERANCE, DEFAULT_MAX_DURATION_TO_KEEP, DEFAULT_MAX_TARGET_TICKS_ON, DEFAULT_MIN_DURATION_TO_KEEP, DEFAULT_MIN_TARGET_TICKS_ON, 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_KARAOKE, DEFAULT_USE_PRE_DEFINED_CHORDS, DEFAULT_USE_TRIPLETTED_NOTES, DEFAULT_USE_TRIPLETTED_RESTS, DURATION_RATIO_TOLERANCE, ET_INLINE_BLK, ET_INSTR, ET_NOTES, exportResult, EXTRA_GLOBALS, format, INLINE_BLOCK, instrumentHistory, instrumentsByChannel, instrumentsByName, isSoftKaraoke, KARAOKE_ONE_CHANNEL, LENGTH_STRATEGY, LENGTH_TICK_TOLERANCE, lyricsChannels, lyricsSyllables, MAX_DURATION_TO_KEEP, MAX_SOURCE_TICKS_ON, MAX_TARGET_TICKS_ON, MIDICA, MIN_DURATION_TO_KEEP, MIN_SOURCE_TICKS_ON, MIN_TARGET_TICKS_ON, 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, SLICE_BEGIN_BLOCK, 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_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 java.lang.String |
appendTickComment(java.lang.String line,
long tick)
Appends a tick comment to the given line, if tick comments are configured.
|
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 |
createInlineBlock(byte channel,
long tick,
Slice slice)
Creates an inline block with a multiple option.
|
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 |
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 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.
|
addWarningRestSkipped, calculateTicks, createConfig, createQualityStats, createRestBeforeSlice, createStrategyStats, createTickDescription, export, getCommentSymbol, getFurthestInstrument, getLengthsForSum, getNoteLengthProperties, incrementStats
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
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 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 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 java.lang.String 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 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.
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 appendTickComment(java.lang.String line, long tick)
Appends a tick comment to the given line, if tick comments are configured. Otherwise the given line is returned unchanged.
line
- the line to be completed by a commenttick
- MIDI tick