SuperCollider Class
Creating a "cavern" class (March 2019).
Supercollider classes have a couple of different uses. Some people tend not to use the class structure when programming in SC. This is understandable - you can do a lot without using them. However in the current project I am putting some of the code blocks and algorithms into classes. Note that this kind of SC class is really an encapsulation of various blocks of code and is not connected to any C++ server side programming. Thus we are not constructing a "ugen".
The project is focused on "ambient" forms - in this particular case "Caverns". The class below gives one a prototype of "dripping" and "glopping" in a cavern. No effects yet in this iteration.
Synth2{
//instance vars
var mInput;
var mSynth;
var mWin;
*new { arg xx;
^super.new.init(xx);
}
init { arg xx;
~filter1 = 2000;
~filter2 = 2000;
~filter2a = 2000;
~dur =0.05;
Server.default.waitForBoot({fork{
Server.default.sync; // sync to the server
this.addSynthDef.value;
{ this.makeGui.value; }.defer;
}});
}
addSynthDef {
SynthDef(\testz, { arg out = 0, amp = 1, bPassF = 2000, hPassF = 3000, pan = 0, decay = 0.06, filtF = 400, amp_z =1;
var z = BPF.ar(BrownNoise.ar(0.8.dup), bPassF, 0.2, mul: amp);
var z2 = HPF.ar(z, hPassF, 0.2, mul: amp);
var env = EnvGen.kr(Env.perc(0.01, decay), doneAction: 2);
Out.ar(out, Pan2.ar(LPF.ar(z, filtF), pan, env*amp_z));
}).add;
SynthDef(\testz2, { arg out = 0, amp = 1, bPassF2 = 2000, hPassF = 3000, pan = 0, decay = 0.06, filtF2 = 400, amp_z =1;
var z = BPF.ar(GrayNoise.ar(1.0.dup), bPassF2, 0.2, mul: amp);
var z2 = HPF.ar(z, hPassF, 0.2, mul: amp);
var env = EnvGen.kr(Env.perc(0.01, decay), doneAction: 2);
Out.ar(out, Pan2.ar(LPF.ar(z2, filtF2), pan, env*amp_z));
}).add;
Server.default.sync;
}
makeGui{
QtGUI.palette = QPalette.dark;
mWin = Window.new(
"Synther1",
Rect( left:20, top:20,
width: 300, height: 400 ));
mWin.background = Color.blue(0.3,1);
mWin.layout = HLayout(
VLayout(
StaticText().string_("Cavern_1"),
Button()
.states_([
["OFF", Color.gray(0.2), Color.green(0.8)],
["ON", Color.gray(0.8), Color.grey(0.2)] ])
.mouseDownAction_({
arg state;
state.value.postln;
if (state.value == 0) {
mSynth = (
Pbind(
\instrument, Prand([ \testz,\testz2],inf),
\bPassf, Pwhite(100,12000, inf),
\bPassF2, Pfunc{~filter2},
\decay, Pfunc{~dur},
\hPassf, Pwhite(100,13000, inf),
\pan, Pwhite(0.0, 1, inf),
\filtF, Pfunc{~filter1},
\filtF2, Pwhite(80, 20000, inf),
\dur, Pwhite(0.01,0.3,inf);
).play;
)
} {
mSynth.stop;
}
})
.minHeight_(70)
.minWidth_(70),
nil
),
VLayout(
//PopUpMenu().items_(["buffer1","file2","file3"]).font_(Font("Sans",20)),
StaticText().string_("Filter"),
Slider2D()
.x_(0.05)
.y_(0.05)
.action_({ arg slider;
~filter1 = slider.y.value.linexp(0,1,300,20000,nil);
~filter2 = slider.x.value.linexp(0,1,30,20000,nil);
}),
StaticText().string_("Grain Length"),
Slider(nil,Rect(0,0,50,10))
.minHeight_(20)
.thumbSize_(50)
.action_({ arg slider2;
~dur = slider2.value.linexp(0,1,0.06,0.5,nil);
})
),
);
mWin.front;
mWin.alwaysOnTop = true;
mWin.onClose_({
mSynth.free;
})
}
}
//some of this code is modified from various sources - the class template comes from Koutsomichalis "Mapping and Visualization".
The code above is a .sc file that needs to be put into the Extensions folder of the Supercollider application. You then run it with "Synth2.new" from a standard SC IDE and the GUI appears. Obviously this is only a rudimentary structure at this point. No effects and other components that are required. Also some of the class variables are structured as environmental variables in the code above. Note also that I have assigned an argument "xx" to the init - it has no value at the moment and is not used.