Setting up MIDI

This section is all about using FoxDot players to sequence musical events using an external MIDI device. This requires the most up-to-date versions of FoxDot and the SuperCollider “FoxDot Quark”. You can find out more about keeping updated here.

Sending messages to a MIDI device

The first thing to do is connect your laptop to your MIDI device and make sure the correct drivers are installed – this usually happens automatically but not always. Next, make sure that SuperCollider can “see” the device. To do this, open SuperCollider and run this line of code:


You should then see a message in the “post window” along these lines:

MIDI: device 0 2 -1202759152  (Microsoft GS Wavetable Synth)
MIDI: device 1 3 -1202759144  (USB2.0-MIDI)
MIDI Sources:
	MIDIEndPoint("USB2.0-MIDI", "USB2.0-MIDI")
MIDI Destinations:
	MIDIEndPoint("Microsoft GS Wavetable Synth", "Microsoft GS Wavetable Synth")
	MIDIEndPoint("USB2.0-MIDI", "USB2.0-MIDI")
-> MIDIClient

If not, then please consult the SuperCollider documentation on MIDIClient. This a list of the MIDI devices that SuperCollider (and FoxDot) can send messages to. The first device is Microsoft’s internal MIDI synth for Windows and the second is an external device connected by USB (these might have different names depending on the device and connection). By default, FoxDot will send messages to the first MIDI destination (“Microsoft GS Wavetable Synth” in this example) but you can select a different device by running the same code but with the index of the preferred device in brackets. So to select the “USB2.0-MIDI” device I would run:


You can now send messages to your MIDI device from FoxDot! To do this, you need to use the MidiOut synth. It operates the same as a normal synth but sends pitch and amplitude messages to a MIDI device e.g.

p1 >> MidiOut([0,1,2,3,4,5], dur=PDur(3,8), amp=[1,1/2,1/2]).every(6, "stutter", 4, dur=3, oct=6)

You can specify the MIDI channel as you would do any other attribute e.g. using channel = 1, which defaults to 0.

p1 >> MidiOut([0,1,2,3], channel = 1)

Note: Be careful when repeating the same note with the same duration; if a MIDI note-on event is triggered slightly before the MIDI note-off for the previous event, it will be stopped by the note-off. This is a known bug and being looked into.

Synchronising MIDI messages and FoxDot messages

If you are using both FoxDot and your MIDI device, you may notice that the sound events are not in sync. To fix this you need to manually set the Clock.midi_nudge value, which adds a delay to the MIDI messages. Here is some example code to help sync up the messages:

p1 >> MidiOut([0,4])

p2 >> play("x * ")

# Value is usually between 0.15 and 0.25
Clock.midi_nudge = 0.2

When the sounds are in sync they will stay in sync until the next time you start FoxDot, so remember this value!