Skip to content

midifileopen

Open a MIDI file for playback.

This opcode can be called from anywhere, it is non-op if used in an instrument triggered by a MIDI event.

Syntax

 id:i = midfileopen(name:S[,port:i])
id midifileopen Sname[,iport]

Initialization

name -- MIDI file name.

port (optional, default=0) -- MIDI channel port mapping: (port + 1)*channel

Returns a MIDI file id to use with other opcodes.

Examples

Here is an example of the miditempo opcode. It uses the files midifileopen.csd.

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

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

instr Midisynth
 midifileplay(mf)
 amp:i = ampmidi(0.2)
 cps:i = cpsmidi()
 sig:a  = vco2(amp,cps)
 env:a  = madsr(0.001, 0.5, 0.1, 0.1)
   out(sig*env)
endin

schedule(Midisynth,0,0)
event_i("e", 0, midifilelen(mf))

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

See also

Sensing and Control: Tempo and Sequencing

Credits

Author: Victor Lazzarini
May 2025
New in Csound 7