Class: MIDIFile

MIDIFile(name)

A MIDIFile both reads and write MIDI files.

Constructor

new MIDIFile(name)

Create a MIDI file reader/writer.
Parameters:
Name Type Description
name string A name for the MIDIFile.
Author:
  • Lawrence Fyfe
Source:

Methods

addTrack(track)

Add the specified track to this MIDIFile.
Parameters:
Name Type Description
track MIDITrack The track to add.
Source:

dumpHeader()

Dump header data to the console.
Source:

dumpTrackEvents()

Dump event data to the console for all tracks.
Source:

getAllTracks() → {Array}

Get all tracks in this MIDIFile.
Source:
Returns:
An array of tracks.
Type
Array

getByteArray() → {Array}

Get the byte array for the MIDIFile.
Source:
Returns:
An array of bytes.
Type
Array

getTrack(trackNumber) → {MIDITrack}

Get the track specified by the track number.
Parameters:
Name Type Description
trackNumber number The track number to get.
Source:
Returns:
The specified track if it exists.
Type
MIDITrack

getTrackEventType(type, trackNumber) → {Array}

Get the specified type of events from the specified track.
Parameters:
Name Type Description
type string The event type.
trackNumber number The track number to get events from.
Source:
Returns:
An array of events.
Type
Array

getTrackEvents(trackNumber) → {Array}

Get events from the specified track.
Parameters:
Name Type Description
trackNumber number The track number to get events from.
Source:
Returns:
An array of events.
Type
Array

readByte() → {number}

Read a single byte.
Source:
Returns:
A byte.
Type
number

readFile(name, byteArray)

Read a MIDI file as an array of bytes.
Parameters:
Name Type Description
name string A name for the MIDI file.
byteArray Uint8Array An array of bytes from the MIDI file.
Source:

readHeader()

Read the MIDI file header.
Source:

readIdentifier() → {string}

Read the MIDI file identifier.
Source:
Returns:
The file identifier.
Type
string

readMIDIEvent(midiEvent, typeNibble)

Read a MIDI event.
Parameters:
Name Type Description
midiEvent Object The MIDI event.
typeNibble nibble Half of a byte indicating the MIDI event type.
Source:

readMetaEvent(metaEvent)

Read a Meta event.
Parameters:
Name Type Description
metaEvent Object The Meta event.
Source:

readString(start, end) → {string}

Read a string from bytes at the specified Array range.
Parameters:
Name Type Description
start number The starting byte.
end number The ending byte.
Source:
Returns:
A string.
Type
string

readSysExEvent(sysExEvent, status)

Read a SysEx event.
Parameters:
Name Type Description
sysExEvent Object The SysEx event.
status byte The status (type) of the SysEx event.
Source:

readTrackEvent() → {Object}

Read event bytes and return a MIDI, SysEx, or Meta event object.
Source:
Returns:
A MIDI, SysEx, or Meta event.
Type
Object

readVariableByteNumber() → {number}

Read a number represented by 1-4 bytes.
Source:
Returns:
A number.
Type
number

setTrackEvents(trackNumber, events)

Set events for the specified track. This will replace any existing events in the track!
Parameters:
Name Type Description
trackNumber number The track number to set events for.
events Array An array of events.
Source:

toFramesPerSecond(byte) → {number}

Convert a byte value to frames per second.
Parameters:
Name Type Description
byte number The byte to convert.
Source:
Returns:
Frames per second.
Type
number

toFramesPerSecondByte(fps) → {number}

Convert frames per second to a byte value.
Parameters:
Name Type Description
fps number Frames per second to convert.
Source:
Returns:
A byte representing frames per second.
Type
number

toNumber(bytes)

Convert a byte array to a number.
Parameters:
Name Type Description
bytes Array The byte array to convert.
Source:

toSeconds(ticks) → {number}

Convert MIDI ticks to seconds.
Parameters:
Name Type Description
ticks number The ticks to convert.
Source:
Returns:
Seconds.
Type
number

toTicks(seconds) → {number}

Convert seconds to MIDI ticks.
Parameters:
Name Type Description
seconds number The seconds to convert.
Source:
Returns:
Ticks.
Type
number

writeByte(byte) → {number}

Write the specified byte.
Parameters:
Name Type Description
byte number The byte to write.
Source:
Returns:
The number of bytes written: one.
Type
number

writeEvent(event)

Write the specified event to a MIDI track.
Parameters:
Name Type Description
event Object The MIDI, SysEx, or Meta event to write.
Source:

writeFile()

Write a MIDI file.
Source:

writeHeader()

Write a MIDI file header.
Source:

writeIdentifierBytes(string)

Write the specified string to bytes.
Parameters:
Name Type Description
string string The string to convert to bytes for writing.
Source:

writeLengthAndData(data) → {number}

Write variable length data to bytes. The length is determined from the size of the data and written as a variable number of bytes.
Parameters:
Name Type Description
data Array The data to convert to bytes for writing.
Source:
Returns:
The number of bytes written.
Type
number

writeLengthAndString(string) → {number}

Write an arbitrary string to bytes. The length is determined from the size of the data and written as a variable number of bytes.
Parameters:
Name Type Description
string string The string to convert to bytes for writing.
Source:
Returns:
The number of bytes written.
Type
number

writeMIDIBytes(event) → {number}

Write the specified MIDI event to bytes.
Parameters:
Name Type Description
event Object The MIDI event to convert to bytes for writing.
Source:
Returns:
The number of bytes written.
Type
number

writeMetaEvent(event)

Write the specified Meta event to bytes.
Parameters:
Name Type Description
event Object The Meta event to convert to bytes for writing.
Source:

writeNumberBytes(number, number, writeToByteArray) → {number}

Write the specified number to bytes.
Parameters:
Name Type Description
number number The number to convert to bytes for writing.
number number The number of bytes for representing the number.
writeToByteArray Array An Array for writing.
Source:
Returns:
The number of bytes written.
Type
number

writeSysExEvent(event)

Write the specified SysEx event to bytes.
Parameters:
Name Type Description
event Object The SysEx event to convert to bytes for writing.
Source:

writeTrack(track)

Write the specified track to a MIDI file.
Parameters:
Name Type Description
track MIDITrack The MIDITrack to write.
Source:

writeVariableNumberBytes(number) → {number}

Write the specified number to a variable number of bytes.
Parameters:
Name Type Description
number number The number to convert to 1-4 bytes for writing.
Source:
Returns:
The number of bytes written.
Type
number