Hey everyone!
I want to share this with you, and at the same time ask if you have better ideas.
Scenario: I have a Synth playing on a Bus, and I want to move it to another bus.
Problem: It clicks if I do it abruptly (e.g. synth.set(\out,newBus) )
So I did this:
SynthDef(\play){
|buf,loop=0,t_reset=0,rate=1,
pan=0,amp=0.2,gate=1,
out=0,outFade=1|
// just a mono buf being panned to stereo
var play = PlayBuf.ar(1,buf,BufRateScale.ir(buf)*rate,t_reset,loop:loop);
var env = EnvGen.kr(Env.asr(0.01,1.0,0.01),gate-Done.kr(play),doneAction:2);
var panned = Pan2.ar(Mix(play),pan)*env*amp.lag(0.5);
// here we act on out changes
var prev_out = LastValue.kr(out);
var outChanged = Changed.kr(out);
var fade_sweep = Sweep.ar(outChanged,1/outFade).clip(0,1);
var pan_out = Pan2.ar(panned,fade_sweep.linlin(0,1,-1,1)).flop;
var outsEq = BinaryOpUGen('==',prev_out,out);
OffsetOut.ar(prev_out,
Select.ar(outsEq,[pan_out.first,Silent.ar])
);
OffsetOut.ar(out,
Select.ar(outsEq,[pan_out.last,panned])
);
}.add;
See DX suite from miSCellaneous_lib which is designed for this task.
Here’s a simple example: A mono signal is crossfaded through out buses 0, 1, 3, 2 with constant switch time 1.
(
x = {
DXFanOut.ar(
Dseq([0, 1, 3, 2], inf), // demand rate sequence of output bus indices
LFTri.ar(150, 0, 0.05) * EnvGate(),
fadeTime: 1 // can be demand rate sequence of times
)
}.scope(4)
)
x.release
A number of options for crossfade curve, step and hold type type (‘fadeMode’), multichannel expansion etc. is available. There exist classes for fanning (spreading) and mixing and variants to deal with multichannel arrays or, alternatively, buses. Currently the time has to be given with constant numbers, ugens, or demand rate sequences, it’s on my todo list to add the option of triggered change.
(
x = { |out|
DXFanOut.ar(
out, // demand rate sequence of output bus indices
LFTri.ar(150, 0, 0.05) * EnvGate(),
fadeTime: 0.2 // can be demand rate sequence of times
)
}.scope(4)
)
x.set(\out, 1)
x.set(\out, 3)
x.set(\out, 0)
x.release