Skip to content

midiout_i

Sends a MIDI channel message at initialization.

midiouti is another name for midiout_i. Both spellings use the same arguments and behavior. Use midiout to send messages during performance.

Syntax

midiout_i(istatus, ichan, idata1, idata2 [, iport])
midiouti(istatus, ichan, idata1, idata2 [, iport])
midiout_i istatus, ichan, idata1, idata2 [, iport]
midiouti istatus, ichan, idata1, idata2 [, iport]

Initialization

All arguments are i-rate. The opcode sends one message when it initializes, including during reinitialization. It has no output arguments. An instrument's duration does not cause the message to repeat or arrange a later note-off.

istatus selects the message type. Use 0 to send nothing. The other supported values are shown below.

istatus Message idata1 idata2
128 Note off Note number Release velocity
144 Note on Note number Velocity
160 Polyphonic aftertouch Note number Pressure
176 Control change Controller number Value
192 Program change Program number Ignored
208 Channel aftertouch Pressure Ignored
224 Pitch bend Least significant 7 bits Most significant 7 bits

ichan is the MIDI channel, from 1 to 16. Supply the message type and channel separately.

idata1 and idata2 are MIDI data bytes. Use integers from 0 to 127. Both arguments are required, even for messages that use only one data byte. Set the unused argument to 0. Program numbers use the raw MIDI range 0 to 127, so a device that labels programs 1 to 128 displays a number one greater. Pitch bend has its center at idata1 = 0 and idata2 = 64.

iport selects the output port and defaults to 0. Use a nonnegative integer supported by the MIDI output backend. It is separate from ichan and does not open or select a physical device on its own.

Configure real-time MIDI output with -Q and the chosen MIDI backend, or write messages to a MIDI file with --midioutfile. Port routing depends on the backend or host. PortMidi's -Qm mode routes port 0 to the first opened output, port 1 to the second, and so on. Its single-device mode ignores the per-message port. MIDI file output writes the messages without preserving iport as a port designation.

A note-on needs a matching note-off message later. Use a separate scheduled event for that message, as in the example.

Examples

The example writes a program change, a volume setting and two short notes to midiout_i.mid. It uses both spellings and shows an explicit port 0 as well as the default. Each note has a separate note-off event.

Run it from a writable directory. It needs no MIDI device and produces no audio. Open the resulting MIDI file in a sequencer to inspect or play the messages.

It uses midiout_i.csd.

Write MIDI messages using both i-time spellings
<CsoundSynthesizer>
<CsOptions>
-n -d --midioutfile=midiout_i.mid
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

instr 1
  // The alias sends one message at initialization, using explicit port 0.
  midiouti(p4, 1, p5, p6, 0)
endin

instr 2
  // The older spelling sends channel volume with the default port.
  midiout_i(176, 1, 7, 100)
endin
</CsInstruments>
<CsScore>
// Choose raw program number 21 and set the channel volume.
i 1 0 0.01 192 21 0
i 2 0 0.01
// Each note-on has a matching note-off half a second later.
i 1 0.1 0.01 144 60 80
i 1 0.6 0.01 128 60 0
i 1 0.8 0.01 144 64 80
i 1 1.3 0.01 128 64 0
e
</CsScore>
</CsoundSynthesizer>

See also

midiouti, midiout, MIDI Message Output, Generic Input and Output

Credits

Gabriel Maldonado wrote the original MIDI output implementation in 1998. Victor Lazzarini added the i-time form in 2017.

The i-time form is available from Csound 6.10.