Neben dem Empfang von MIDI-Events können wir auch MIDI-Events aussenden, um externe Hardware-Synths, Keyboards und andere Geräte zu triggern und zu steuern. Sonic Pi bietet einen vollständigen Satz von fns zum Senden verschiedener MIDI-Nachrichten wie z.B:
Note on - midi_note_on
Note off - midi_note_off
Control change - midi_cc
Tonhöhenveränderung - midi_pitch_bend
Taktgeber - midi_clock_tick
Es gibt auch noch viele weitere MIDI-Meldungen – schau in der API-Dokumentation nach all den anderen Funktionen, die mit midi_
anfangen.
Um eine MIDI-Nachricht an ein externes Gerät zu senden, müssen wir es zuerst angeschlossen haben. Schau Dir den Unterabschnitt ‘Anschließen eines MIDI-Instruments’ in Abschnitt 11.1 für weitere Details an. Beachte, dass bei Verwendung von USB der Anschluss an ein Gerät, an das Du sendest (und nicht von dem Du empfängst), die gleiche Prozedur ist. Wenn Du jedoch die klassischen DIN-Anschlüsse verwendest, stell sicher, dass Du den MIDI-Ausgang Deines Computers verwendest. Du solltest Dein MIDI-Gerät in den Einstellungen sehen.
The many midi_*
fns work just like play
, sample
and synth
in that they send a message at the current (logical) time. For example, to spread out calls to the midi_*
fns you need to use sleep
just like you did with play
. Let’s take a look:
midi_note_on :e3, 50
Dieser sendet eine MIDI-Note auf Event an das angeschlossene MIDI-Gerät mit Velocity 50. (Beachte, dass Sonic Pi Noten in der Form :e3
automatisch in ihre entsprechende MIDI-Nummer wie z.B. 52 in diesem Fall konvertiert).
Wenn Dein MIDI-Gerät ein Synthesizer ist, solltest Du hören können, wie er eine Note spielt. Um dies zu deaktivieren, verwende midi_note_off
:
midi_note_off :e3
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"
Wir können auch angeben, an welchen Kanal gesendet werden soll, in dem wir die Option channel:
(mit einem Wert im Bereich 1-16) verwenden:
midi_note_on :e3, channel: 3
Natürlich können wir auch beides zur gleichen Zeit festlegen, um an ein bestimmtes Gerät auf einen bestimmten Kanal zu senden:
midi_note_on :e3, port: "moog_minitaur", channel: 5
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).