Set a Synth param with MouseX

Hi, I want to quickly try some parameter changes on a synth while designing it. How can I get mouse coordinates to set its parameters?

I’m trying to do the following;

SynthDef(\t3, {
	|amp=0.1, pan=0, out=0, gate=1,p0=1, p1=1, p2=1, p3=1|
	var sig, env;
	sig = {x=LFNoise1.ar((p2*0.5)!2);Formlet.ar(Crackle.ar(x.range(p0*0.8 +1,1.98)),TExpRand.ar(p1*200,2e3,x).lag(2),x.range(5e-4,1e-3),p3* 0.0012)};

	env = EnvGen.ar(Env.adsr(),gate,doneAction:2, levelScale:amp);
	Out.ar(out, Pan2.ar(sig*env, pan));
}
).add;

a = Synth(\t3);
a.set(\p0, <a value from MouseX here>);

Thank you!

Since MouseX/MouseY are server-side, your options are either to use them directly in your SynthDef OR (and this is probably the better/more flexible choice in your case) to make a separate Synth that writes mouse coordinates to a control Bus and map that bus to a Control in your Synth.

So in addition to the SynthDef and Synth in your example, you’d add something like:

SynthDef.new(\mouse, { Out.kr(\outBus.kr, MouseX.kr) }).add;

~mouseBus = Bus.control;
~mouse = Synth.new(\mouse, [\outBus, ~mouseBus]);

a.map(\p0, ~mouseBus)
2 Likes