public class MidiEventParser extends java.lang.Object implements EventParser
MidiEventParser
handles the interfacing between this program and MIDI files.
It can read in MIDI events from a file with run()
.
One EventParser is required per song you wish to parse.
Modifier and Type | Field and Description |
---|---|
static int |
CHANNEL_MASK
The mask for reading the channel number from a MidiMessage.
|
private java.util.List<java.util.List<MidiNote>> |
goldStandard
The gold standard voices from this song.
|
static int |
KEY_SIGNATURE
The constant which midi uses for key signature change events.
|
static int |
MESSAGE_MASK
The mask for reading the message type from a MidiMessage.
|
private NoteEventParser |
noteEventParser
The NoteTracker which will keep track of the notes for this song.
|
private javax.sound.midi.Sequence |
song
The song we are parsing.
|
static int |
TEMPO
The constant which midi uses for tempo change events.
|
static int |
TIME_SIGNATURE
The constant which midi uses for time signature change events.
|
private TimeTracker |
timeTracker
The TimeTracker which will handle timing information for this song.
|
private boolean |
useChannel
True if we want to use the input data's channel as gold standard voices.
|
Constructor and Description |
---|
MidiEventParser(java.io.File midiFile,
NoteEventParser noteEventParser,
TimeTracker timeTracker,
boolean useChannel)
Creates a new MidiEventParser
|
Modifier and Type | Method and Description |
---|---|
java.util.List<java.util.List<MidiNote>> |
getGoldStandardVoices()
Get a List of the gold standard voices from this song.
|
private int |
getNextTrackNum(long[] nextEventTick)
Get the index of the track with the next event.
|
private boolean |
moreEventsRemain(int[] nextEventIndex)
Return true if some notes remain.
|
void |
run()
Parses the events from the loaded MIDI file through to the NoteTracker.
|
public static final int CHANNEL_MASK
public static final int MESSAGE_MASK
public static final int TEMPO
public static final int TIME_SIGNATURE
public static final int KEY_SIGNATURE
private TimeTracker timeTracker
private final NoteEventParser noteEventParser
private final javax.sound.midi.Sequence song
private java.util.List<java.util.List<MidiNote>> goldStandard
private boolean useChannel
public MidiEventParser(java.io.File midiFile, NoteEventParser noteEventParser, TimeTracker timeTracker, boolean useChannel) throws javax.sound.midi.InvalidMidiDataException, java.io.IOException
midiFile
- The MIDI file we will parse.noteEventParser
- The NoteEventParser to pass events to when we run this parser.useChannel
- True if we want to use the input data's channel as gold standard voices.
False to use track instead.java.io.IOException
- If an I/O error occurred when reading the given file.javax.sound.midi.InvalidMidiDataException
- If the given file was is not in a valid MIDI format.public void run() throws javax.sound.midi.InvalidMidiDataException
run
in interface EventParser
javax.sound.midi.InvalidMidiDataException
- If a note off event doesn't match any previously seen note on.java.lang.InterruptedException
- If this is running on a GUI and gets cancelled.private boolean moreEventsRemain(int[] nextEventIndex)
nextEventIndex
- The indices of the next event for each track.
-1 i none remains.private int getNextTrackNum(long[] nextEventTick)
nextEventTick
- The ticks for the next event on each of the tracks.public java.util.List<java.util.List<MidiNote>> getGoldStandardVoices()
getGoldStandardVoices
in interface EventParser