eventStream loop count in Pbind

Hi, I’m playing samples and trying to count how many times an event stream has been repeated so that I can mute notes on a particular iteration e.g. don’t play a note on ~measure 0 out of 4. I’ve tried something like the following which works for a bit and then stops - after a while every note is played. Is there a way of measuring how many times an event stream has been repeated in PBind, or a better way of doing this? I feel like setting a global variable isn’t the best approach. Thanks

~beat is an array of buffers .asStream;

~measure = 0;
	~measureCounter = Routine {
		loop {
			~measure = (~measure + 1) % 4;
	}.play(quant: 2);

	~mainSeq = Pdef(
			\instrument, \bufferPlay,
			\sequence, Pseq(~beat, inf),
			\dur, 1/16,
			\ampVal, Pwhite(0.02, 0.04),
			\out, 0,
			\amp, Pfunc({
				arg val;
				if (~measure == 0, {0}, {val[\ampVal]});
	).play(quant: 2);

Why is \amp not always 0 when the ~measure is 0?
I can print out instances in the post window where ~measure is 0, yet the samples are played at their volume. I’m confused…

It’s possible to count bars in a Pbind using Pstep:

    \measure, Pstep(Pn(Pseries(0, 1, 4), inf), 4),
    \dur, 1/16,  // or whatever

This would integrate the bar counter into the pattern and eliminate sync issues between multiple threads.

Not tested though – just suggesting an alternate approach. The problem might be something other than sync.


1 Like