Skip to content

midifilelen

Returns the length of a MIDI file.

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

Syntax

 len:i =  midifilelen([id:i])
ilen midifilelen [id]

Initialization

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

The length is returned in seconds.

Examples

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

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

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

instr Len
 print(midifilelen(mf))
 exitnow(0)
endin

schedule(Len,0,0)


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

See also

Sensing and Control: Tempo and Sequencing

Credits

Author: Victor Lazzarini
May 2025
New in Csound 7