Confusion in Pbind timing

hey I built an example out of a problem i cannot solve
I am trying to use a synth to play a portion of a signal that plays infinitely

dispatch synth is used to segment the never stopping signal (synth blo)
while the synth bli play a sequence over a defined amount of beats

t =;

//to pass the infinite signal
~bu =,2);

~grp =;

SynthDef(\dispatch2,{|in, out, dur|,,2)*[0,1,1,0],[0,dur,0,0]),doneAction:2))}).add;

SynthDef(\blo, {|out,dur|, 0.1)!2)}).add;

SynthDef(\bli, {|out,dur|,[0,0.1,0.1,0],[0,0.1,0,0]),doneAction: 2))!2)}).add;

Pbind(\instrument,\blo,\out, ~bu, \dur ,99999),

	Pseq([ Pbind(\instrument,\bli,\out, 0, \dur ,Pseq([1/1],12)),
		Pbind(\instrument,\dispatch2, \dur , Pseq([4/1 ],1) ,\in,~bu,\out,0, \group ,~grp)


dispatch makes blo signal overlaps over the following bli

I can hear the envelope of dispatch is not considering the bpm and keeps playing with the default tempo

please how do you make this work ?

thanks a lot !!

one solution is to divide dur argument from dispatch to get the actual value for 151 bpm


it works, would there be an easier way maybe to get the same result?


Yes, this is a bit of a gotcha… \dur for events is a measurement of BEATS, not seconds. It just so happens that when tempo == 1, one beat is one second, which makes it very easy to assume they are the same.

One other subtlety here too: \dur is the number of beats between events. \sustain is the duration in beats of a single event. Usually, you want to scale envelopes by \sustain and not \dur, because this reflects how long your event is actually supposed to play - doing it by \dur means your envelope will stop when the next event plays, even if you intended your Events to overlap. I’ll refer to \sustain and not \dur because it’s a little more correct…

You can solve this by calculating the sustain in seconds (\sustainTime) and passing that to your synth:

SynthDef(\dispatch2, { 
	|in, out, sustainTime|
		*[0,1,1,0],[0,1,0,0]), timeScale: sustainTime, doneAction:2)

	\instrument, \dispatch2, 
	\dur, Pseq([4/1], 1), 
	\sustainTime: { ~sustain.value / (~tempo ?? thisThread.tempo) },
	\in, ~bu,
	\out, 0, 
	\group, ~grp			

The tempo key in Event unfortunately behaves a little badly… it’s nil by default, and the Event playback stuff pulls the tempo from thisThread.tempo in the nil case, so you have to do the same for your key.


allright I suggest to keep putting dur as argument in the envelope and for the timescale 60/bpm, this solution works thanks a lot Scott