Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to replace global effects? #308

Open
ahihi opened this issue Jan 5, 2025 · 1 comment
Open

how to replace global effects? #308

ahihi opened this issue Jan 5, 2025 · 1 comment

Comments

@ahihi
Copy link
Contributor

ahihi commented Jan 5, 2025

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
Copy link
Contributor Author

ahihi commented Jan 5, 2025

ah i think i figured it out. setting globalEffects[i] directly skips this bit which sets the GlobalDirtEffect's numChannels.

this seems to work: (and frees the old effect synth)

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

does this look reasonable? i could do a PR to add an example like this to adding-global-effects.scd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant