Skip to content

Instantly share code, notes, and snippets.

@kisielk
Last active July 20, 2023 18:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kisielk/941ccd49b023c5b0e591a4967214d490 to your computer and use it in GitHub Desktop.
Save kisielk/941ccd49b023c5b0e591a4967214d490 to your computer and use it in GitHub Desktop.
Linnstrument + Supercollider
(
var notes, synths, on, off, mod, bend, touch;
~num_channels = 8;
~bend_range = 24;
MIDIIn.connectAll;
notes = Array.newClear(~num_channels);
synths = Array.newClear(~num_channels);
on = MIDIFunc.noteOn({ | vel, num, chan, src |
// ("on" + chan + num + vel).postln;
notes[chan] = num;
synths[chan] = Synth(\default, [\freq, num.midicps, \amp, vel * (1.0/128.0)]);
});
off = MIDIFunc.noteOff({ | vel, num, chan, src |
// ("off" + chan + num + vel).postln;
synths[chan].release;
notes[chan] = nil;
synths[chan] = nil;
});
mod = MIDIFunc.cc({ | val, num, chan, src |
// ("cc1" + chan + num + val).postln;
}, 1);
bend = MIDIFunc.bend({ | val, chan, src |
var bend = ~bend_range * ((val - 8192)/8192);
// ("bend" + chan + val).postln;
if (synths[chan] != nil) {
synths[chan].set(\freq, (notes[chan] + bend).midicps);
};
});
touch = MIDIFunc.touch({ | val, chan, src |
// ("touch" + chan + val).postln;
if (synths[chan] != nil) {
synths[chan].set(\amp, val * (1.0/128.0));
};
});
q = {
on.free;
off.free;
mod.free;
bend.free;
touch.free;
}
)
q.value;
@kisielk
Copy link
Author

kisielk commented Jun 24, 2016

Now we nil the notes and synths on note off. This is because sometimes pressure and bend messages make it to the handler before the note on, and it was causing errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment