Skip to content

midifileloop

Sets the looping mode of a MIDI file playback.

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

Requires the -F flag to operate. If a filename is passed to -F, it is open with id 0 and playback starts immediately.

Syntax

 midifileplay(loop:i, [id:i])
 midifileplay(loop:k, [id:i])
midifileplay iloop, [id]
midifileplay kloop, [id]    

Initialization

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

loop -- playback loop mode: 1 = on, 0 = off

Performance

loop -- playback loop mode: 1 = on, 0 = off

Examples

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

Example of the midifileloop 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

instr loop
midifileloop p4, mf
endin

schedule(Midisynth,0,0)
schedule(loop,0,0,1)
event("e",0,154)

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

See also

Sensing and Control: Tempo and Sequencing

Credits

Author: Victor Lazzarini
May 2026
New in Csound 7