SuperDirt icon indicating copy to clipboard operation
SuperDirt copied to clipboard

how to replace global effects?

Open ahihi opened this issue 10 months ago • 2 comments

i am trying to write a custom replacement for dirt_delay. for now the SynthDef is identical except for a high-pass filter on the input, plus two args to control it:

(
SynthDef("pulu_dirt_delay" ++ ~dirt.numChannels, { |dryBus, effectBus, gate = 1, delaytime, delayfeedback, delaySend = 1, delayAmp = 1, lock = 0, cps = 1, delayhpf=0, delayhpq=0|
	var signal;
	var input = In.ar(dryBus, ~dirt.numChannels);
	var maxDelayTime = 4;

	input = RHPF.ar(input, delayhpf.abs.clip(20, SampleRate.ir / 2), delayhpq.linexp(0, 1, 1, 0.001));
	input = input * delaySend.lag(LFNoise1.kr(1).range(0.01, 0.02)); // regulate input

	delayfeedback = delayfeedback.max(0);
	delaytime = delaytime * if(lock, reciprocal(cps), 1);
	delaytime = delaytime.clip(0, maxDelayTime); // just to be sure
	// from sc3-plugins
	signal = \SwitchDelay.asClass.ar(input, 1, 1, delaytime, delayfeedback, maxDelayTime);

	signal = signal * EnvGen.kr(Env.asr, gate, doneAction:2);
	signal = signal * delayAmp.lag(0.01);

	DirtPause.ar(signal, graceTime:4);

	Out.ar(effectBus, signal);

}, [\ir, \ir]).add;
)

based on hacks/adding-global-effects.scd, i have tried the following code to replace the default dirt_delay for each orbit:

(
~dirt.orbits.do { |o|
	var i;
	i = o.globalEffects.detectIndex { |fx| fx.name.asString.contains("dirt_delay") };
	o.globalEffects[i] = GlobalDirtEffect(\pulu_dirt_delay, [\delaytime, \delayfeedback, \delaySend, \delayAmp, \lock, \cps, \delayhpf, \delayhpq]);
	o.initNodeTree;
};
)

but after this, every event produces server errors:

FAILURE IN SERVER /n_run Node 1450 not found
FAILURE IN SERVER /n_set Node 1450 not found

(node number 1450 for orbit 1, 1456 for orbit 2, 1462 for orbit 3 etc)

and the delay no longer works. other global effects continue to work.

i think i am missing some cleanup code, but not sure what it is…

ahihi avatar Jan 05 '25 20:01 ahihi