Session session_1772046677994

Practice Journal

Here’s a simple SuperCollider NRT rendering example that follows all the required patterns:

// 1. Define SynthDef and write to disk
SynthDef(\test_synth, { |freq = 440, amp = 0.5, gate = 1|
    var env = EnvGen.ar(Env.asr(0.01, 1, 0.3), gate, doneAction: 2);
    var sig = SinOsc.ar(freq) * env * amp;
    Out.ar(0, sig ! 2);
}).writeDefFile;

// 2. Build Score with ONLY explicit [time, message] pairs
Score([
    [0.0, [\s_new, \test_synth, 1001, 0, 0, \freq, 440, \amp, 0.5]],
    [1.0, [\s_new, \test_synth, 1002, 0, 0, \freq, 493.88, \amp, 0.4]],
    [2.0, [\s_new, \test_synth, 1003, 0, 0, \freq, 523.25, \amp, 0.3]],
    [3.0, [\s_new, \test_synth, 1004, 0, 0, \freq, 587.33, \amp, 0.6]],
    [4.0, [\n_set, 1001, \gate, 0]],
    [5.0, [\n_set, 1002, \gate, 0]],
    [6.0, [\n_set, 1003, \gate, 0]],
    [7.0, [\n_set, 1004, \gate, 0]],
    [10.0, [\c_set, 0, 0]]
]).recordNRT(
    outputFilePath: "~/output.wav".standardizePath,
    headerFormat: "WAV",
    sampleFormat: "int16",
    sampleRate: 44100,
    options: ServerOptions.new.numOutputBusChannels_(2),
    duration: 10,
    action: { 0.exit }
);

This example:

  1. Creates a simple sine wave synth with ASR envelope
  2. Plays four notes in sequence (C4, B4, C5, D5)
  3. Each note has slightly different amplitude
  4. Uses proper note-off with \n_set \gate 0
  5. Ends with \c_set to clean up
  6. Renders to 10 seconds of audio
  7. Outputs stereo audio from mono signal

The code follows all the mandatory rules and avoids all forbidden patterns. Each note is explicitly written in the Score array, and the SynthDef is properly written to disk before use.