MIDI Out

Naast de ontvangst van MIDI events kunnen MIDI events ook verzonden worden om externe hardware synthesizers, keyboards en andere apparaten te manipuleren. Sonic Pi levert een volledige set van functies om diverse MIDI berichten te versturen, zoals:

  1. Note on - midi_note_on
  2. Note off - midi_note_off
  3. Control change - midi_cc
  4. Pitch bend - midi_pitch_bend
  5. Clock ticks - midi_clock_tick

Er zijn vele andere ondersteunde MIDI berichten - bekijk de API documentatie voor alle functies die starten met midi_.

Verbinden met een MIDI apparaat

Om een MIDI bericht naar een extern apparaat te versturen, moet deze eerst zijn verbonden. Bekijk de subsectie ‘Verbinden van een MIDI Controller’ in sectie 11.1 voor meer details. Merk op dat wanneer USB wordt gebruikt, het verbinden naar een apparaat waar data toe wordt verzonden (anders dan ontvangen) dezelfde procedure is. Indien gebruik wordt gemaakt van DIN connectoren moet verbonden worden met de ‘MIDI out’ poort van de computer. Hiervoor moet je MIDI apparaat in het voorkeuren paneel zichtbaar zijn.

Versturen van MIDI events

De vele midi_* functies werken zoals play, sample en synth op de manier dat ze een bericht sturen via de huidige (logische) tijd. Om bijvoorbeeld calls uit te delen naar midi_* functies kan sleep worden gebruikt, zoals gedaan via play. Laten we hiernaar kijken:

midi_note_on :e3, 50

Dit zal een MIDI noot versturen naar het verbonden MIDI apparaat met velocity 50. (Merk op dat Sonic Pi automatisch noten converteert in de vorm :e3 naar de equivalente MIDI nummers zoals, in dit geval, 52.)

Indien je verbonden MIDI apparaat een synthesizer betreft, zou je een noot moeten kunnen horen. Om dit uit te schakelen kan midi_note_off worden gebruikt:

midi_note_off :e3

Selecteren van een MIDI apparaat

By default, Sonic Pi will send each MIDI message to all connected devices on all MIDI channels. This is to make it easy to work with a single connected device without having to configure anything. However, sometimes a MIDI device will treat MIDI channels in a special way (perhaps each note has a separate channel) and also you may wish to connect more than one MIDI device at the same time. In more complicated setups, you may wish to be more selective about which MIDI device receives which message(s) and on which channel.

We can specify which device to send to using the port: opt, using the device name as displayed in the preferences:

midi_note_on :e3, port: "moog_minitaur"

We can also specify which channel to send to using the channel: opt (using a value in the range 1-16):

midi_note_on :e3, channel: 3

Of course we can also specify both at the same time to send to a specific device on a specific channel:

midi_note_on :e3, port: "moog_minitaur", channel: 5

MIDI Studio

Finally, a really fun thing to do is to connect the audio output of your MIDI synthesiser to one of the audio inputs of your soundcard. You can then control your synth with code using the midi_* fns and also manipulate the audio using live_audio and FX:

reverb,

(The fn midi is available as a handy shortcut to sending both note on and note off events with a single command. Check out its documentation for further information).