How to play a SuperCollider file non-interactively from the terminal command line interface (CLI) either on speakers or saving to an output file?

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:

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

Answers (1)

Les_h
Les_h

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

Related Questions