public class MidiParser extends SequenceParser
An object of this class can be used in order to parse a MIDI file.
It uses the SequenceCreator
in order to create a MIDI sequence from the parsed input and includes meta events whenever a key is pressed or released. This is used later for the channel activity analyzer in the player while playing the MIDI sequence.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
chosenCharset |
static int |
CTRL_CHANGE_BALANCE |
static int |
CTRL_CHANGE_BANK_SELECT |
static int |
CTRL_CHANGE_FOOT_CONTROLLER |
static int |
CTRL_CHANGE_MODULATION_WHEEL |
static int |
CTRL_CHANGE_PAN |
static int |
CTRL_CHANGE_VOLUME |
private boolean |
isProducedByMidica |
private static LyricUtil |
lyricUtil |
protected java.lang.String |
midiFileCharset |
transposeLevel
Constructor and Description |
---|
MidiParser() |
Modifier and Type | Method and Description |
---|---|
protected void |
createSequence(javax.sound.midi.Sequence sequence)
Transforms the parsed MIDI sequence.
|
protected int |
getImportFormat()
Returns the import format defined in
SequenceCreator as IMPORT_FORMAT_*. |
void |
parse(java.lang.Object fileAsObj)
Parses a MIDI file.
|
private void |
processMetaMessage(javax.sound.midi.MetaMessage msg,
long tick,
int origTrack)
Processes a meta message from the input sequence.
|
private void |
processShortMessage(javax.sound.midi.ShortMessage msg,
long tick)
Processes a short message from the input sequence.
|
private void |
processSysexMessage(javax.sound.midi.SysexMessage msg,
long tick)
Processes a SysEx message from the input sequence.
|
protected void |
replaceChannelVolume()
Replaces all channel volume events in the successfully parsed sequence by an according expression message.
|
getFileName, getFilePath, getTransposeLevel, postprocessSequence, preprocess, setTransposeLevel, transpose
public static final int CTRL_CHANGE_BANK_SELECT
public static final int CTRL_CHANGE_MODULATION_WHEEL
public static final int CTRL_CHANGE_FOOT_CONTROLLER
public static final int CTRL_CHANGE_VOLUME
public static final int CTRL_CHANGE_BALANCE
public static final int CTRL_CHANGE_PAN
private boolean isProducedByMidica
protected java.lang.String midiFileCharset
protected java.lang.String chosenCharset
private static LyricUtil lyricUtil
public void parse(java.lang.Object fileAsObj) throws ParseException
Parses a MIDI file.
fileAsObj
- MIDI file to be parsed.ParseException
- If the file or URL can not be parsed correctly.protected int getImportFormat()
Returns the import format defined in SequenceCreator
as IMPORT_FORMAT_*.
Returns SequenceCreator.IMPORT_FORMAT_MIDI
by default. Can be overridden by foreign format importers like ALDA, ABC, and so on.
protected void createSequence(javax.sound.midi.Sequence sequence) throws ParseException, javax.sound.midi.InvalidMidiDataException
Transforms the parsed MIDI sequence. Passes all events to SequenceCreator
in order to create a new sequence while adding meta events for each key-press and key-release event.
sequence
- The original MIDI sequence.ParseException
- If the input file can not be parsed correctly.javax.sound.midi.InvalidMidiDataException
- If the created sequence is invalid.private void processMetaMessage(javax.sound.midi.MetaMessage msg, long tick, int origTrack) throws javax.sound.midi.InvalidMidiDataException
Processes a meta message from the input sequence.
Meta messages are just forwarded into the target sequence without being changed. Karaoke-related meta messages are written into track 1 or 2. All others will be written into track 0.
msg
- Meta message from the input sequence.tick
- Tickstamp of the message’s occurrence.origTrack
- Original track number.javax.sound.midi.InvalidMidiDataException
private void processSysexMessage(javax.sound.midi.SysexMessage msg, long tick)
Processes a SysEx message from the input sequence. SysEx messages are just forwarded into the target sequence without being changed.
msg
- SysEx message from the input sequence.tick
- Tickstamp of the message’s occurrence.private void processShortMessage(javax.sound.midi.ShortMessage msg, long tick) throws javax.sound.midi.InvalidMidiDataException, ParseException
Processes a short message from the input sequence.
If it is a note-on or note-off message than the note will be transposed according to the configured transpose level.
If it is a program change, note-on or note-off message than an according meta message is added to the target sequence together with the message itself.
msg
- The short message from the input sequence.tick
- Tickstamp of the message’s occurrence.javax.sound.midi.InvalidMidiDataException
ParseException
protected void replaceChannelVolume() throws javax.sound.midi.InvalidMidiDataException
Replaces all channel volume events in the successfully parsed sequence by an according expression message.
Problem:
Many MIDI files contain channel volume messages (MSB Controller 0x07, LSB Controller 0x27). These interfere with setting the channel volume in the player.
Solution:
The messages are replaced only in the CREATED sequence (the one that’s used by the player). The original sequence (used by the analyzer) stays untouched.
javax.sound.midi.InvalidMidiDataException
- if the transformation to expression fails