Skip to content

Instantly share code, notes, and snippets.

@KGZM
Created November 26, 2013 20:16
Show Gist options
  • Save KGZM/7665424 to your computer and use it in GitHub Desktop.
Save KGZM/7665424 to your computer and use it in GitHub Desktop.
Experimenting with SuperCollider.
(
var notes, on, off;
MIDIClient.init;
MIDIIn.connect();
SynthDef.new(\MonoSaw, {
|freq = 440, amp = 0.2,
dur = 1, gate = 0,
fc = 1.4|
//Oscillator Section
var osc = Saw.ar(freq);
//Filter Envelope
var filterEnv = Env.adsr(
attackTime: 0.5,
decayTime: 1,
sustainLevel: 0.2,
releaseTime: 2,
peakLevel: 1,
curve: -4,
bias: 0
);
var filterEG = EnvGen.ar(filterEnv, gate);
//Filter
var filter = DFM1.ar(
in: osc,
freq: freq * fc, //* filterEG * 1.4,
res: 0.5,
inputgain: 1,
type: 0, // 0 for LPF, 1 for HPF
noiselevel: 0.005,
mul: 1,
add: 0
);
//Amplifier Envelope
var ampEnv = Env.adsr(
attackTime: 0.2,
decayTime: 5,
sustainLevel: 0.8,
releaseTime: 5,
peakLevel: 0.9,
curve: -4,
bias: 0
);
var ampEG = EnvGen.ar(ampEnv, gate);
Out.ar(0, [filter * ampEG,filter * ampEG]);
}).add;
w = Window("My Synth", Rect(0,0, 500,600));
w.front;
EZKnob(w, label: "Cutoff",
controlSpec: ControlSpec(0.25, 2.0, \lin, 0.01, 1.4,\X),
action: { |ez| ~synth.set("fc", ez.value) }
);
~synth = Synth(\MonoSaw);
~triggers = 0;
~notes = List.new();
on = MIDIFunc.noteOn({ |veloc, num, chan, src|
~triggers = ~triggers + 1;
~notes.add(num.midicps);
~synth.set(\freq, num.midicps, \gate, 1, \amp, veloc * 0.00315);
});
off = MIDIFunc.noteOff({ |veloc, num, chan, src|
var oldpitch = ~notes.pop();
~synth.set(\gate, 0);
(~triggers >= 1).if({
~triggers = ~triggers - 1;
~synth.set(\freq, oldpitch);
});
});
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment