0

I'm fiddling with SuperCollider + OSC and right now i don't seem to get the proper understanding of it.

This code should do:

  1. start a server
  2. define a synth
  3. start an instance of the synth
  4. mount a listener to alter the sin frequency through remote command
(
Server.default = Server.internal;
s = Server.default;
s.boot;

SynthDef(\fly, { arg freq = 500;
   Out.ar(0, SinOsc.ar(freq, 0, 0.1))
}).add;

~fly = Synth.new(\fly);

OSCdef.new(
    \move,
    {arg msg;
        [msg].postln;

        ~fly.set(\freq, msg[0]);
    },
    '/move',
    nil, 57120
);
)

Obviously it does not work as intented. The synth is not created by running the whole script. I need to run every block by itself. Also the call in OSCDef doesn't know about the ~fly synth: FAILURE IN SERVER /n_set Node 1000 not found.

Imperative
  • 3,138
  • 2
  • 25
  • 40

1 Answers1

0

JITLib makes use of the environment variables and adds a bunch of behavior. If you want to use a plain variable and manage the Synth yourself, use one of the single-character vars [a..z] instead of ~fly. Otherwise, you can let JITLib do its thing, in which case something like this will work:

(
Server.default = Server.internal;
s = Server.default;
s.boot;

~fly = { arg freq = 500;
   SinOsc.ar(freq, 0, 0.1)
};


OSCdef.new(
    \move,
    {arg msg;
        [msg].postln;

        ~fly.set(\freq, msg[0]);
    },
    '/move',
    nil, 57120
);
)

Reference: