Package com.softsynth.midifile
Class MIDIFileOutput
java.lang.Object
java.io.RandomAccessFile
com.softsynth.midifile.MIDIFileOutput
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.io.DataOutput
,java.lang.AutoCloseable
public class MIDIFileOutput
extends java.io.RandomAccessFile
MIDI File Writer.
Write tracks and events to a file.
Write tracks and events to a file.
- Author:
- Phil Burk (C) 1999 SoftSynth.com
- See Also:
MIDIFileInputStream
-
Constructor Summary
Constructors Constructor Description MIDIFileOutput(java.io.File file)
MIDIFileOutput(java.lang.String fileName)
-
Method Summary
Modifier and Type Method Description void
finishTrack()
static void
main(java.lang.String[] args)
void
startTrack()
Start chunk for next track.void
writeEndOfTrack(int time)
Every track must end with an EndOfTrack event.void
writeEvent(int time, int command, int data1, int data2)
Write duration and command followed by appropriate number of bytes to file.void
writeHeader(int format, int numTracks, short division)
Write standard MIDI File header.void
writeMetaEvent(int time, int type, byte[] b)
The duration, followed by 0xFF, followed by the type of MetaEvent, followed by the length of the array, followed by the array itself will be written to the file.void
writeSysExEvent(int time, byte[] b)
The duration, followed by 0xF0, followed by the length of the array, followed by the array itself will be written to the file.void
writeSysExEventF7(int time, byte[] b)
The duration, followed by 0xF7, followed by the length of the array, followed by the array itself will be written to the file.void
writeTime(int time)
Write time for an event.void
writeVariableLengthQuantity(int val)
Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MIDIFileOutput
public MIDIFileOutput(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
MIDIFileOutput
public MIDIFileOutput(java.lang.String fileName) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Details
-
writeVariableLengthQuantity
public void writeVariableLengthQuantity(int val) throws java.io.IOException- Throws:
java.io.IOException
-
writeHeader
public void writeHeader(int format, int numTracks, short division) throws java.io.IOExceptionWrite standard MIDI File header.- Throws:
java.io.IOException
-
startTrack
public void startTrack() throws java.io.IOExceptionStart chunk for next track.- Throws:
java.io.IOException
-
writeEndOfTrack
public void writeEndOfTrack(int time) throws java.io.IOExceptionEvery track must end with an EndOfTrack event. Call this before finishTrack().- Throws:
java.io.IOException
-
finishTrack
public void finishTrack() throws java.io.IOException- Throws:
java.io.IOException
-
writeTime
public void writeTime(int time) throws java.io.IOExceptionWrite time for an event. The duration since the last event will be calculated and stored in the file as a variable length number.- Throws:
java.io.IOException
-
writeSysExEvent
public void writeSysExEvent(int time, byte[] b) throws java.io.IOExceptionThe duration, followed by 0xF0, followed by the length of the array, followed by the array itself will be written to the file.- Throws:
java.io.IOException
-
writeSysExEventF7
public void writeSysExEventF7(int time, byte[] b) throws java.io.IOExceptionThe duration, followed by 0xF7, followed by the length of the array, followed by the array itself will be written to the file.- Throws:
java.io.IOException
-
writeMetaEvent
public void writeMetaEvent(int time, int type, byte[] b) throws java.io.IOExceptionThe duration, followed by 0xFF, followed by the type of MetaEvent, followed by the length of the array, followed by the array itself will be written to the file.- Throws:
java.io.IOException
-
writeEvent
public void writeEvent(int time, int command, int data1, int data2) throws java.io.IOExceptionWrite duration and command followed by appropriate number of bytes to file. Data1 and Data2 will not be written if they are not needed.- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args)
-