home/ atoms/ sc-midi-responder

SuperCollider responds to incoming MIDI by registering callback functions on MIDI message types

MIDIIn.connect (or MIDIClient.init + MIDIIn.connectAll) opens MIDI input ports. You assign handler functions to MIDIIn.noteOn, .noteOff, .control, .bend, etc. Each function receives port, channel, note number, and velocity (or control number and value). The MIDIFunc / MIDIdef API (modern) adds named, filterable responders that can be removed or replaced. This lets SC respond to hardware controllers, keyboards, and sequencers in real time without polling.

Examples

MIDIIn.connect; MIDIIn.noteOn = { |port, chan, note, vel| Synth.new(\default, [\freq, note.midicps, \amp, 0.2]) };

Assessment

Connect a MIDI keyboard to SC (or use a virtual device). Register a noteOn responder that triggers a custom SynthDef and a noteOff responder that releases it. Test with rapid repeated notes to check polyphony.

“MIDIIn.connect; MIDIIn.connect(0,3); // assigns a function to incoming noteOn messages MIDIIn.noteOn = { |port, chan, note, vel|”
corpus · the-supercollider-book-official-code-examples-scbookcode-gpl · chunk 138