Controls MIDI output through sfxlib where the target backend supports it.
Syntax
result = Midi Open(device)
Midi Close
result = Midi Close()
result = Midi Play(filename)
Midi Stop
Midi Pause
Midi Resume
result = Midi Send(status, data1, data2)
Description
MIDI is not recorded audio. It is a stream of musical instructions sent to a MIDI device or synthesizer. Those instructions can say things like note on, note off, change instrument, or change controller value.
Midi Open selects a MIDI output device by index. Midi Send sends one short MIDI message using a status byte and two data bytes. For example, &h90 is a common note-on status byte on channel 1, the first data byte is the note number, and the second is velocity.
Midi Play attempts to play a MIDI file where the backend supports file playback. Stop, Pause, Resume, and Close control that MIDI path.
MIDI support varies a lot by operating system and backend. Programs should check return values and continue gracefully if no MIDI device exists.
Example
if midi open(0) >= 0 then
midi send &h90, 60, 100 ' note on: middle C
sleep 250, 1
midi send &h80, 60, 0 ' note off
midi close
end if
Notes
- Use MUSIC for recorded music files such as WAV or decoded audio.
- Use PLAY or NOTE for generated music that does not need a MIDI device.
See also