| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // MIDI note handling
- (
- var midiIn, synths;
- ~synths = IdentityDictionary.new; // Store active synths keyed by note number
- // Connect to MIDI
- MIDIClient.init;
- MIDIIn.connectAll;
- // Note On: create synth
- MIDIdef.noteOn(\noteOn, { |vel, num, chan, src|
- var freq = num.midicps;
- //postln("Note On: " + num + " Velocity: " + vel);
- if (vel > 0) {
- var synth = Synth(\rgbSynth, [
- \freq, freq,
- \amp, vel/127,
- \ampAttack, ~synthParams.ampAttack,
- \ampRelease, ~synthParams.ampRelease,
- \filterAttack, ~synthParams.filterAttack,
- \filterRelease, ~synthParams.filterRelease,
- \pitchAttack, ~synthParams.pitchAttack,
- \pitchRelease, ~synthParams.pitchRelease,
- \redAmt, ~synthParams.redAmt,
- \greenAmt, ~synthParams.greenAmt,
- \blueAmt, ~synthParams.blueAmt
- ]);
- ~synths[num] = synth;
- } { // Treat as noteOff if it is a noteOn with velocity 0
- //postln("Note On: " + num + " Velocity: " + vel);
- ~synths[num].set(\gate, 0);
- ~synths.removeAt(num);
- }
- });
- // Note Off: release synth
- MIDIdef.noteOff(\noteOff, { |vel, num, chan, src|
- //postln("Note Off: " + num + " Velocity: " + vel);
- ~synths[num].set(\gate, 0);
- ~synths.removeAt(num);
- });
- // Run these functions directly
- "MIDI functions loaded.".postln;
- )
|