Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@kisielk 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