Sending different SendReply in SynthDef

Hello,

I am trying to activate different SendReply uGens in a single SynthDef, using a Select uGen to switch them according to which ‘out’ argument the synth is given.

What seems to be happening is that both are sending at once. Is there any way to get the behaviour I’m after? Essentially, it needs to send the amp envelope to a separate OSC receiver according to which output is selected.

Unfortunately I can’t send as a bundle, because then overlapping synths affect the whole OSC stream - I am sending the OSC on to Processing after receiving it using OSCDefs in SC.

My SynthDef:

	//define perc synth
	SynthDef(\perc, { arg out, gate = 0, freq = 100, atk = 0.00001, rel = 0.75, pAtk = 0.0001, pRel = 0.3, pEnvScale = 2.5, dTime = 0, amp = 0.8, noiseLevel = 0.5;
		var aEnv, pEnv, oscil, oscil2, noise;

		noise = LPF.ar(WhiteNoise.ar(0.75) * Line.ar(1,0,0.003), 4000);
		aEnv = EnvGen.kr(Env.perc(atk, rel), doneAction: 2);
		pEnv = EnvGen.kr(Env.perc(pAtk, pRel)) * pEnvScale;

		oscil = SinOsc.ar(freq * pEnv, 0, amp) * aEnv;
		oscil2 = SinOsc.ar(freq + 10 , 0, amp * 0.65) * aEnv;
		Out.ar(out, BPeakEQ.ar(oscil + oscil2, freq: 1000.0, rq: 6, db: -10.0) + (noise * noiseLevel));
		Select.ar(out, [SendReply.ar(Impulse.ar(50), '/percEnvL', [aEnv]), SendReply.ar(Impulse.ar(50), '/percEnvR', [aEnv])]);
	}).add;

Select evaluates everything and outputs only one, by design.

You’ll need to multiply the triggers by their own on/off switches.

var trig = Impulse.ar(50);

...

SendReply.ar(trig * (out <= 0), '/percEnvL', [aEnv]);
SendReply.ar(trig * (out >= 1), '/percEnvR', [aEnv]);

EDIT: Another way – if you have control over the message format, you could put the output bus into the message as a parameter. It’s not strictly necessary to encode as part of the OSC command.

SendReply.ar(Impulse.ar(50), '/percEnv', [out, aEnv]);

Then the receiver in Processing would disambiguate based on the parameter.

hjh

Thank you James - that makes sense, with Select both are evaluated, just not output.

This technique works - I didn’t think to use comparison operators but it’s clear and simple. Perfect!