( ~notes = Array.newClear(128); // Initialize the array to store synths // Handle noteOn for MIDI device 8454149 (first device) MIDIdef.noteOn(\noteOnTest_device1, { arg vel, nn, chan, src; [vel, nn, src].postln; // Post the velocity, note number, and source to the console // Only respond to MIDI input from source 8454149 (device 1) if (src == 8454147, { // Create a new synth for device 1 ~notes[nn] = Synth.new( \mellotron, [ \freq, nn.midicps, \amp, vel.linexp(1,127,0.01,0.3), ] ); }); }); // Handle noteOff for MIDI device 8454149 (first device) MIDIdef.noteOff(\noteOffTest_device1, { arg vel, nn, chan, src; [vel, nn, src].postln; // Only respond to MIDI input from source 8454149 (device 1) if (src == 8454147, { // Turn off the synth and free the memory for device 1 ~notes[nn].set(\gate, 0); ~notes[nn] = nil; }); }); // Handle noteOn for MIDI device 8454145 (second device) MIDIdef.noteOn(\noteOnTest_device2, { arg vel, nn, chan, src; [vel, nn, src].postln; // Post the velocity, note number, and source to the console // Only respond to MIDI input from source 8454145 (device 2) if (src == 8454146, { // Create a new synth for device 2 ~notes[nn] = Synth.new( \fm_pulsar_terrain, [ \freq, nn.midicps, \amp, vel.linexp(1,127,0.01,0.3), ] ); }); }); // Handle noteOff for MIDI device 8454145 (second device) MIDIdef.noteOff(\noteOffTest_device2, { arg vel, nn, chan, src; [vel, nn, src].postln; // Only respond to MIDI input from source 8454145 (device 2) if (src == 8454146, { // Turn off the synth and free the memory for device 2 ~notes[nn].set(\gate, 0); ~notes[nn] = nil; }); }); )