My apologies if someone all ready responded, it seems sometimes I'm not always seeing responses to questions. You can use SendReply and an OSCresponder to do this:
(
SynthDef.new(\SoundA,{
|gate=1|
var sine,env;
env = EnvGen.ar(Env.asr(0.1,1,0.25,-4),gate:gate,doneAction:2);
sine = SinOsc.ar(440,0,0.3);
Out.ar(0,[sine,sine]*env);
}).store;
SynthDef.new(\SoundB,{
var sine,env,gateEnv,length;
length = Rand(0.25,3.0);
gateEnv = EnvGen.kr(Env.new([0,0,1],[0.1+length,0]));
env = EnvGen.kr(Env.asr(0.1,1,0.25,-4),gate:(1-gateEnv).abs,doneAction:2);
sine = SinOsc.ar(200,0,0.3);
SendReply.kr(gateEnv,'soundBTrig',[env]);
Out.ar(0,[sine,sine]*env);
}).store;
o = OSCresponderNode(nil,'soundBTrig', { |t,r,msg| msg.postln; ~synthA.set(\gate,0); }).add;
)
(
t = Task({
loop {
~synthA = Synth(\SoundA );
2.0.wait;
Synth(\SoundB );
4.0.wait;
}
})
)
t.play
t.stop
o.remove;
You could also set up NodeWatcher to do something similar. Best,