Hi, so I’m very new to SC so this is probably an incredibly stupid problem I am encountering but I cannot, for the love of myself, understand how to solve it. I’m exercising with the code and trying to understand scheduling, now, my problem is I created a GUI where a ‘start/stop’ button should manage a routine, only that whenever I press the button sclang.exe stops responding. I guess I’m missing some vital details and I just created an infinite loop so if anyone has a minute to spend helping a kind, and surely dumb, soul I’ll be very glad. Next is the entire code and as you can see it’s very basic because, again, I just started from zero with SuperCollider
SynthDef(\mySynth, {
|freq = 440, amp = 0.5, atk = 0.01, rel = 1|
var sig, env;
sig = SinOsc.ar(freq);
sig = LPF.ar(sig, 2000);
env = EnvGen.kr(Env.perc(atk, rel), doneAction: 2);
sig = sig * env * amp;
Out.ar(0, sig!2);
}).add;
~synthRoutine = nil;
// GUI
(
var window, startButton, freqSlider, ampSlider, atkSlider, relSlider;
window = Window("Synth Controller", Rect(100, 100, 300, 400));
window.view.decorator = FlowLayout(window.view.bounds);
startButton = Button(window, Rect(0, 0, 280, 20))
.states_([["Start", Color.black, Color.green], ["Stop", Color.black, Color.red]])
.action_({ |button|
if (button.value == 0) {
button.valueAction = 1;
~synthRoutine = Routine({
loop {
if (button.value == 0, {
"Stopping routine".postln;
~synthRoutine.stop;
});
Synth(\mySynth, [
\freq, freqSlider.value,
\amp, ampSlider.value,
\atk, atkSlider.value,
\rel, relSlider.value
]);
(0.5 + 1.5.rand).wait;
}
}).play(AppClock);
} {
button.valueAction = 0;
~synthRoutine.stop;
}
});
freqSlider = Slider(window, Rect(0, 0, 280, 20))
.value_(440)
.action_({ |sl| sl.value_(sl.value.clip(20, 2000)); });
StaticText(window, Rect(0, 0, 280, 20)).string_("Frequency");
ampSlider = Slider(window, Rect(0, 0, 280, 20))
.value_(0.5)
.action_({ |sl| sl.value_(sl.value.clip(0, 1)); });
StaticText(window, Rect(0, 0, 280, 20)).string_("Amplitude");
atkSlider = Slider(window, Rect(0, 0, 280, 20))
.value_(0.01)
.action_({ |sl| sl.value_(sl.value.clip(0.001, 1)); });
StaticText(window, Rect(0, 0, 280, 20)).string_("Attack");
relSlider = Slider(window, Rect(0, 0, 280, 20))
.value_(1)
.action_({ |sl| sl.value_(sl.value.clip(0.1, 10)); });
StaticText(window, Rect(0, 0, 280, 20)).string_("Release");
window.front;
)