edu.columbia.ee.csmit.MidiKaraoke.write
Class SimpleMidiWriter
java.lang.Object
edu.columbia.ee.csmit.MidiKaraoke.write.SimpleMidiWriter
public class SimpleMidiWriter
- extends java.lang.Object
This class writes a midi file with a single tempo.
|
Method Summary |
static void |
write(java.lang.String fileName,
double[] onset,
double[] duration,
int[] channel,
int[] pitch,
int[] velocity,
int[] track,
int microsecondsPerQuarterNote,
int resolution,
int[] timeSignature)
Creates a simple midi file which does not specify patches (instruments). |
static void |
write(java.lang.String fileName,
double[] onset,
double[] duration,
int[] channel,
int[] pitch,
int[] velocity,
int[] track,
int microsecondsPerQuarterNote,
int resolution,
int[] timeSignature,
int[][] patches)
Creates a simple midi file. |
static void |
write(java.lang.String fileName,
double[] onset,
double[] duration,
int[] channel,
int[] pitch,
int[] velocity,
int microsecondsPerQuarterNote,
int resolution,
int[] timeSignature)
Creates a simple midi file that does not specify instruments and place
all notes in track 0. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SimpleMidiWriter
public SimpleMidiWriter()
write
public static void write(java.lang.String fileName,
double[] onset,
double[] duration,
int[] channel,
int[] pitch,
int[] velocity,
int[] track,
int microsecondsPerQuarterNote,
int resolution,
int[] timeSignature,
int[][] patches)
throws javax.sound.midi.InvalidMidiDataException,
SimpleMidiWriter.InvalidTempo,
java.io.IOException,
SimpleMidiWriter.InvalidSignature
- Creates a simple midi file. The parameters onset, duration, channel,
pitch, velocity, and track should all be arrays that are the same length as
the number of notes. For example,
double[] onset = {0, 2, 5};
// make each note 2 beats long
double[] duration = {2, 2, 2};
// pitches C4 (middle C), D4, E4
int[] pitch = {60, 62, 64};
// put each note on a different channel
int[] channel = {0, 1, 2};
// use a variety of velocity (loudness) values
int[] velocity = {40,65, 90};
// put all the notes on track 1
int[] track = {1, 1, 1};
// channel | track | patch number:
// 0 1 0 (acoustic grand piano)
// 1 1 56 (trumpet)
// 2 1 22 (harmonica)
int[][] patches = {{0,1,0},{1,1,56},{2,1,22}};
// pick half a second per quarter note
int microsecondsPerQuarterNote = (int) (0.5 * 1000000.0);
// pick a resolution of 100 ticks per beat. This means that the
// shortest note we can specify is 1/100th of a beat.
int resolution = 100;
// pick a time signature, 4/4 (common time) with 1 midi clock per
// quarter note and 8 32nd notes per quarter note.
int[] timeSignature = {4,4,1,8};
// pick some name for the resulting file.
String fileName = "Temp.mid";
// write the file
SimpleMidiWriter.write(fileName, onset, duration, channel, pitch,
velocity, track, microsecondsPerQuarterNote, resolution,
timeSignature,patches);
would give you a midi file with three notes.
- Parameters:
fileName - - name of the file to createonset - - array of note onsets in beatsduration - - array of note durations in beatschannel - - array of note channel numberspitch - - array of note pitchesvelocity - - array of note velocity (volume) valuestrack - - array of note track numbersmicrosecondsPerQuarterNote - - number of microseconds per quarter
note (beat)resolution - - number of ticks per beat. Indicates the level of
quantization of the note durations.timeSignature - - a 4-element array with the 4 parts of a midi time
signature message. timeSignature[0] = numerator of the time signature
(i.e. 4 for 4/4 time), timeSignature[1] = the denominator of the time
signature (i.e. 2 for 4/4 time, 3 for 6/8, etc.), timeSignature[3] =
the number of midi clocks per quarter note, timeSignature[4] = the
number of 32nd notes per quarter note.patches - - an Nx3 element array, where N is the number patches
(instruments) you want to specify. These patches will be set at the
beginning of the midi file. Each row should specify the channel,
track, and patch number in that order. If null, no instruments will
be specified.
- Throws:
javax.sound.midi.MidiUnavailableException
javax.sound.midi.InvalidMidiDataException
edu.columbia.ee.csmit.MidiKaraoke.write.PianoRollWriter.InvalidTempo
java.io.IOException
SimpleMidiWriter.InvalidTempo
SimpleMidiWriter.InvalidSignature
write
public static void write(java.lang.String fileName,
double[] onset,
double[] duration,
int[] channel,
int[] pitch,
int[] velocity,
int[] track,
int microsecondsPerQuarterNote,
int resolution,
int[] timeSignature)
throws javax.sound.midi.InvalidMidiDataException,
SimpleMidiWriter.InvalidTempo,
java.io.IOException,
SimpleMidiWriter.InvalidSignature
- Creates a simple midi file which does not specify patches (instruments).
The parameters onset, duration, channel,
pitch,velocity, and track should all be arrays that are the same length as
the number of notes.
- Parameters:
fileName - - name of the file to createonset - - array of note onsets in beatsduration - - array of note durations in beatschannel - - array of note channel numberspitch - - array of note pitchesvelocity - - array of note velocity (volume) valuestrack - - array of note track numbersmicrosecondsPerQuarterNote - - number of microseconds per quarter
note (beat)resolution - - number of ticks per beat. Indicates the level of
quantization of the note durations.timeSignature - - a 4-element array with the 4 parts of a midi time
signature message. timeSignature[0] = numerator of the time signature
(i.e. 4 for 4/4 time), timeSignature[1] = the denominator of the time
signature (i.e. 2 for 4/4 time, 3 for 6/8, etc.), timeSignature[3] =
the number of midi clocks per quarter note, timeSignature[4] = the
number of 32nd notes per quarter note.
- Throws:
javax.sound.midi.MidiUnavailableException
javax.sound.midi.InvalidMidiDataException
edu.columbia.ee.csmit.MidiKaraoke.write.PianoRollWriter.InvalidTempo
java.io.IOException
SimpleMidiWriter.InvalidTempo
SimpleMidiWriter.InvalidSignature
write
public static void write(java.lang.String fileName,
double[] onset,
double[] duration,
int[] channel,
int[] pitch,
int[] velocity,
int microsecondsPerQuarterNote,
int resolution,
int[] timeSignature)
throws javax.sound.midi.InvalidMidiDataException,
SimpleMidiWriter.InvalidTempo,
java.io.IOException,
SimpleMidiWriter.InvalidSignature
- Creates a simple midi file that does not specify instruments and place
all notes in track 0. The parameters onset, duration, channel,
pitch, and velocity should all be arrays that are the same length as
the number of notes.
- Parameters:
fileName - - name of the file to createonset - - array of note onsets in beatsduration - - array of note durations in beatschannel - - array of note channel numberspitch - - array of note pitchesvelocity - - array of note velocity (volume) valuesmicrosecondsPerQuarterNote - - number of microseconds per quarter
note (beat)resolution - - number of ticks per beat. Indicates the level of
quantization of the note durations.timeSignature - - a 4-element array with the 4 parts of a midi time
signature message. timeSignature[0] = numerator of the time signature
(i.e. 4 for 4/4 time), timeSignature[1] = the denominator of the time
signature (i.e. 2 for 4/4 time, 3 for 6/8, etc.), timeSignature[3] =
the number of midi clocks per quarter note, timeSignature[4] = the
number of 32nd notes per quarter note.
- Throws:
javax.sound.midi.MidiUnavailableException
javax.sound.midi.InvalidMidiDataException
edu.columbia.ee.csmit.MidiKaraoke.write.PianoRollWriter.InvalidTempo
java.io.IOException
SimpleMidiWriter.InvalidTempo
SimpleMidiWriter.InvalidSignature