Pbind duration rest , notes don't play because they fall on rest

I am having issues wit the Pbind test for note gate
When a rest is inserted , the note
In the following code , note nr50 and note nr57 are not played because they fall on a rest .
What to do to have the rests fall in between the notes , which is what rest are about heh ?


(
SynthDef (\simple,
{
arg att=0.001,dec=0.200,mod=500,pitch=0,filterfreq=400;
var sig,env;

		env=EnvGen.ar(Env([0,1,0],[att,dec],[0,-5]),doneAction:2);
		sig=Pulse.ar(pitch.midicps,mul:0.5)+Saw.ar((pitch+0.1).midicps,mul:0.5);///////I an
		sig=RLPF.ar(sig,filterfreq+(env*mod).clip(40,20000),rq:0.5);
		sig=sig*env!2;
		Out.ar(0,sig)
}).add
)




(
Pdef(\qwe,
	Pbind(\instrument,\simple,
		\dur,Pseq([0.5,0.5,Rest(1),0.5,0.5,Rest(1),0.5,0.5,Rest(1)],inf),
		\pitch,Pseq([48,47,50,33,72,57],inf),
		\filterfreq,Prand([100,400,100,400],inf),
		\dec,Prand([0.4,0.400,0.250,0.6],inf),
		\att,Prand([0.001,0.001,0.001,0.001],inf);

	).play
)
);
/////

Pbind always evaluates every sub-stream in every event. A Rest object does not block the other sub-streams. (Think about how complicated that logic would be. What if it’s already evaluated almost all of the sub-streams, and then the last one is a Rest? You happen to have written \dur, with Rests, first, but another user might not. So SC goes with the simpler rule – get a value from every sub-stream, every time.)

There are two ways to get rests:

  1. Insert dummy values into the other patterns.

  2. Write short notes instead of rests. That is, a “rest” is just the absence of a note being triggered. You could do that by having a longer duration and a shorter sustain time. (This is how DAWs do it.)

// Option 1
// btw do consider spaces after commas, let the code breathe
// also fixing an incorrectly placed .play

(
Pdef(\qwe,
	Pbind(\instrument, \simple,
		\dur, Pseq([0.5, 0.5, Rest(1), 0.5, 0.5, Rest(1), 0.5, 0.5, Rest(1)], inf),
		\pitch, Pseq([48, 47, 0, 50, 33, 0, 72, 57, 0], inf),
		\filterfreq, Prand([100, 400, 0, 100, 400, 0], inf),
		\dec, Prand([0.4, 0.400, 0, 0.250, 0.6, 0], inf),
		// all att values are the same, so...
		\att, 0.001
	)
).play
);


// Option 2
(
Pdef(\qwe,
	Pbind(\instrument, \simple,
		\dur, Pseq([0.5, 1.5, 0.5, 1.5, 0.5, 1.5], inf),
		\legato, Pseq([0.8, 0.24], inf),
		\pitch, Pseq([48, 47, 50, 33, 72, 57], inf),
		\filterfreq, Prand([100, 400, 100, 400], inf),
		\dec, Prand([0.4, 0.400, 0.250, 0.6], inf),
		// all att values are the same, so...
		\att, 0.001
	)
).play
);

hjh

1 Like

Dummy of zero seems like a good idea when pitch values are in hertz , when pitches are midi nr’s we need a negative since 0 is around 8 hz
Thanks for the tip


3

If the dummy frequency is 8 Hz, and the event contains a Rest object, then it doesn’t matter because a rest event doesn’t play anything.

(
p = Pbind(
	\midinote, 0,
	\dur, Rest(1)  // always rest
).play;
)

… and the server still reads “0s” – no synths. No synths = no sound = no 8 Hz hitting your speakers. So don’t worry about it.

You need some value as a placeholder to keep the sub-patterns in sync. But, just because the placeholder value exists, does not mean that the server will act on it. (If you’re putting a dummy value in for a non-rest event, then that would be a coding mistake.)

hjh

Another way is to use Pgate. This is a bit more advanced, but it will save you the trouble of entering dummy values, which can be very time-consuming if you are working with a large set of data.

(
Pdef(\qwe,
    Pbind(
        \instrument,\simple,
        \dur,Pseq([0.5,0.5,Rest(1),0.5,0.5,Rest(1),0.5,0.5,Rest(1)],inf),
        \notRest, Pfunc {|ev| ev.dur.isRest.not},
        \pitch, Pgate(Pseq([48,47,50,33,72,57],inf), inf, \notRest),
        \filterfreq,Prand([100,400,100,400],inf),
        \dec,Prand([0.4,0.400,0.250,0.6],inf),
        \att,Prand([0.001,0.001,0.001,0.001],inf);        
    )
).play;
);

EDIT: I forgot about Pclutch, which is one step simpler than Pgate:

(
Pdef(\qwe,
    Pbind(
        \instrument,\simple,
        \dur,Pseq([0.5,0.5,Rest(1),0.5,0.5,Rest(1),0.5,0.5,Rest(1)],inf),
        \pitch, Pclutch(Pseq([48,47,50,33,72,57],inf), Pfunc {|ev| ev.dur.isRest.not}),
        \filterfreq,Prand([100,400,100,400],inf),
        \dec,Prand([0.4,0.400,0.250,0.6],inf),
        \att,Prand([0.001,0.001,0.001,0.001],inf);        
    )
).play;
)