public class MidiWriter
extends java.lang.Object
MidiWriter
is able to take in MidiNote
s and a TimeTracker
,
and write them out to a valid Midi File.
This will write out the new file so that any anacrusis is now built into the file. That is, the first measure is extended with rests so that it becomes a full measure.
Modifier and Type | Field and Description |
---|---|
private int |
offsetLength
The length of the rests we will add to the beginning of this song, in ticks.
|
private java.io.File |
outFile
The File we want to write to.
|
private javax.sound.midi.Sequence |
sequence
The Sequence containing the Midi data we are going to write out.
|
private TimeTracker |
timeTracker
The TimeTracker for this Midi data.
|
Constructor and Description |
---|
MidiWriter(java.io.File outFile,
TimeTracker tt)
Create a new MidiWriter to write out to the given File.
|
Modifier and Type | Method and Description |
---|---|
void |
addMidiNote(MidiNote note)
Add the given MidiNote into the
sequence . |
void |
write()
Actually write the data out to file.
|
private void |
writeKeySignature(KeySignature keySignature,
long tick)
Write the given key signature out to
sequence at the given tick. |
private void |
writeTempo(Tempo tempo,
long tick)
Write the given tempo out to
sequence at the given tick. |
private void |
writeTimeSignature(TimeSignature timeSignature,
long tick)
Write the given time signature out to
sequence at the given tick. |
private void |
writeTimeTracker()
Write the proper TimeTracker events out to our
sequence . |
private java.io.File outFile
private TimeTracker timeTracker
private javax.sound.midi.Sequence sequence
private int offsetLength
public MidiWriter(java.io.File outFile, TimeTracker tt) throws javax.sound.midi.InvalidMidiDataException
outFile
- outFile
tt
- timeTracker
javax.sound.midi.InvalidMidiDataException
- If somehow the TimeTracker has an invalid PPQ value.private void writeTimeTracker() throws javax.sound.midi.InvalidMidiDataException
sequence
.javax.sound.midi.InvalidMidiDataException
- If the TimeTracker contained invalid Midi data.private void writeKeySignature(KeySignature keySignature, long tick) throws javax.sound.midi.InvalidMidiDataException
sequence
at the given tick.keySignature
- The key signature to write.tick
- The tick at which to write it.javax.sound.midi.InvalidMidiDataException
- If the key signature produces invalid Midi data.private void writeTimeSignature(TimeSignature timeSignature, long tick) throws javax.sound.midi.InvalidMidiDataException
sequence
at the given tick.timeSignature
- The time signature to write.tick
- The tick at which to write it.javax.sound.midi.InvalidMidiDataException
- If the time signature contained invalid Midi data.private void writeTempo(Tempo tempo, long tick) throws javax.sound.midi.InvalidMidiDataException
sequence
at the given tick.tempo
- The tempo to write.tick
- The tick at which to write it.javax.sound.midi.InvalidMidiDataException
- If the tempo contained invalid Midi data.public void addMidiNote(MidiNote note) throws javax.sound.midi.InvalidMidiDataException
sequence
.note
- The note to add.javax.sound.midi.InvalidMidiDataException
- If the MidiNote contains invalid Midi data.public void write() throws java.io.IOException
java.io.IOException
- If the file cannot be written to.