Im using a function ~transC
by @elgiano to make transitions from one value to another inside a Pspawner
. (But its also kind of a general question when using Ppar
and want to change individual keys of the Patterns inside the Ppar
).
its working fine for single keys. but ive tried to use the ~transC
function with a Ppar
chained to a \dur
Pattern inside a Pspawner
and make independent transitions for the \freq
of \a
and \b
and its not working. any ideas? In this simplified example I would like to have \a
going from 300 to 400 hz and \b
going from 400 to 500 hz independently. thanks so much
(
/* transC:
continuous transition, pars are set using a custom synth that writes to busses
- trans is defined as a dictionary of envelopes
e.g (amp: Env([0.1,0.5],1), ...)
- all envelopes are stretched to last transDur
- event-specific parameters like \legato are converted to Penvs and not written to busses
// \a for 3 seconds, then trans for 5 second
~transC.(\a,3,(
amp: Env([0.1,0.5],1)
),5)
*/
~transC = {|patA, durA, transDef, transDur|
Pspawner{|sp|
var trans = PatternProxy();
trans.source = Pbind();
sp.par(trans<>Pdef(patA));
durA.wait;
trans.source = Pbind(*~mapTrans.(transDef,transDur).asKeyValuePairs);
transDur.wait;
sp.suspendAll();
}
};
// used by transC
~mapTrans = {|parEnvs, transDur= 1|
var penvs = parEnvs.select{|v|v.class===Penv}.collect{|penv|
penv.times = penv.times*transDur
};
var busses = parEnvs
.select{|v,k| penvs.keys.includes(k).not}.collect{Bus.control(s,1)};
{
busses.collect{|bus, parName|
Out.kr(bus, EnvGen.kr(parEnvs[parName],timeScale:transDur));
};
Line.kr(0,1,transDur,doneAction:2);
Silent.ar;
}.play.onFree{
busses do: _.free
};
busses.collect(_.asMap) ++ penvs
};
)
working:
(
// transC example
Pdef(\a, Pbind(\note, Pseq((0..10)), \amp, 0.1, \pan, -1));
Pdef(\b, Pbind(\note, Pseq((0..10)), \amp, 0.5, \pan, 1));
)
// \a for 3 seconds, then trans for 5 second, then \b for 3 seconds
(
Pspawner{|sp|
sp.seq(~transC.(\a, 3, (
amp: Env([0.1, 0.5], 1),
pan: Env([-1, 1])
), 5));
sp.seq(Pfindur(3, Pdef(\b)))
}.play
)
not working:
(
Pdefn(\durs, Pbind(\dur, 0.5));
Pdefn(\notes, Pbind(\freq, [300, 400]));
Pdef(\a, Pbind(\freq, Pkey(\freq).collect(_[0]), \amp, 0.1, \pan, -1, \out, 0));
Pdef(\b, Pbind(\freq, Pkey(\freq).collect(_[1]), \amp, 0.1, \pan, 1, \out, 2));
Pdef(\poly,
Ppar([Pdef(\a), Pdef(\b)]) <> Pdefn(\durs) <> Pdefn(\notes);
)
)
// \poly for 3 seconds, then trans for 5 seconds
(
Pspawner{|sp|
sp.seq(~transC.(\poly, 3, (
freq: Env([[300,400], [400,500]], 1),
//freq: Pfunc { Env([[300,400], [400,500]], 1).asArray },
//freq: [ Env([300, 400], 1), Env([400, 500], 1) ]
), 5));
}.play
)