# Question about Demand UGens

Hey there !

After listening to the wonderful Metrics album by Jonatan Liljedahl I decided to give Demand UGens a deeper look.

And I’m a bit confused. Could you help ?

``````(
{
var trig, snd, tempo, clock;
tempo = 1.0;
clock = Impulse.kr(tempo);
trig = Demand.kr(clock, 0, Dseq([tempo, tempo],repeats: inf));
snd = Impulse.ar(trig);
snd.lag;
}.plot(5)
)
``````

gives what I expected

``````(
{
var trig, snd, tempo, clock;
tempo = 1.0;
clock = Impulse.kr(tempo);
trig = Demand.kr(clock, 0, Dseq([tempo * 2, tempo],repeats: inf));
snd = Impulse.ar(trig);
snd.lag;
}.plot(5)
)
``````

gives me also what I expected

But

``````(
{
var trig, snd, tempo, clock;
tempo = 1.0;
clock = Impulse.kr(tempo);
trig = Demand.kr(clock, 0, Dseq([tempo / 2, tempo],repeats: inf));
snd = Impulse.ar(trig);
snd.lag;
}.plot(5)
)
``````

gives me

and I’m really puzzled, because I would have thought I would get a trigger at 0, then at 2s, then at 3s, then at 5s.

Any clue ?

Thanks in advance !

It puzzles, but makes senso also imo. What you are showing here is a quite complicated – I would say non-standard – usage of demand rate ugens: iterated triggering. The frequeny of the second Impulse is changed during a cycle and this is causing the effect:
The first trigger of the resulting signal happens at t = 0. At t = 1 50 % of the first period is over (as tempo = 0.5), now the remaining 50 % are fullfilled with the doubled tempo, so the first cycle has to end at t = 1.5. At t = 2 50 % of the second cycle is over, but again the tempo changes to 0.5. So the rest of the second cycle needs one second. At t = 3 tempo change (to 1) and second Impulse meet again (the first time after t = 0), so this cycle has length 1, and then the process loops.

I’ve never deeply dived into this special kind of drate application, but I suppose you can produce maximally opaque effects. This could be fun, but as demand rate ugens can be extremely tricky already with straight intentions (and contain some buggy stuff also) I’d start with more easy examples first. E.g. if you want to produce sequences of different durations have a look at Duty, TDuty etc.

Thanks a lot Daniel.
Now it makes a lot of sense.
I had totally overlooked that changing the rate of the Impulse generator while it was in action would impact the Impulse calculation.
And I did not know about Duty or TDuty, and they seem to be what I need.
Thanks again for your detailed explanation, love the SC community.
All the best
Geoffroy