Skip to content

midion

Generates MIDI note messages at k-rate.

Syntax

midion(kchn, knum, kvel [, iport])
midion kchn, knum, kvel [, iport]

Initialization

iport -- MIDI output port, optional set to 0.

Performance

kchn -- MIDI channel number (1-16)

knum -- note number (0-127)

kvel -- velocity (0-127)

midion (k-rate note on) plays MIDI notes with current kchn, knum and kvel. These arguments can be varied at k-rate. Each time the MIDI converted value of any of these arguments changes, last MIDI note played by current instance of midion is immediately turned off and a new note with the new argument values is activated. This opcode, as well as moscil, can generate very complex melodic textures if controlled by complex k-rate signals.

A change of port, when iport is a global variable another instrument sets, moves the note the same way: it is turned off on the old port and sent on the new one. A noteoff always goes to the port of its noteon.

When a note is tied onto a held note, midion keeps sounding a note whose channel, number, velocity and port stay the same, and turns it off before sending a different one. A reinit pass turns the note off and sends it again. When the instrument ends without a release, for instance through turnoff2 with krelease 0, or the performance stops, the note still sounding is turned off.

In Csound 7.0.0, midion crashed at its first control cycle. Earlier versions sent the new note at a tie or a reinit without turning off the one still sounding, and left a note sounding when its instrument ended without a release.

Any number of midion opcodes can appear in the same Csound instrument, allowing a counterpoint-style polyphony within a single instrument.

Examples

Here is a simple example of the midion opcode. It uses the file midion_simple.csd.

This example generates a minor chord over every note received on the MIDI input. It generates MIDI notes on csound's MIDI output, so be sure to connect something.

Simple Example of the midion opcode.
<CsoundSynthesizer> 
<CsOptions> 
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac           -iadc     -d         -M0  -Q1 ;;;RT audio I/O with MIDI in
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 10
nchnls = 2
0dbfs = 1

; Example by Giorgio Zucco 2007


instr 1 ;Triggered by MIDI notes on channel 1

  ifund notnum
  ivel  veloc

  knote1 init ifund
  knote2 init ifund + 3
  knote3 init ifund + 5

  ;minor chord on MIDI out channel 1
  ;Needs something plugged to csound's MIDI output
  midion 1, knote1,ivel
  midion 1, knote2,ivel
  midion 1, knote3,ivel

endin


</CsInstruments>
<CsScore>
; Dummy ftable
f0 60
</CsScore>
</CsoundSynthesizer>

Here is another example of the midion opcode. It uses the file midion_scale.csd.

This example generates random notes from a given scale for every note received on the MIDI input. It generates MIDI notes on csound's MIDI output, so be sure to connect something.

Example of the midion opcode to generate random notes from a scale.
<CsoundSynthesizer> 
<CsOptions> 
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac           -iadc     -d        -M0  -Q1 ;;;RT audio I/O with MIDI in
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 10
nchnls = 2
0dbfs = 1

; Example by Giorgio Zucco 2007

instr 1 ; Triggered by MIDI notes on channel 1

  ivel  veloc

  krate = 8
  iscale = 100 ;f

  ; Random sequence from table f100
  krnd  randh int(14),krate,-1
  knote table abs(krnd),iscale
  ; Generates random notes from the scale on ftable 100
  ; on channel 1 of csound's MIDI output
  midion 1,knote,ivel

endin

</CsInstruments>
<CsScore>
f100 0 32 -2  40 50 60 70 80 44 54 65 74 84 39 49 69 69

; Dummy ftable
f0 60
</CsScore>
</CsoundSynthesizer>

See also

Note-on/Note-off Output

Credits

Author: Gabriel Maldonado
Italy
May 1997

Thanks goes to Rasmus Ekman for pointing out the correct MIDI channel and controller number ranges.