Multichannel expansion in patterns sending [Env.perc].asArray

Hi everyone,
how could I send the env-array to do a multichannel expansion correctly?

SynthDef(\DcOuts){|durSeconds=1, amp=1, bus=0|
    var env = \env.kr(Env.newClear(8).asArray);
    var sig = EnvGen.kr(env, timeScale:durSeconds.poll, doneAction:2) * amp;
    Out.kr(bus, sig);
}.add;

(
Pbindef(\ph5,
    \instrument, \DcOuts,
    \bus,Pseq((0..5),inf),
    \env, Pseq([ [Env.perc]],inf),
    \dur, Pseq([1/4],inf),
).play;
)

(
Pbindef(\ph5, \env,Pseq([ [[ [Env.perc], [Env.perc(0.999,0.001,1,4)] ]] ], inf)).play;
)

Really thanks in advance

You need the “template” of the envelope you want to pass in the SynthDef.
Here your example with audio out

SynthDef(\DcOuts, {|durSeconds=1, amp=1, bus=0|
	var env = \env.kr(Env.perc.asArray);
	var sig = EnvGen.kr(env, doneAction:2).poll * amp * SinOsc.ar(400);
    Out.ar(bus, sig);
}).add;

(
Pbindef(\ph5,
    \instrument, \DcOuts,
	\env, Pseq([ [Env.perc(0.02, 1)], [Env.perc(0.5, 0.02)] ],inf),
    \dur, Pseq([0.5],inf),
).trace.play;
)

It’s also possible to pass envelopes of different lengths via patterns, then you need a maximum template. miSCellaneous_lib quark’s tutorial “Event patterns and array args” contains examples for this.

1 Like

hi @dkmayer

I’m trying to convert this to ‘classic’ arg mode and it seems this does not work and I don’t understand why:

(
SynthDef(\DcOuts1, {
	arg durSeconds=1, amp=1, bus=0, env = Env.perc.asArray;
	//var env = \env.kr(Env.perc.asArray);
	
	var sig = EnvGen.kr(env, doneAction:2) * amp * PinkNoise.ar;
    Out.ar(bus, sig);
}).add;
)
(
Pbindef(\ph5,
    \instrument, \DcOuts1,
	\env, Prand([ [Env.perc(0.02, 0.5)], [Env.perc(0.2, 0.02)] ],inf),
    \dur, Prand((1..10)*0.05,inf),
);
)

Pbindef(\ph5).play

I’m probably missing something about named controls. how can I avoid using them in your example above?

The default values in a SynthDef arg block must be literal numbers or arrays – 1 and 0 are literals, while Env.perc.asArray is an expression.

The only way to create a synth input where the default is an expression is with NamedControl. It isn’t supported to convert this into a regular arg.

hjh

1 Like