You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scd/padsynth practice EF-edit.scd

110 lines
2.6 KiB
Plaintext

s.boot;
MIDIClient.init;
MIDIIn.connectAll;
MIDIClient.sources.do;
(
SynthDef(\rhubarb, {
|freq = 440, gate = 1, cutoff = 1e4, rq = 0.3, amp = 0.05, modDepth = 0.3, modDepth2 = 0.5, noiseLevel = 0.8, ringFreq = 80, detune = 0|
var env, osc1, osc2, osc3, filt1, filt2, filt3, lfo, lfo2, noise, noiseFilt, sig1, sig2, sig3, mix;
// Slightly Different Oscillators
osc1 = LFTri.ar(freq + detune);
osc2 = Pulse.ar(freq + detune);
// osc1 = LFTri.ar((freq + detune) * 1);
// osc2 = Pulse.ar((freq + detune)* 0.5);
osc3 = SawDPW.ar(freq * 2);
// LFO to Modulate Filter Frequency
lfo = LFNoise2.kr(20).range(1 - modDepth, 1 + modDepth);
lfo2 = LFNoise2.kr(1).range(1 - modDepth, 1 + modDepth);
// lfo2 = noise;
// Apply Different Filters to Each Oscillator
filt1 = SVF.ar(osc1, cutoff * lfo, rq);
filt2 = RLPF.ar(osc2, cutoff * lfo, rq);
filt3 = RLPF.ar(osc3, cutoff * lfo2, rq);
// ADSR Envelope
env = EnvGen.kr(Env.adsr(0, 0.3, 0.3, 0.1), gate, doneAction: 2);
// Panning and Mixing
sig1 = Pan2.ar(filt1 * env * amp, -0.3);
sig2 = Pan2.ar(filt2 * env * amp, 0.3);
sig3 = Pan2.ar(filt3 * env * amp, 0);
// sig2 = GVerb.ar(sig2, 299, 4);
// mix = mix + (noise * env * noiseLevel); // Add noise with envelope control
// mix = DelayC.ar(mix, maxdelaytime: 0.2, delaytime: 0.3);
// Output
Out.ar(0, sig2!2);
}).add;
)
Synth(\rhubarb)
(
// Test pattern
Pbind(
\instrument, \rhubarb,
/*\degree, Pseq([
[2, 4, 7, 12], [1, 5, 9], [4, 7, 11], [5, 9, 8]
], inf), // Chord progression*/
\degree, Pseq([[2, 7, 11], [1, 5, 9], [3, 9], [1,3,5]], inf),
// \degree, Pseq([2, 4, 11,], inf),
// \dur, 0.5, // Duration of each chord
\amp, 0.08, // Volume
// \cutoff, 1200,
\detune, -2, // Slight detune
\pan, Pwhite(-0.3, 0.3), // Random stereo width
).play;
)
(
// MIDI
// EMF: one major issue here is that ~notes is never actually initialized as an array, so it's nil. when you try to store a Synth at index nn, SC throws an error, because you can't put an item into nil. So, we first initialize ~notes as an array of size 128. After I add this line, your polyphonic MIDI code seems to work fine (no stuck notes)
~notes = Array.newClear(128);
MIDIdef.noteOn(\noteOnTest, {
arg vel, nn, chan, src;
// [vel, nn].postln;
~notes[nn] = Synth.new(
\rhubarb,
[
\freq, nn.midicps,
\amp, vel.linexp(1,127,0.01,0.3),
\gate, 1,
\detune, 2,
\cutoff, 400,
\rq, 0.5,
]
);
});
MIDIdef.noteOff(\noteOffTest, {
arg vel, nn;
// [vel, nn].postln;
~notes[nn].set(\gate, 0);
~notes[nn] = nil;
});
)