Reputation: 382672
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:
rs.scd
finishes playing? I could do 1.wait; 0.exit;
but that forces me to hardcode the 1
, which is the length in seconds of the 4 0.25s notes being played. That 1
is also hardcoded in nrs.csd
, and it would be great to be able to factor it out there as well.thisProcess.argv
and an if
, 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.
Upvotes: 6
Views: 1409
Reputation: 143
For your first question:
In x.recordNRT
you can add an action. This function will execute after the score finishes.
...
x.recordNRT(
...
duration: x.endTime,
action: {0.exit}
);
For your second question:
This is an unusual use case. I don't know a better method than argv and an if statement. (See also https://doc.sccode.org/Classes/Main.html#-argv )
Things that you can put before the if include:
Constructing your pattern and creating your synthdefs.
Things that need to go after the If include sending the SynthDefs to the server, as the NRT server is not the same as the local server. See the helpfile you linked for some warnings about that.
Upvotes: 1