0

I’m new to SC and the whole music programming thing in general. I’ve done a python app, that reads a text and sends word by word to SC through OSC. The text is only the words ‘miau’ and ‘guau’ repeated for fun and to try it out.

Another thing kind of weird happening, is that on the SC console I get three times the same word than on the text and on terminal (that python prints each word). So for each ‘miau’ on the txt/terminal, I get ‘miau miau miau’ on the SC console.

The OSC communication is working, but I hear no sound. I’ve played my buffers separately, and they are working. When I play the buffers or the SynthDef I can hear the samples being played, so I assume the issue is on the switch.

s.boot;

~b0 = Buffer.read(s, "/path/to/bd/BT0A0A7.wav")
~b1 =Buffer.read(s, "/path/to/hh/000_hh3closedhh.wav")

~b0.play; 

(
SynthDef.new(\playbuf, {|amp=1, out=0, buf, da=2, rate =1|
var sig;
sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, doneAction:da);
sig = sig*amp;
Out.ar(out, sig);
}).add;
)

Synth.new(\playbuf, [\buf, ~b1.bufnum]);

(
OSCdef.new("texto",{
    |msg, time, addr, port|
    msg[1].postln;
    switch(msg[1],
        "miau", {Synth.new(\playbuf, [\buf, ~b1.bufnum])},
        "guau", {Synth.new(\playbuf, [\buf, ~b0.bufnum])}
        );

},
'/supercollider',
)
)

Although it copies the text, so I know the OSC is working, the samples won't play. Any tip appreciated!

sophiet
  • 13
  • 7

1 Answers1

0

Just use single quotes instead of double quotes in the switch. Like this:

(
OSCdef(\texto,{ |msg|
    switch ( msg[1],
        'miau', { Synth.new(\playbuf, [\buf, ~b1.bufnum] ) },
        'guau', { Synth.new(\playbuf, [\buf, ~b0.bufnum] ) }
    )
}, '/supercollider' )
)

saudações,

Gil

Edited to add:

Text surrounded by double quotes are strings. Text surrounded by single quotes are symbols. These are different classes. OSC messages use symbols instead of strings, which is why using double quotes won't work.

Symbols look like any of the following:

'symbol'
\symbol
"symbol".asSymbol
'symbol'.asSymbol

Those last two can help if for some reason you have text, but you aren't sure what it is.

Les_h
  • 145
  • 9
skmecs
  • 36
  • 5