Last active
December 16, 2021 08:53
-
-
Save umbrellaprocess/973d2aa16e95bf329ee2 to your computer and use it in GitHub Desktop.
A simple example of MIDI Keyboard for SuperCollider 3.6.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple example of MIDI Keyboard for SuperCollider 3.6.x | |
*/ | |
MIDIIn.connect; | |
s.boot; | |
( | |
SynthDef("umbSinewave",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = SinOsc.ar(freq, 0, amp); | |
x = EnvGen.kr(Env.adsr(0.01,0.3,0.5,1,0.6,-4),gate,doneAction: 2) * x; | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
) | |
( | |
var keys; | |
keys = Array.newClear(128); | |
~noteOnFunc = {arg src, chan, num, vel; | |
var node; | |
node = keys.at(num); | |
if (node.notNil, { | |
node.release; | |
keys.put(num, nil); | |
}); | |
node = Synth.tail(nil, "umbSinewave", [\freq, num.midicps, \amp, vel/127]); | |
keys.put(num, node); | |
[chan,num,vel/127].postln; | |
}; | |
MIDIIn.addFuncTo(\noteOn, ~noteOnFunc); | |
~noteOffFunc = {arg src, chan, num, vel; | |
var node; | |
node = keys.at(num); | |
if (node.notNil, { | |
node.release; | |
keys.put(num, nil); | |
}); | |
}; | |
MIDIIn.addFuncTo(\noteOff, ~noteOffFunc); | |
) | |
// cleanup | |
( | |
MIDIIn.removeFuncFrom(\noteOn, ~noteOnFunc); | |
MIDIIn.removeFuncFrom(\noteOff, ~noteOffFunc); | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, it is not quite keyboard, for that it not a physical nor virtual device that you may play on.
It is more of a «midi instrument» that is playable from any midi keyboard, physical or virtual, given it's properly connected to SC. ;)
i'd update a decription perhaps, like this:
«Minimal MIDI instrument playable from a MIDI keyboard (not included)» ;)