home/ atoms/ sc-midi-input

SC receives MIDI via MIDIIn.connectAll and MIDIdef callbacks; ADSR gate management requires per-note synth node tracking

SuperCollider handles MIDI input through MIDIIn.connectAll (connects all devices) and MIDIdef responders. For sustained notes with an ADSR envelope, each note-on must create a Synth and store its node reference in an array indexed by MIDI note number; the note-off handler sends .set(\gate, 0) to that specific node. Without per-note tracking, pressing the same key twice creates orphan synths that won’t release. vel.linlin(0, 127, 0, 1) scales MIDI velocity to SC’s 0–1 amplitude range.

Examples

MIDIIn.connectAll;
varnoteArray = Array.newClear(128);
MIDIdef.noteOn(\down, {|vel, note|
  noteArray[note] = Synth("qs", [\freq, note.midicps, \amp, vel.linlin(0,127,0,1)]);
});
MIDIdef.noteOff(\up, {|vel, note|
  noteArray[note].set(\gate, 0);
});

Assessment

Explain why a simple noteOn handler that creates a Synth without note tracking fails for polyphonic ADSR patches. Write the corrected version with an Array-based note tracker.

“needstokeeptrackofwhichsynthno de corresp ondstoeachkey.WecanuseanArrayforthatpurp ose,asshowninthee”
corpus · a-gentle-introduction-to-supercollider-bruno-ruviaro · chunk 16