SC receives MIDI via MIDIIn.connectAll and MIDIdef, and tracks note on/off pairs using arrays indexed by MIDI note number
After MIDIIn.connectAll, SC can receive MIDI messages. MIDIdef.noteOn(key, func, ccNum, chan) registers a callback triggered on note-on; MIDIdef.noteOff handles release. For sustained ADSR synths, a 128-slot Array stores each active Synth reference at the index equal to the MIDI note number: on note-on, create a Synth and store it; on note-off, retrieve it by note number and call .set(\gate, 0). MIDIdef.cc handles continuous controllers. MIDIFunc.trace(true) monitors all incoming messages for debugging.
Examples
MIDIIn.connectAll; noteArray = Array.newClear(128); MIDIdef.noteOn(\on,{arg vel,note; noteArray[note]=Synth(‘quick2’,[\freq,note.midicps,\amp,vel.linlin(0,127,0,1)])}); MIDIdef.noteOff(\off,{arg vel,note; noteArray[note].set(\gate,0)});
Assessment
Describe why a single Synth variable is insufficient for polyphonic MIDI and how Array.newClear(128) solves the problem.