Full SuperCollider script #
The complete Slow Harmonic Pad instrument uses stock SuperCollider units. Set ~soundStage from 1 to 3 and evaluate the entire block again to select a cumulative stage. Wait for the ready message; ~soundNote.(60, 0.8, 1) plays MIDI 60 at velocity 0.8 with a one-second held duration. Held duration controls when release begins, while each source's decay and modulation continue independently. ~soundStop.() frees the active instrument and its effects. This block replaces the previously installed PlayGrid instrument in the same interpreter.
(
~soundStage = 3;
~soundOutputScale = 1.133972;
~soundRelease = 4.3;
~soundNames = (motion: \pgSlowHarmonicPadMotion, voice: \pgSlowHarmonicPadVoice, effects: \pgSlowHarmonicPadEffects);
~pgWave = { |freq, amplitude=1, phase=0, partials=#[1]|
Mix(partials.collect { |weight, i|
var harmonic = freq * (i + 1);
SinOsc.ar(harmonic.clip(0.01, 22000), phase * 2pi * (i + 1)) * weight * (harmonic < 22000)
}) * amplitude;
};
~soundDefs = [
SynthDef(\pgSlowHarmonicPadMotion, { |out=0| Out.kr(out, DC.kr(0)) }),
SynthDef(\pgSlowHarmonicPadVoice, { |out=0, midi=60, velocity=0.8, gate=1, startMidi=60|
var stage = ~soundStage;
var aA = 0, aB = 0, aC = 0, aD = 0, aL = 0, aR = 0, aSource = 0, iHz = 0;
var iVelocity = 0, kA = 0, kB = 0, kC = 0, kD = 0, kHz = 0, kTrem = 0;
iHz = (midi).midicps;
iVelocity = (velocity).clip(0, 1);
kHz = (iHz * (2 ** ((0 - 14) / 12)));
kA = EnvGen.kr(Env([0, 1, 1, 0], [2.057, 0.5, 4.3], \lin, releaseNode: 2), gate);
aA = ~pgWave.((kHz * 9), kA, 0, [1, 0.767361489, 0.298538262, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
aSource = (aA * (0.6 + (0.4 * iVelocity)));
if((stage >= 2)) {
kB = EnvGen.kr(Env([0, 1, 1, 0], [2.294, 0.5, 3.7], \lin, releaseNode: 2), gate);
aB = ~pgWave.((kHz * 1.003), (kB * ((0 - 1.9)).dbamp), 0, [0, 0.0462381021, 0, 0.0518800039, 0, 0.0446683592, 0, 0.0298538262, 0, 0.0812830516, 0.199526231, 0.167880402, 0.221309471, 0.201836636, 0.136458314, 0.103514217, 0.0776247117, 0, 0.192752491, 0.266072506, 0.221309471, 0.216271852, 0.171790839, 0.0699841996, 0.0575439937, 0.0891250938, 0, 0.147910839, 0.28840315, 0.0812830516, 0.221309471, 0.0323593657, 0.0758577575, 0.034673685, 0.181970086, 0.0416869383, 0.167880402, 0.0653130553]);
aSource = (aSource + (aB * (1 + (0 * iVelocity))));
kC = EnvGen.kr(Env([0, 1, 1, 0], [2.8, 0.5, 4.1], \lin, releaseNode: 2), gate);
aC = ~pgWave.((kHz * 1), (kC * ((0 - 9.1)).dbamp), 0, [0, 0.0462381021, 0, 0.0518800039, 0, 0.0446683592, 0, 0.0298538262, 0, 0.0812830516, 0.199526231, 0.167880402, 0.221309471, 0.201836636, 0.136458314, 0.103514217, 0.0776247117, 0, 0.192752491, 0.266072506, 0.221309471, 0.216271852, 0.171790839, 0.0699841996, 0.0575439937, 0.0891250938, 0, 0.147910839, 0.28840315, 0.0812830516, 0.221309471, 0.0323593657, 0.0758577575, 0.034673685, 0.181970086, 0.0416869383, 0.167880402, 0.0653130553]);
aSource = (aSource + (aC * (1 + (0 * iVelocity))));
kD = EnvGen.kr(Env([0, 1, 1, 0], [2.38, 0.5, 4], \lin, releaseNode: 2), gate);
aD = ~pgWave.((kHz * 1), (kD * ((0 - 6)).dbamp), 0, [0.120226443, 0, 0.24266101, 0, 0.254097271, 0, 0.144543977, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
aSource = (aSource + (aD * (0.65 + (0.35 * iVelocity))));
};
if((stage >= 3)) {
kTrem = (SinOsc.kr(0.35, 0 * 2pi) * 1);
aSource = (aSource * (0.82 + (0.18 * kTrem)));
};
aL = (aSource * ((0 - 33)).dbamp);
aR = aL;
Out.ar(out, [aL, aR]);
EnvGen.kr(Env.asr(0.0001, 1, 4.3), gate, doneAction: 2);
}),
SynthDef(\pgSlowHarmonicPadEffects, { |in=0, out=0|
var stage = ~soundStage;
var outputScale = ~soundOutputScale;
var input = In.ar(in, 2);
var feedback = LocalIn.ar(2);
var aChFbL = 0, aChFbR = 0, aChInL = 0, aChInR = 0, aChMid = 0, aChSide = 0, aChTimeL = 0, aChTimeR = 0;
var aL = 0, aR = 0, aTapL = 0, aTapR = 0, kCh = 0;
aL = input[0];
aR = input[1];
if((stage >= 3)) {
aChFbL = feedback[0];
aChFbR = feedback[1];
aChInL = aL;
aChInR = aR;
kCh = (SinOsc.kr(0.9, 0 * 2pi) * 1);
aChTimeL = K2A.ar((7 + (3.4000000000000004 * kCh)));
aChTimeR = K2A.ar((7 - (3.4000000000000004 * kCh)));
aTapL = DelayC.ar((aChInL + (aChFbL * (0 - 0.02))), 80 / 1000, (aChTimeL / 1000).clip(0.00002, 80 / 1000));
aTapR = DelayC.ar((aChInR + (aChFbR * (0 - 0.02))), 80 / 1000, (aChTimeR / 1000).clip(0.00002, 80 / 1000));
aChFbL = aTapL;
aChFbR = aTapR;
aL = ((aL * 0) + (aTapL * 1));
aR = ((aR * 0) + (aTapR * 1));
aChMid = ((aL + aR) * 0.5);
aChSide = (((aL - aR) * 0.5) * 1.3);
aL = (aChMid + aChSide);
aR = (aChMid - aChSide);
};
LocalOut.ar([aChFbL, aChFbR].collect { |channel| channel + DC.ar(0) });
Out.ar(out, [((aL * 1) * outputScale), ((aR * 1) * outputScale)]);
})
];
~soundStop = {
if(~cirrusGroup.notNil) { ~cirrusGroup.free; ~cirrusGroup = nil };
if(~cirrusAudio.notNil) { ~cirrusAudio.free; ~cirrusAudio = nil };
if(~cirrusMotion.notNil) { ~cirrusMotion.free; ~cirrusMotion = nil };
if(~pgGroup.notNil) { ~pgGroup.free; ~pgGroup = nil };
if(~pgAudio.notNil) { ~pgAudio.free; ~pgAudio = nil };
if(~pgMotion.notNil) { ~pgMotion.free; ~pgMotion = nil };
};
~soundInstall = {
s.waitForBoot {
~soundStop.();
~soundDefs.do { |definition| definition.add };
s.sync;
~pgAudio = Bus.audio(s, 2);
~pgMotion = Bus.control(s, 1);
~pgGroup = Group.head(s);
~pgLastMidi = 60;
Synth.head(~pgGroup, ~soundNames.motion, [\out, ~pgMotion]);
~pgVoices = Group.tail(~pgGroup);
Synth.tail(~pgGroup, ~soundNames.effects, [\in, ~pgAudio]);
"Slow Harmonic Pad ready".postln;
};
};
~soundNote = { |midi=60, velocity=0.8, hold=1|
var note = Synth.head(~pgVoices, ~soundNames.voice, [
\out, ~pgAudio, \midi, midi, \velocity, velocity.clip(0, 1),
\startMidi, ~pgLastMidi
]);
~pgLastMidi = midi;
SystemClock.sched(hold, { note.set(\gate, 0); nil });
note;
};
if(~soundOffline != true) { ~soundInstall.() };
)