Addapting Tempo.Clock Tempo in SynthDef

Hello everyone, this one is probably an easy question.
I was playing with Tempo.Clock and patterns and wish to also let the SynthDefs which are played be tracked by this TempoClock. I show you an example with a kick and a wobble bass:

//SynthDefs:
(
//simple kick
SynthDef(\kk,{Out.ar(0,0.5*Line.kr(1,0,0.05,doneAction:2)*SinOsc.ar(Line.kr(110,44,0.05)!2))}).add;
//wobble bass
SynthDef(\wb,{
	arg dur=1;
	var lfo, sig;
	//here is the lfo which frequency should be changed according
	//the TempoClock
	lfo = SinOsc.ar(dur);
	sig = 0.1*(3*(lfo**2)*SinOsc.ar(110!2)).tanh; //sinus bass
	sig = sig*sqrt(Line.kr(1,0,dur,doneAction:2)); //simple envelope
	Out.ar(0,sig)
}).add;
)
//Demonstration
TempoClock.tempo = 1; // with this TempoClock, the Wobble is in time
(
~k = Pbind(\instrument,\kk,\dur,Pseq([1],inf)).play;
~b = Pbind(\instrument,\wb,\dur,Pseq([1],inf)).play;
);
TempoClock.tempo = 0.5; //now the wobble doesnt fill the space
//basically synth def needs to track TempoClock.tempo

In this Example, im wishing the LFO of the wobble bass to also speed up or slow down, depending on the changes of a tempo clock. I could add a variable in the SynthDef to make it track the TempoClock variable, but I’m not sure how to do this either.
Any help appreciated. Thanks

[EDIT]: changed the code formatting style

I’d suggest to use a control bus to hold the tempo.

t = Bus.control(s, 1).set(TempoClock.tempo);

// sync using dependent notifications
c = SimpleController(TempoClock.default)
.put(\tempo, { |object, whatChanged, tempo|
    c.set(tempo)
});

Now synths can use In.kr to get the tempo value.

The LFO rate should be fine.

Envelopes and Lines won’t adjust their duration in the middle of a segment, though. I could work something out for that later but not just at the moment.

hjh

1 Like

Hello, thanks for answering!!
Learned something new for sure.
Mostly it works, I can divide the length of the envelopes by the same control bus for the tempo. Then it also stretches accordingly. I guess this is no problem.

I am wondering about this code snipplet:

Is it supposed to make any changes to the TempoClock.tempo, to a change to Bus, which is saved as variable: ‘t’? Because this does not seem to work.

Atm, when i change the tempo, i also have to write a second line, to make it work:

(
TempoClock.tempo = 2;
t.set(TempoClock.tempo);
)

Thanks for answering the question!

It’s a typo – sorry. Indeed it should have been t.set.

I often use c for a control bus and forgot that I wrote it differently this time.

Good catch – after you fix that, you shouldn’t have to set the bus separately.

hjh

Ok cool, I still had to make some minor changes, since the tempo argument doesn’t seem to give any results. But its now a working version! Thank you very much!
In case anybody else would be interested, here is the result:

//tempoclock configurations
(
t = Bus.control(s, 1).set(TempoClock.tempo);
c = SimpleController(TempoClock.default).put(\tempo,{t.set(TempoClock.tempo);});
)
//SynthDefs:
(
//simple kick
SynthDef(\kk,{Out.ar(0,0.5*Line.kr(1,0,0.05,doneAction:2)*SinOsc.ar(Line.kr(110,44,0.05)!2))}).add;
//wobble bass
SynthDef(\wb,{
	arg dur=1;
	var tempo, lfo, sig;
	//here is the lfo which frequency should be changed according
	//the TempoClock
	tempo = In.kr(t.index);
	lfo = SinOsc.ar(dur*tempo);
	sig = 0.1*(3*(lfo**2)*SinOsc.ar(110!2)).tanh; //sinus bass
	sig = sig*sqrt(Line.kr(1,0,dur/tempo,doneAction:2)); //simple envelope
	Out.ar(0,sig)
}).add;
)
//Demonstration
(
~k = Pbind(\instrument,\kk,\dur,Pseq([1],inf)).play;
~b = Pbind(\instrument,\wb,\dur,Pseq([1],inf)).play;
);
TempoClock.tempo = 0.5; //synch wobble with tempoclock
TempoClock.tempo = 1; //synch wobble with tempoclock
TempoClock.tempo = 4; //synch wobble with tempoclock
1 Like

Right again! I’m slipping… I’d better slow down next time.

That last version looks great.

hjh

1 Like