Sending a synth with python

Hello,
I’m trying to send a Synthdef with Python. but it doesn’t seem to work. I get no Output.

(
SynthDef(\write_sinus_example, {
	var sig = SinOsc.ar(\freq.kr(440))!2;
	sig = SinOsc.ar(1) * sig * \amp.kr(0.3);
	Out.ar(\out.kr(0), sig);
}).store;
)

So I’ve been storing a SynthDef. I also tried it with “.writeDefFile”.

and now i have a write_sinus_example.scsynthdef in my synthdefs folder.

Now I’m running a scsynth in a terminal:
scsynth -u 57110

and i have this python script:

from pythonosc.udp_client import SimpleUDPClient
import time

c = SimpleUDPClient("127.0.0.1", 57110)

c.send_message(
    "/d_load",
    "/home/MYUSERNAME/.local/share/SuperCollider/synthdefs/write_sinus_example.scsyndef"
)

time.sleep(0.2)

c.send_message("/s_new", ["write_sinus_example", 1000, 0, 0])                                                             

I replaced MYUSERNAME.
If i run the script twice, the scsynth tells me the node is already in. But i hear no Sound or get any other messages.

Can someone help me understand why I don’t hear aynthing?
I use Linux and jackd.
Thank!

Can someone help me understand why I don’t hear aynthing?
I use Linux and jackd.
Can you check with qjackctl or some other tool that the scsynth from
your shell connects to the jack outputs?

You could also check whether the scsynth on the command line produces sound by
sending synthdefs to it from an instance of scide that uses that server,
instead of from python3 first, something (untested) like:

r = Server.remote(\remote1, NetAddr("127.0.0.1", 57110), Server.default.options.copy, clientID: 0);
r.ping;
r.clientID; // query my client id
r.makeWindow; // will read "inactive", also allowing me to change default server to \remote1
r.maxNumClients;
{SinOsc.ar * 0.1}.play(r);
r.freeAll; // This can not be stopped with Ctl-.

best, P

1 Like

Here’s a scsynth startup transcript that will make sound:

Found 345 LADSPA plugins
VSTPlugin 0.6.2
JackDriver: client name is 'SuperCollider'
SC_AudioDriver: sample rate = 44100.000000, driver's block size = 256
JackDriver: connected  xxx:capture_FL to SuperCollider:in_1
JackDriver: connected  xxx:capture_FR to SuperCollider:in_2
JackDriver: connected  SuperCollider:out_1 to xxx:playback_FL
JackDriver: connected  SuperCollider:out_2 to xxx:playback_FR
SuperCollider 3 server ready.

I’m willing to guess that your scsynth -u 57110 output looks like this:

Found 345 LADSPA plugins
VSTPlugin 0.6.2
JackDriver: client name is 'SuperCollider'
SC_AudioDriver: sample rate = 44100.000000, driver's block size = 256
SuperCollider 3 server ready.

Those “connected” lines are important.

See the Linux readme “Environment variables” section for an explanation of auto-connection environment variables.

Or, you can manually connect using jack_connect at the command line, or RaySession (extra install but :+1: :+1: :+1: ) or qpwgraph (maybe already installed but less usable IMO).

EDIT: Also, when running a server at the command line idea, it’s a good idea to grab your options string in sclang:

s.options.asOptionsString
->  -u 57110 -a 1024 -i 2 -o 2 -m 524288 -R 0 -C 1 -l 1

… and paste into the command.

hjh

1 Like

Oh wow, I simply forgot to connect the scsynth to an output. I completely forgot that this was done in the IDE automatically.
Thank you very much! I get some sound now!

When the language boots the server, it autoconnects because the LinuxPlatform class sets the system environment variables for it during language startup. If you want another shell to autoconnect, then you’d need to set the variables before running scsynth (or, write a shell script that sets them and then runs scsynth).

hjh

1 Like