SimpleMIDIFile:
Filter:
Classes (extension) | Undocumented classes

SimpleMIDIFile : Object
ExtensionExtension

simple MIDI file implementation

Description

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:

Class Methods

SimpleMIDIFile.new(pathName)

create a new, possibly empty instance.

Arguments:

pathName

SimpleMIDIFile.fromPattern(pattern, maxEvents: 1000, maxAmp: 0.2, startTime: 0, inTracks: 2, inTempo: 120, timeSignature)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

create a new instance from a pattern.

Arguments:

pattern
maxEvents
maxAmp
startTime
inTracks
inTempo
timeSignature

SimpleMIDIFile.read(pathName)

read an existing MIDI file from disk.

Arguments:

pathName

SimpleMIDIFile.tempoScale

SimpleMIDIFile.tempoScale = value

global tempo scale

Inherited class methods

Instance Methods

core methods

.pathName

.pathName = value

file path of the midi file. defaults to "~/scwork/midi.mid".

.midiEvents

.midiEvents = value

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:
typeval1val2
noteOnnote numbervelocity
noteOffnote numbervelocity
polyTouchnote numberamount
cccontrol numberamount
programprogram number(no val2)
afterTouchamount(no val2)
pitchBenddepends on pitchBendMode

.metaEvents

.metaEvents = value

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

types of which the last item is a value

types of which the last item is an array of values

types of which the last item something else

there can be unknown types of meta events. They have status byte number instead of a symbol in the 'type' slot of the array

.tempo

.tempo = newTempo: 120

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:

newTempo

the new tempo

.timeMode

.timeMode_(newTimeMode, convert: true)

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

.division

.division = value

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)

.format

.format = value

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.

.tracks

.tracks = value

number of tracks used. Can be fetched from midiEvents using adjustTracks.

.pitchBendMode

.pitchBendMode_(to, convert: true)

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

.init0(inTempo: 120, timeSignature)

init as type 0 file

Arguments:

inTempo
timeSignature

.init1(inTracks: 2, inTempo: 120, timeSignature)

init as type 1 file. Minimum tracks are 2; first track contains metaData.

Arguments:

inTracks
inTempo
timeSignature

read/write

.read

read MIDI file from disk.

.write(newFileName)

write MIDI file to disk.

Arguments:

newFileName

the filename

.writeFile(theFile)

Arguments:

theFile

.checkWrite(newFileName, overwrite: false, ask: true)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-checkWrite.sc

Arguments:

newFileName
overwrite
ask

pattern support

.p(inst, amp: 0.2, useTempo: true)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

Arguments:

inst
amp
useTempo

.fromPattern(pattern, maxEvents: 1000, maxAmp: 0.2, startTime: 0)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

fill with events from a Pattern

Arguments:

pattern
maxEvents
maxAmp
startTime

.generatePatternSeqs

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

returns sequenceable [note, dur] data in an array.

correction

.adjustTracks

adjust number of tracks according to midi data

.adjustEndOfTrack(track, wait: 0)

Arguments:

track
wait

.correctTempoEvents(removeDuplicates: true, removeDoubles: true)

Arguments:

removeDuplicates
removeDoubles

.sortMIDIEvents

sort events on time and track

.sortMetaEvents

.getTempo

conversion / processing

.convertNoteOns(noteOffVelo: 64)

Arguments:

noteOffVelo

.convertNoteOffs

.shiftTime(deltaTime)

Arguments:

deltaTime

selection

.midiTrackEvents(trackNumber: 0)

Arguments:

trackNumber

.midiChannelEvents(channel, track)

Arguments:

channel
track

.midiTrackTypeEvents(track: 0, type: 'noteOn', channel)

Arguments:

track
type
channel

.midiTypeEvents( ... args)

Arguments:

... args

.noteEvents(channel, track)

Arguments:

channel
track

.realNoteOnEvents(channel, track)

Arguments:

channel
track

.noteOffEvents(channel, track)

Arguments:

channel
track

.firstNoteOnTrack(track: 0)

Arguments:

track

.pitchBendEvents(channel, track)

Arguments:

channel
track

.afterTouchEvents(channel, track)

Arguments:

channel
track

.controllerEvents(cc, channel, track)

Arguments:

cc
channel
track

.modulationEvents(channel, track)

Arguments:

channel
track

.breathEvents(channel, track)

Arguments:

channel
track

.volumeEvents(channel, track)

Arguments:

channel
track

.panEvents(channel, track)

Arguments:

channel
track

.expressionEvents(channel, track)

Arguments:

channel
track

.damperEvents(channel, track)

Arguments:

channel
track

.metaTrackEvents(trackNumber: 0)

Arguments:

trackNumber

.timeSignatureEvents

.keySignatureEvents

.smpteOffsetEvents

.tempoEvents

.testEndOfTrack(track)

Arguments:

track

converted selection

to different array formats or Classes

.noteSustainEvents(channel, track)

Arguments:

channel
track

returns events in the form:

.midiDeltaEvents(track: 0, type: 'noteOn', channel)

Arguments:

track
type
channel

.midiDeltaCCEvents(track: 0, cc: 1, channel)

Arguments:

track
cc
channel

.timeSignatures

.keySignatures

.trackNames

.instNames

.midiTracks

.metaTracks

.asDicts

.asNoteDicts(channel, track)

Arguments:

channel
track

.envFromType(track: 0, type: 'pitchBend', channel)

Arguments:

track
type
channel

.envFromCC(track: 0, cc, channel)

Arguments:

track
cc
channel

extraction of single values

.trackName(track: 0)

Arguments:

track

.instName(track: 0)

Arguments:

track

.length

.smpteOffset

timing methods (converted selection, extraction)

.tempi

.tempoMap

.tempoEnv

.beatAtTime(time: 0)

Arguments:

time

.timeAtBeat(beat: 0)

Arguments:

beat

.tempoAtTime(time: 0)

Arguments:

time

.timeSignatureAsArray

.measureAtBeat(beat: 0, measureFormat)

Arguments:

beat
measureFormat

.measureAtTime(time: 0, measureFormat)

Arguments:

time
measureFormat

.beatAtMeasure(measure, measureFormat)

Arguments:

measure
measureFormat

.timeAtMeasure(measure, measureFormat)

Arguments:

measure
measureFormat

addition of events

.addMIDIEvent(event, sort: true)

Arguments:

event

array, for format, see above.

sort

.addAllMIDIEvents(events, sort: true)

Arguments:

events

array of arrays, for their format, see above.

sort

.addMIDIEventToTrack(event, track: 0, sort: true)

Arguments:

event
track
sort

.addAllMIDIEventsToTrack(events, track: 0, sort: true)

Arguments:

events
track
sort

.addMIDITypeEvent(type: 'cc', channel: 0, args, absTime: 0, track: 0, sort: true)

Arguments:

type
channel
args
absTime
track
sort

.addAllMIDITypeEvents(type: 'cc', channel: 0, args, absTime, track: 0, sort: true)

Arguments:

type
channel
args
absTime
track
sort

.addNote(noteNumber: 64, velo: 64, startTime: 0, dur: 1, upVelo, channel: 0, track: 0, sort: true)

Arguments:

noteNumber
velo
startTime
dur
upVelo
channel
track
sort

.addCC(cc: 7, val: 127, startTime: 0, channel: 0, track: 0)

Arguments:

cc
val
startTime
channel
track

.addMetaEvent(event, sort: true)

Arguments:

event
sort

.addTrack(name)

Arguments:

name

.addTimeSignature(div: 4, denom: 4, time: 0, sort: true, removeOld: true)

Arguments:

div
denom
time
sort
removeOld

.addTimeSignatureString(string: "4/4", time: 0, sort: true, removeOld: true)

Arguments:

string
time
sort
removeOld

.addTempo(tempo: 120, time: 0, sort: true, removeOld: true)

Arguments:

tempo
time
sort
removeOld

.setTrackName(name, track: 0)

Arguments:

name
track

.setInstName(name, track: 0)

Arguments:

name
track

.setTempo(newTempo)

Arguments:

newTempo

removal

.removeMetaEvents(type: 'tempo', time, track: 0)

Arguments:

type
time
track

.removeTimeSignature(time: 0, doIt: true)

Arguments:

time
doIt

.removeTempo(time: 0, doIt: true)

Arguments:

time
doIt

analysis

.analyzeTypes

.analyzeMetaTypes

.analyzeChannels(type)

Arguments:

type

.analyzeChannel(channel: 0, track)

Arguments:

channel
track

.analyzeUsedChannels(track)

Arguments:

track

.analyzeUsedTracks

.analyzeUsedEvents

.analyzeTracks(type)

Arguments:

type

.analyzeCC

.analyzeCCTracks

.usedChannels(track)

Arguments:

track

.usedTracks(channel)

Arguments:

channel

.countMIDIEvents(type: 'noteOn', track, channel)

Arguments:

type
track
channel

.info

additions

.convertTimes(newTimeMode: 'seconds')

Arguments:

newTimeMode

.getTime(file)

Arguments:

file

.play(clock, protoEvent, quant, inst, amp: 0.2)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

Arguments:

clock
protoEvent
quant
inst
amp

.noteOnEvents(channel, track)

Arguments:

channel
track

.sysexEvents

.sysexEvents = value

.processChunk(file)

Arguments:

file

.rawMeasureAtBeat(beat: 0)

Arguments:

beat

.convertToInt8(val, size: 2)

Arguments:

val
size

.convertPitchBend(to: 'int16')

Arguments:

to

.asDeltaChunks

.numbytes

.numbytes = value

.theTrackNumber

.theTrackNumber = value

.asChunks

.asMIDIFileChunks

.theChan

.theChan = value

.playNotesWithFunction(function, channel, track, clock, doneAction)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-asEvents.sc

Arguments:

function
channel
track
clock
doneAction

.curTime

.curTime = value

.init

.theCmd

.theCmd = value

.keySignatures

.ccEvents(cc, channel, track)

Arguments:

cc
channel
track

.renderPattern(pattern, maxEvents: 1000, timeSig: "4/4", numTicks: 1024)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

Arguments:

pattern
maxEvents
timeSig
numTicks

.convertToVLInteger(dT)

Arguments:

dT

.rawMeasureAtTime(time: 0)

Arguments:

time

.trackNames

.asMetaChunks

.asMIDIChunks

.handleMeta(file)

Arguments:

file

.playWithSynth(defName: "default", maxlevel: 0.5, minlevel: 0, addArgs, addAction: 'addToHead', channel, track, target)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-asEvents.sc

Arguments:

defName
maxlevel
minlevel
addArgs
addAction
channel
track
target

.plot(notesOnly: false)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-plot.sc

Arguments:

notesOnly

.panEvents(channel, track)

Arguments:

channel
track

.expressionEvents(channel, track)

Arguments:

channel
track

.beatAtRawMeasure(rawMeasure: 0)

Arguments:

rawMeasure

.prAdjustEndOfTrack(track: 0, wait: 0)

Arguments:

track
wait

.tempo

.tempo = newTempo: 120

Arguments:

newTempo

.info

.asMetaDeltaChunks

.asPenFunction(bounds, track: 0, type: 'pitchBend', channel: 0, cc: 0, minVal: 0, maxVal: 127, grid: true)

From extension in /home/stefan/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-plot.sc

Arguments:

bounds
track
type
channel
cc
minVal
maxVal
grid

.timeAtRawMeasure(rawMeasure: 0)

Arguments:

rawMeasure

.handleRunningStatus(val, file)

Arguments:

val
file

.getVl(file)

Arguments:

file

.handleMIDI(cmd, file)

Arguments:

cmd
file

.handleSysex(file)

Arguments:

file

.firstNote(trackArray)

Arguments:

trackArray

.endOfTrack(track)

Arguments:

track

.asMIDIDeltaChunks

Inherited instance methods

Undocumented instance methods

.addSysexEvent(event, sort: true)

.asSysexChunks

.sortSysexEvents

.sysexTrackEvents(trackNumber: 0)

.sysexTracks