Skip to content

Instantly share code, notes, and snippets.

@Rampoina
Created September 29, 2015 00:40
Show Gist options
  • Save Rampoina/24ab2fe8da288af951ee to your computer and use it in GitHub Desktop.
Save Rampoina/24ab2fe8da288af951ee to your computer and use it in GitHub Desktop.
(
MIDIClient.init;
MIDIIn.connectAll;
~sustain = 0;
~notes = Array.newClear(16);
~ys = Array.newClear(16);
MIDIdef.noteOn(\noteOnTest, {
arg vel, nn, chan, src;
~notes[chan].set(\gate, 0);
~notes[chan] = Synth.new(\tone, [\freq, nn.midicps, \amp, vel.linexp(1,127,0.01,1), \gate, 1, \yControl, ~ys[chan]]);
});
MIDIdef.noteOff(\noteOffTest, {
arg vel, nn, chan;
~notes[chan].set(\gate, 0);
~notes[chan] = nil;
});
});
MIDIdef.touch(\touchTest, {
arg vel, chan;
~notes[chan].set( \amp, vel.linexp(1,127,0.01,1));
});
MIDIdef.polytouch(\polyTouchTest, {
arg vel, nn, chan;
~notes[chan].set( \amp, vel.linexp(1,127,0.01,1));
});
MIDIdef.cc(\cc, {
arg val, ccNum, chan, lel;
var a = ccNum;
if (ccNum == 64, {
if (val > 0, {
"OFF".postln;
~sustain = 0;
}, {
~sustain = 1;
"ON".postln;
}
);
});
if (ccNum == 74, {
if (~notes[chan] == nil, {
~ys[chan] = val;
});
~notes[chan].set(\yControl, val);
//val.postln;
});
});
MIDIdef.bend(\bendTest, {
arg val, chan, src;
~notes[chan].set(\bend, val.linlin(0,16383, -24,24))
});
SynthDef.new(\tone,
{
arg freq=440, amp=0.3, gate=0, bend=0, yControl = 0;
var decay = 5;
var coef = 0.1;
var sig, env, snd1, env2, f, y;
y = yControl.linlin(30, 127, 0.5, 0.9);
f = freq* bend.midiratio;
env = EnvGen.kr(Env.adsr, gate, doneAction:2);
//sig = LFTri.ar(f)*amp*AmpComp.kr(f, 46.25, 0.85);
sig = Pulse.ar(freq * bend.midiratio, width: y , mul: amp*AmpComp.kr(42, 0.8));
sig = RLPF.ar(sig, freq: 500);
sig = FreeVerb.ar(sig, 0.4, 0.8)*env!2;
Out.ar(0, sig);
}).add;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment