Feeding a Bus from another Bus

I am trying to feed a control bus reading from another control bus, so far unsuccessful. I have something like this:

~baseFreqBusPad.set(~baseFreqBusKnob.get({arg val; val}));

where both ~baseFreqBusPad and ~baseFreqBusKnob are Bus.controls.
I also tried the ~baseFreqBusKnob.value, this also doesn’t update the ~baseFreqBusPad bus. Is this approach I am trying principally correct? Then I should search for the ground elsewhere in my code!

Update
I also don’t understand why evaluating the ~baseFreqBusKnob.value results in a Bus(control, 3, 1, localhost) instead of the current value of the bus? Is value not meant to give the value back?

I think this should be:

~baseFreqBusKnob.get({arg val; ~baseFreqBusPad.set(val)});

so that the set in inside the get action function.
Best,
Paul

Here’s some test code:

s.boot;

//setup
(
~baseFreqBusPad = Bus.control(s, 1);
~baseFreqBusKnob = Bus.control(s, 1);
~baseFreqBusPad.set(0);
~baseFreqBusKnob.set(10);
)

(
//print vals
~baseFreqBusPad.get({arg val;("~baseFreqBusPad" + val).postln;});
~baseFreqBusKnob.get({arg val;("~baseFreqBusKnob" + val).postln;});
)

(
//copy from bus
~baseFreqBusKnob.get({arg val; ~baseFreqBusPad.set(val)});
)

(
//print vals
~baseFreqBusPad.get({arg val;("~baseFreqBusPad" + val).postln;});
~baseFreqBusKnob.get({arg val;("~baseFreqBusKnob" + val).postln;});
)

Best,
Paul

The problem with this is: I don’t want to set the value for ~baseFreqBusPad in the same moment ~baseFreqBusKnob perhaps changes (the knob is a midi-controller knob, and the pad is a midi-controller pad).
So the scenario is I want to change a parameter with the knob, but only to set it for my synth when I click on the pad.

btw, If this is the way to do it, this is really counter-intuitive! I mean why is it not possible to set from what you get, instead of to get and during getting also to set?!

It’s because get and set are asynchronous. To get and set immediately, you can use get/setSynchronous. Example code:

(
//setup
~baseFreqBusPad = Bus.control(s, 1);
~baseFreqBusKnob = Bus.control(s, 1);
~baseFreqBusPad.setSynchronous(0);
~baseFreqBusKnob.setSynchronous(10);
//print vals
("~baseFreqBusPad" + ~baseFreqBusPad.getSynchronous).postln;
("~baseFreqBusKnob" + ~baseFreqBusKnob.getSynchronous).postln;
//copy from bus
~baseFreqBusPad.setSynchronous(~baseFreqBusKnob.getSynchronous);
//print vals
("~baseFreqBusPad" + ~baseFreqBusPad.getSynchronous).postln;
("~baseFreqBusKnob" + ~baseFreqBusKnob.getSynchronous).postln;
)

There’s more detail in the Bus help file.

2 Likes

Thank you , the synchronous was the point :grinning: I learned something new

1 Like

Bus, Buffer, Group, Synth etc. are thin abstractions. They only make it more convenient to generate Server messages to manipulate them. They don’t do any other kind of bookkeeping or value tracking for you. When you .set a bus, it only sends a message to the server to change the bus value. After that, the bus object itself forgets the value, and the only way to get the value back is to ask the server and wait for a reply.

Value tracking would have to be implemented in a higher level abstraction on top of Bus. For example, GenericGlobalControl in my ddwCommon quark works like this:

s.boot;

~baseFreqBusKnob = GenericGlobalControl(\freqknob, nil, 2000, \freq);

~baseFreqBusKnob.value;
-> 2000

// GGC acts like a bus
a = Synth(\default, [freq: ~baseFreqBusKnob.asMap]);

~baseFreqBusKnob.set(400);

// but it remembers its value, which Bus does not
~baseFreqBusKnob.value;
-> 400

a.release;

… with other features to play an automation synth onto the bus, and automatically update the language side value a few times a second.

Hm, do you need a control bus at all for the knob, then? Wouldn’t it be simpler for your MIDI responder for the knob to save the value on the language side and transmit it to the server only when the button trigger is received?

The timing resolution of getSynchronous, btw, is limited to the audio hardware buffer size. That’s OK for your use case because aBus.set without a timestamp is also quantized to the audio hardware buffer size :grin: – just pointing it out because “synchronous” makes it sound like the timing is better than it really is.

hjh

1 Like