Skip to content

midifilein

Returns a generic MIDI message from a MIDI file.

Syntax

status:i,chan:i,data1:i,data2:i,time:i = midifilein(index:i,[id:i])
status:k, chan:k, data1:k, data2:k, time:k = midifilein(index:k,[id:k])
istatus, ichan, idata1, idata2, itime midifilein iindex, id
kstatus, kchan, kdata1, kdata2, ktime midifilein kindex, kid

Initiatialization

index -- MIDI event index in MIDI file (0 - midifilevents()].

id (optional, default=0) -- MIDI file id, defaults to 0, the id of any file passed to the -F flag.

status -- the type of MIDI message. Can be:

  • 128 (note off)
  • 144 (note on)
  • 160 (polyphonic aftertouch)
  • 176 (control change)
  • 192 (program change)
  • 208 (channel aftertouch)
  • 224 (pitch bend)
  • 0 if no MIDI message are pending in the MIDI IN buffer

chan -- MIDI channel (1-16 if only one input port is used, higher if channel is port mapped.)

data1, data2 -- message-dependent data values

Performance

Same as above, but operational only at performance time. Users should select the appropriate overload for init or perf-time.

Examples

Here is an example of the midifilein opcode. It uses the file midifilein.csd.

Example of the midifilein opcode.
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
0dbfs=1

mf@global:i = midifileopen("catherine.mid")

instr Read
evts:i = midifilevents(mf)
print evts
cnt:i = 0
status:i[] = init(evts)
chan:i[] = init(evts)
data1:i[] = init(evts)
data2:i[] = init(evts)
time:i[] = init(evts)
while cnt < evts do
 st:i,chn:i,d1:i,d2:i,t:i = midifilein(cnt,mf)
 // copy events to array       
 status[cnt] = st
 chan[cnt] = chn
 data1[cnt] = d1
 data2[cnt] = d2
 time[cnt] = t
 cnt += 1
od
print status[10]
exitnow()
endin

schedule(Read,0,0)


</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

See also

Sensing and Control: Tempo and Sequencing

Credits

Author: Victor Lazzarini
May 2025
New in Csound 7