I would like to have a synth (see below) running in the background while live coding. I would like to be able to fade it in and out (so I think that means I want a NodeProxy pointing to it). The synth in question is just some filtered noise crudely mimicking the sounds of the sea.
SynthDef(\ocean, {
var wave1 = BrownNoise.ar() * SinOsc.kr(
LFNoise1.ar(0.1).exprange(0.2, 0.5)
).range(0.3, 0.6);
var wave2 = BrownNoise.ar() * SinOsc.kr(
LFNoise1.ar(0.1).exprange(0.5, 0.7),
phase: 0.2
).range(0.3, 0.6) * 0.8;
var wind = BPF.ar(
WhiteNoise.ar(),
LFNoise2.kr(3).exprange(1200, 1500),
rq:0.15
) * LFNoise1.ar(0.4).range(0.4, 1.5);
Out.ar(0, ([wave1, wave2] * 0.8 + wind) * 0.7 * \amp.kr(1))
}).add;
How can I best achieve this?
I have tried to use an Ndef. Trying Ndef(\bg, Synth(\ocean)) results in an error: "A synth is no valid source for a proxy". I tried Ndef(\bg, Pbind(\instrument, \ocean, \dur, \inf)) but that leaves me unable to modify any of the parameters (when I try set I don't see anything, presumably because it waits until the next event of the pattern, which never comes).
So how can I do this? Feel free to answer using any of Ndef, NodeProxy or ProxySpace, whatever suits you best. Or to tell me that this is an XY problem, and I should be doing something else instead.
For your use case, You can just use the SynthDef as you have it above. Then control it with a Pdef:
Eg, running each of these lines one at a time:
Pdef(\ocean, Pmono(\ocean, \amp, 0.2)).play
Pdef(\ocean).fadeTime=5
Pdef(\ocean, Pmono(\ocean, \amp, 0))
If you're writing the SynthDef ahead of time, just for good practice, you might want to add a gate to it and have an envelope with a doneAction, so it doesn't run forever.
SynthDef(\ocean, {
var wave1 = BrownNoise.ar() * SinOsc.kr(
LFNoise1.ar(0.1).exprange(0.2, 0.5)
).range(0.3, 0.6);
var wave2 = BrownNoise.ar() * SinOsc.kr(
LFNoise1.ar(0.1).exprange(0.5, 0.7),
phase: 0.2
).range(0.3, 0.6) * 0.8;
var wind = BPF.ar(
WhiteNoise.ar(),
LFNoise2.kr(3).exprange(1200, 1500),
rq:0.15
) * LFNoise1.ar(0.4).range(0.4, 1.5);
var env = EnvGen.kr(Env.asr, \gate.kr(1), doneAction:2);
Out.ar(0, ([wave1, wave2] * 0.8 + wind) * 0.7 * \amp.kr(1) * env)
}).add;
// wait
Pdef(\ocean, Pmono(\ocean, \amp, 0.2)).play
//wait
Pdef(\ocean).stop