Dear all,
I’m trying to use sclang from the command line to generate a short WAV file and then continue on to other tasks (all controlled from a Ruby script). To do this, I need sclang to exit so that my script can continue its next steps. At the moment. My SC saves audio correctly and exits the interpreter if run it from the IDE (select all and evaluate). However, if I run it with sclang from the command line (sclang autobot.scd
), it exits without saving an audio file. If I remove the exit command or add a short wait before it, the audio file saves; but, the process does not exit. I’m running SC 3.8 under macOS 10.13.
I’m not sure if there is a better way to handle what I’m doing. At the moment, this project is at the proof-of-concept stage. See my code below. I assume only the stuff around the render audio comment and below is relevant; but, I’m not sure.
Thanks for any help you can give.
David
(
r = Routine.new({
/////////////////
// setup steps //
/////////////////
~botStep = 0;
ScoreClock.beginScore;
ScoreClock.tempo = exprand(1, 2);
~baseFreq = exprand(50,200);
~botStep.yield; ~botStep = ~botStep + 1;
///////////////////
// pattern steps //
///////////////////
4.do({ |i|
p = Pbind(
\instrument, \klang,
\foo, 0,
\freq, Pwrand([[~baseFreq*2, ~baseFreq*2.02], [~baseFreq*3, ~baseFreq*3.03], [~baseFreq*4, ~baseFreq*4.04], [~baseFreq*1.9, ~baseFreq*1.82]], [6, 3, 3, 1].normalizeSum, inf),
\dur, (1/(i+2.pow(i))),
\do, Pfunc { |e| if (e.freq[0] == (~baseFreq*1.9)) { nil }{ e.postln; } },
).play(ScoreClock);
});
~botStep.yield; ~botStep = ~botStep + 1;
////////////////////
// make the score //
////////////////////
~score = ScoreClock.makeScore(60, 2);
~botStep.yield; ~botStep = ~botStep + 1;
//////////////////
// render audio //
//////////////////
~score.recordNRT(outputFilePath: ("/Users/david/Dropbox/castbot/wav/temp.wav").standardizePath, headerFormat: "WAV");
~botStep.yield; ~botStep = ~botStep + 1;
//////////////////
// exit program //
//////////////////
("done after" + ~botStep + "steps").postln;
// 10.wait; // Waiting allows audio to render, but sclang doesn't quit.
0.exit;
}); // end Routine r
);
r.nextN(5);