Modifying a control bus in serie

I’ve got this basic Synth of which I’m trying to control the Amplitude through a bus:

SynthDef(\basic, {
	var out=\out.kr(0);
	var amp=\amp.kr(0.5);
	var sig=SinOsc.ar(440);
	var env=EnvGate.new();
	sig=sig*env*amp;
	Poll.kr(Impulse.kr(5),amp,"Amp");
	Out.ar(out,sig!2);
}).add();

For controlling the bus, I’m using 2 Synth to build the right value:

(
// outputs a message from 0->1
SynthDef(\ampl, {
	var bus=\bus.kr(0); 
	var peak=\peak.kr(1); 
	// code not relevant here ...
	max.linlin(0,1,0,peak.clip(0,1));
	Out.kr(bus,max); 
}).add;
) 

(
// outputs a message from 0.8->0
SynthDef(\businverter, {
	var bus=\bus.kr(0);
	var max=\max.kr(0.8);
	var val=In.kr(bus);
	val=max-val.linlin(0,1,0,max);
	Out.kr(bus,val);
}).add;
)

Both are working correctly.

I start it like this:

~ctrl=~ctrl ?? {Bus.control(s,1)};
~a=Synth(\ampl,[\bus,~ctrl,\decay,2],target:~grpFx, addAction: \addToHead);
~b=Synth.after(~a,\businverter,[\bus,~ctrl]);

~bsc=Synth(\basic,[\amp,0],target:~grpFx, addAction: \addToTail);
~bsc.map(\amp,~ctrl);

As per definition of of the 2 bus controler synth, the value of the bus should be in [0,0.8].

The poll in the \basic Synth shows that its amp is in [0.8, ~1]

I don’t get why… Any idea ?

(
// outputs a message from 0.8->0
SynthDef(\businverter, {
	var bus=\[bus.kr](http://bus.kr)(0);
	var max=\[max.kr](http://max.kr)(0.8);
	var val=[In.kr](http://In.kr)(bus);
	val=max-val.linlin(0,1,0,max);
	[Out.kr](http://Out.kr)(bus,val);
}).add;
)

Both are working correctly.

sneaky problem. anything you write to busses will be automatically added to what’s already there.
so in the case of your businverter def you should rather overwrite what’s on the bus with…

ReplaceOut.kr(bus,val);

tip: s.scope(rate: \control); is good for debugging kr busses.

_f

#|
fredrikolofsson.com musicalfieldsforever.com

Tricky one. Thanks !!