2 summary:: send MIDI messages
3 related:: Classes/MIDIIn, Reference/MIDI, Reference/UsingMIDI
4 categories:: External Control>MIDI
7 a MIDIOut is bound to a specific link::Classes/MIDIEndPoint:: as defined by the operating system.
11 private::connectByUID, disconnectByUID
16 the index of the MIDIEndPoint in the code::MIDIClient.destinations:: array.
20 ## Mac OSX / Windows || uid is optional; if specified, it should be the uid of that port ie. MIDIClient.destinations[port].uid. If you don't provide a uid, the correct uid will be filled in for you (easier).
21 ## Linux || using the uid is optional as described below.
25 Searches for the device by name. This is safer then depending on the index which will change if your studio setup changes.
27 //list connected out ports with names:
29 MIDIClient.destinations;
33 Searches for a connected MIDIEndPoint by name.
35 //list connected out ports with names:
37 MIDIClient.destinations;
40 method::connect, disconnect
41 Linux only. OS X does not need to connect. On Linux it is an optional feature (see below).
45 private::send, prSysex
48 This sets the latency with which a midi event is sent out. Per default this is set to 0.2, in order to be equal to the Server.latency.
50 On Linux there seems to be an ALSA or kernel bug if the latency is larger than 0, for some Linux kernels. If MIDIOut does not seem to work, set the latency to 0.
61 m.noteOff(16, 61, 60);
65 MIDIIn.connect; // 1 port midi interface
66 MIDIIn.sysex = { arg uid, packet; [uid,packet].postln };
67 MIDIIn.sysrt = { arg src, chan, val; [src, chan, val].postln; };
68 MIDIIn.smpte = { arg src, chan, val; [src, chan, val].postln; };
70 m.sysex(Int8Array[ 16rf0, 0, 0, 27, 11, 0,16rf7])
79 subsection::Using patterns for sending MIDI events
85 a = Pbind(\degree, Prand([1, 2, 3, [0, 5]], inf), \bend, Pwhite(0, 76, inf));
88 // chain a midi event into the pattern and play it (see Pchain)
90 (a <> (type: \midi, midiout: m)).play;
93 See link::Tutorials/A-Practical-Guide/PG_08_Event_Types_and_Parameters#midi_output#PG_08_Event_Types_and_Parameters: MIDI Output:: for a list of midi commands supported by the 'midi' event type.
95 subsection::Linux specific: Connecting and disconnecting ports
97 On Linux, a MIDIOut can be created without setting the destination:
103 In this case each message will be sent to all ports connected to SuperCollider's first MIDI output.
105 A connection can be made through:
111 Note that by connecting in this way, you can connect more than one destination to the MIDI output.
112 You can also use other tools to connect to a MIDIOut port of SC, e.g. through aconnect or QJackCtl (on the ALSA tab).
114 If you set the uid in MIDIOut, a direct connection is established and data will only be sent to that MIDI input port, and not to any other connections made to SC's MIDI output port (through the connect message or external tools).
116 subsection::OS X specific: Sending MIDI to other applications
118 Open the Audio MIDI Setup application. Double-click on IAC Driver and check "device is online".
122 MIDIClient.init(numIns,numOuts)
124 The IAC Bus will now appear in MIDIClient.destinations. It will appear first, which means that any code that you have written that addresses the first physical bus as 0 will now have to be changed.
126 For this reason it is always safer to find the port by name :
128 MIDIOut.newByName("RemoteSL IN","Port 1");
130 The IAC Bus will now also appear to other applications.
133 MIDIMonitor (freeware) can be very useful for troubleshooting:
135 http://www.snoize.com/MIDIMonitor/
137 subsection::Sysex example
139 a machinedrum manual say sysex commands should be formatted like this...
141 $f0,$00,$20,$3c,$02,$00,command,...,$f7
144 and to set the tempo the machinedrum expects this command...
147 %0aaaaaaa | Upper bits
148 %0bbbbbbb | Lower bits
150 Note: Tempo = %aaaaaaabbbbbbb / 24, max 300 BPM, min 30 BPM
153 so to create and send a valid set tempo sysex command from SuperCollider to this machinedrum do...
157 m.sysex(Int8Array[0xf0, 0x00, 0x20, 0x3c, 0x02, 0x00, 0x61, 21, 54, 0xf7]);
160 This will set the tempo to 114.23 bpm. One can calculate the upper and lower 7bit values like this...
163 var bpm, val, upper, lower;
165 val = (bpm*24).round.asInteger;
166 upper = val&2r11111110000000>>7;
167 lower = val&2r00000001111111;
168 [upper, lower].postln;
171 where the resulting 21 and 54 are the same as 2r0010101 and 2r0110110 in binary notation.