I'm trying to have some fun with SuperCollider, and fun to me means running commands in a shell!
So far I've managed to play to speakers with:
rs.scd
s.waitForBoot({
// Play scale once.
x = Pbind(\degree, Pseq([0, 3, 5, 7], 1), \dur, 0.25);
x.play;
});
with:
sclang rs.scd
and save to a file as mentioned at https://doc.sccode.org/Guides/Non-Realtime-Synthesis.html with:
nrs.csd
x = Pbind(\degree, Pseq([0, 3, 5, 7], 1), \dur, 0.25).asScore(1, timeOffset: 0.001);
x.add([0.0, [\d_recv, SynthDescLib.global[\default].def.asBytes]]);
x.sort;
x.recordNRT(
outputFilePath: "nrt.aiff",
sampleRate: 44100,
headerFormat: "AIFF",
sampleFormat: "int16",
options: ServerOptions.new.numOutputBusChannels_(2),
duration: x.endTime
);
0.exit;
So to achieve my goal I'm missing:
- how to quit automatically after
rs.scd
finishes playing? I could do1.wait; 0.exit;
but that forces me to hardcode the1
, which is the length in seconds of the 4 0.25s notes being played. That1
is also hardcoded innrs.csd
, and it would be great to be able to factor it out there as well. - how to make a single file that can either play on speakers, or save to a file, e.g. based on command line options I choose when running it? I think I'll eventually manage by playing with
thisProcess.argv
and anif
, but is there a simpler way?
I was playing with CSound previously, and it was so much simpler to get a similar "hello world" to work there.
Tested on SuperCollider 3.10, Ubuntu 20.04.