6

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 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.
  • 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 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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985

1 Answers1

1

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.

Les_h
  • 145
  • 9