Event type: set

hi guys,
I’m working on a new topic today, making some experiments with the pattern set type and, as usual :stuck_out_tongue: , I came across something I cannot understand.

Follow my steps:

// FIRST EXAMPLE ////////////////////////////////////////////////////

// Let's start booting the server and creating a simple synth definition
s.boot;
(
SynthDef(\test, {
	|out=0, pan=0.0,freq=440, amp=0.4|
	var sig = SinOsc.ar(freq) * amp;
	Out.ar(out, Pan2.ar(sig, pan));
}).add;
)
// and instantiate the synth 
x = Synth(\test)
// as we know we can set parameters of the synth manually
x.set(\freq, 440.rrand(880) )

// I recently found out that I can do this also with a pattern,
// if I use the \set \type.
(
Pbindef(\test_ctrl, 
	\type, \set,
	\instrument, \test, // is this mandatory??
	\id, x,
	\amp, 0.6,
	\freq, Pwhite(440, 880, inf).trace
).quant_([4]).play;
)

// when we are happy, we can get rid of everything
(
Pbindef(\test_ctrl).stop.clear;
x.free;
)
// SECOND EXAMPLE ///////////////////////////////////////////////////

// Now let's try the same thingh with some modifications: now 
// I'm interested in making the pattern trigger a new percussive 
// envelope so, let's create a new synthdef.
(
SynthDef(\test_perc, {
	|t_gate=0, out=0, pan=0.0,freq=440, amp=0.4|
	var env = EnvGen.ar(Env.perc(0.0, 0.1), t_gate);
	var sig = SinOsc.ar(freq) * amp * env;
	Out.ar(out, Pan2.ar(sig, pan));
}).add;
)
// let's instantiate the synth 
x = Synth(\test_perc)
// and set the gate parameter to create a new envelope
x.set(\t_gate, 1)

// now, let's try the same thing as before: make the pattern do the job
// You will find that this won't work at all
(
Pbindef(\test_perc_ctrl, 
	\type, \set,
	\instrument, \test_perc,
	\id, x,
	\amp, 0.6,
	\t_gate, Pseq([1],inf).trace
).quant_([4]).play;
)

// when we are happy, we can get rid of everything
(
Pbindef(\test_perc_ctrl).stop.clear;
x.free;
)

Why the second example is not working the “same” way as the first?
What’s the difference between sending the t_gate parameter setting via the .set method and via pattern?
Thank you as always for your help

PS: maybe related to this?

According to Pattern Guide 08, when you use \type, \set, you need to specify which args to set with the \args key. This can be done one of 2 ways:

  1. specify the \instrument and set \args to an empty array.
  2. omit \instrument and provide an array of the \args you want to set.

I demonstrate the second approach here:

(
x = Synth(\test_perc);
Pbindef(\test_perc_ctrl, 
	\type, \set,
	\id, x,
    \args, #[\t_gate, \amp],
	\amp, 0.6,
	\t_gate, Pseq([1],inf).trace
).quant_([4]).play;
)

I recommend to avoid the first because default values in the event will overwrite your synth’s values:

In this example, the Pbind changes not only \pan but also \freq and \amp.

a = Synth(\default, [freq: 72.midicps, amp: 0.5]);

(
p = Pbind(
	\type, \set,
	\id, a,
	\instrument, \default,
	\pan, Pseq([-0.8, 0.8], inf),
	\dur, 0.25
).play;
)

In this example, it changes only \pan.

a = Synth(\default, [freq: 72.midicps, amp: 0.5]);

(
p = Pbind(
	\type, \set,
	\id, a,
	\args, [\pan],
	\pan, Pseq([-0.8, 0.8], inf),
	\dur, 0.25
).play;
)

hjh

1 Like