a MIDI file implementation capable of reading and writing all types of MIDI data (except sysex messages).
First code examples:
SimpleMIDIFile also supports Event Patterns (see Pattern and Pbind). You can use the p
method to convert a SimpleMIDIFile
into a playable pattern (a Ppar to be exact).
Via the fromPattern method patterns can be turned into midi files as well:
create a new, possibly empty instance.
Arguments:
create a new instance from a pattern.
Arguments:
pattern | |
maxEvents | |
maxAmp | |
startTime | |
inTracks | |
inTempo | |
timeSignature | |
read an existing MIDI file from disk.
Arguments:
file path of the midi file. defaults to "~/scwork/midi.mid"
.
an array containing all MIDI events as arrays. Format:
[ trackNumber, absTime, type, channel, val1, val2 ]
- tracknumber
- the number of the track in which this event sits. For format type 0 files this is always 0, for type 1 files track 0 is reserved for meta events, so midiEvent tracks start counting at 1.
- absTime
- the absolute start-time of the event. If timeMode == \ticks the absTime is in ticks (tempo dependant), if timeMode == \seconds it is in seconds (not depending on tempo). In the original midi file format all times are relative to the previous event on a track, but for convenience SimpleMIDIFile converts them to absolute times when reading in.
- type
- usually a Symbol. Can be one of
[\noteOff, \noteOn, \polyTouch, \cc, \program, \afterTouch, \pitchBend]
- channel midi channel on which the event plays. Starts at 0 (= midi channel 1)
- val1
- val2
- values for the event. These are usually between 0-127. The contents of these vary per event type:
type | val1 | val2 |
noteOn | note number | velocity |
noteOff | note number | velocity |
polyTouch | note number | amount |
cc | control number | amount |
program | program number | (no val2) |
afterTouch | amount | (no val2) |
pitchBend | depends on pitchBendMode | |
an array containing all META events as arrays. Format:
[ trackNumber, absTime, type, [values] / value / string ]
absTime
represents the abslute time at which the event takes place. In the Standard MIDI file format time values are always relative to the previous event. For convenience reasons the SimpleMIDIFile class converts these to absolute times when reading a file. The format of last item in the array above depends on the type of the event:
types of which the last item is a string
\text
\copyright
\trackName
\instName
\lyrics
\marker
\cuePoint
types of which the last item is a value
\sequenceNumber
\tempo
-> tempo in beats per minute
types of which the last item is an array of values
\timeSignature
\keySignature
\sequencerSpecific
\midiChannelPrefix
types of which the last item something else
\smpteOffset
-> a SMPTE\endOfTrack
-> nil
there can be unknown types of meta events. They have status byte number instead of a symbol in the 'type' slot of the array
a global tempo indicator in bpm. tempo
always indicates the first tempo found, ignoring other tempo events in metaEvents
. The tempo mapping functionality uses the tempo events instead of this value. Setting the tempo with tempo_
does not add or change tempo events ( a MIDI file can but does not need to contain a tempo event ). Use getTempo
to get tempo, if existing, from metaEvents
.
Arguments:
either 'ticks'
or 'seconds'
, defaults to 'ticks'
. This affects all time information contained in the midiEvents and metaEvents. Whenever the timeMode is switched all time data will be converted.
- ticks
- standard MIDI file format for time data. The duration of one tick depends on the division and tempo at that specific point.
- seconds
- absolute seconds, not influenced by tempo or division
Arguments:
newTimeMode |
the time mode |
convert |
flag indicating if converting data between time modes |
number of 'ticks' per quarter note. This should usually be 1024. Change it only when you experience problems with specific sequencer software (there seem to be some which use different divisions)
can be 0, 1 or 2 (single, multi or pattern oriented)
- 0
- typically all data in first track (0)
- 1
- typically have all global metaData in first track (0) and all midi data in following tracks (1..). A trackName metaEvent in track 0 is usually interpreted as the song name
- 2
- not very common. Works the same as format 1, but is meant for separate patterns in one file, contained in sequences (tracks)
Empty SimpleMIDIFiles need to be inited as format 0 or 1 first, using init0
and init1
methods.
number of tracks used. Can be fetched from midiEvents using adjustTracks
.
one of int8', 'int16', 'float'
. The default is 'int8'.
- int8
- pitchbend stored as array of 2 int8 values (0-127), as stored in the midifile
- int16
- pitchbend stored as single int16 value (0-16383)
- float
- pitchbend stored as floating point values (-1.0 - 1.0)
Arguments:
to | |
convert |
Flag indicating if existing values should be converted. |
init as type 0 file
Arguments:
init as type 1 file. Minimum tracks are 2
; first track contains metaData.
Arguments:
inTracks | |
inTempo | |
timeSignature | |
read MIDI file from disk.
write MIDI file to disk.
Arguments:
fill with events from a Pattern
Arguments:
pattern | |
maxEvents | |
maxAmp | |
startTime | |
returns sequenceable [note, dur]
data in an array.
adjust number of tracks according to midi data
Arguments:
removeDuplicates | |
removeDoubles | |
sort events on time and track
to different array formats or Classes
Arguments:
channel | |
track |
returns events in the form:
|
Arguments:
event |
array, for format, see above. |
sort | |
Arguments:
events |
array of arrays, for their format, see above. |
sort | |
Arguments:
type | |
channel | |
args | |
absTime | |
track | |
sort | |
Arguments:
type | |
channel | |
args | |
absTime | |
track | |
sort | |
Arguments:
noteNumber | |
velo | |
startTime | |
dur | |
upVelo | |
channel | |
track | |
sort | |
Arguments:
cc | |
val | |
startTime | |
channel | |
track | |
Arguments:
div | |
denom | |
time | |
sort | |
removeOld | |
Arguments:
clock | |
protoEvent | |
quant | |
inst | |
amp | |
Arguments:
function | |
channel | |
track | |
clock | |
doneAction | |
Arguments:
pattern | |
maxEvents | |
timeSig | |
numTicks | |
Arguments:
defName | |
maxlevel | |
minlevel | |
addArgs | |
addAction | |
channel | |
track | |
target | |
Arguments:
bounds | |
track | |
type | |
channel | |
cc | |
minVal | |
maxVal | |
grid | |