Bus

[1]:
import sc3nb as scn
[2]:
sc = scn.startup()
Starting sclang process... Done.
Registering OSC /return callback in sclang... Done.
Loading default sc3nb SynthDefs... Done.
Booting SuperCollider Server... Done.

Using a Control Bus

[3]:
bus = scn.Bus('control')
bus
[3]:
Bus(rate='control', ids=[512])
[4]:
bus.get()
[4]:
0.0
[5]:
syn = scn.Synth("s2")

map the frequency of the synth to the bus value

[6]:
syn.map("freq", bus)
[6]:
<Synth(20001) 's2' s {}>
[7]:
bus.set(120) # changes synths frequency
[7]:
Bus(rate='control', ids=[512])
[8]:
bus.set(440)
[8]:
Bus(rate='control', ids=[512])

Set the frequency value to remove the mapping

[9]:
syn.set("freq", 220)
[9]:
<Synth(20001) 's2' ~ {'freq': 220}>
[10]:
bus.set(440)  # no change
[10]:
Bus(rate='control', ids=[512])
[11]:
syn.free()
[11]:
<Synth(20001) 's2' f {'freq': 220}>

Free the bus to mark the bus id as available again

[12]:
bus.free()

Use multiple Control Buses

[13]:
synth_name = scn.SynthDef("busMulti", """{ |out, freqs=#[200, 400], rates=#[1, 2] |
    Out.ar(out, Splay.ar(SinOsc.ar(freqs) * Decay2.ar(Impulse.ar(rates), 0.001, 0.1)) * 0.5);
}""").add()
[14]:
buses = scn.Bus("control", 2)
buses
[14]:
Bus(rate='control', ids=[512, 513])
[15]:
buses.get()
[15]:
[0.0, 0.0]
[16]:
syn = scn.Synth(synth_name)
[17]:
syn.map("rates", buses)
[17]:
<Synth(20002) 'busMulti' ~ {}>
[18]:
buses.set(1, 1)
[18]:
Bus(rate='control', ids=[512, 513])
[19]:
buses.set(1, 2)
[19]:
Bus(rate='control', ids=[512, 513])
[20]:
buses.get()
[20]:
[1.0, 2.0]
[21]:
syn.free()
[21]:
<Synth(20002) 'busMulti' f {}>
[22]:
buses.free()
[23]:
sc.server.free_all()
[24]:
sc.exit()
Quitting SCServer... Done.
Exiting sclang... Done.
[ ]: