Just intonation MIDI keyboard with SuperCollider
/** | |
* Just intonation MIDI keyboard with SuperCollider | |
*/ | |
MIDIIn.connect; | |
s.boot; | |
( | |
SynthDef("umbSimpleFM",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var m_amp, mod, car; | |
m_amp = 100; | |
mod = SinOsc.ar(freq*2, 0, m_amp); | |
car = SinOsc.ar(freq + mod, 0, amp); | |
car = EnvGen.kr(Env.adsr(0.01,0.3,0.5,1,0.6,-4),gate,doneAction: 2) * car; | |
Out.ar(0, Pan2.ar(car,pan)); | |
}).add; | |
) | |
( | |
var keys, scale; | |
keys = Array.newClear(128); | |
scale = Scale.chromatic.postln; | |
scale.tuning_(\just); // Just intonation | |
//scale.tuning_(\et12); // Twelve-tone equal temperament | |
//scale.tuning_(\mean4); // Meantone, 1/4 Syntonic Comma | |
//scale.tuning_(\pythagorean); // Pythagorean | |
~noteOnFunc = {arg src, chan, num, vel; | |
var node, freq; | |
node = keys.at(num); | |
if (node.notNil, { | |
node.release; | |
keys.put(num, nil); | |
}); | |
node = Synth.tail( | |
nil, "umbSimpleFM",[ | |
\freq, {freq = num.keyToDegree(scale, 12).degreeToKey(scale).midicps}, | |
\amp, vel/127 | |
]); | |
keys.put(num, node); | |
[chan,num,freq,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
This comment has been minimized.
Thank you! I've been trying to figure this out over the last week!