Hi, newbie here,
What would be the best way to control the amplitude of a synth, which is sequenced within a routine with touchosc ?
I’m trying to achieve this with the code below, but it doesn’t work as i would expect.
Thank you for your help
here is the code
//Create the synth
(
SynthDef(\mixedklanks ,{
arg out = 0, freqs = #[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], rings = #[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], atk = 5, sus = 8, rel = 5, pan = 0, amp = 0.5, gate = 0;
var sustain = 6, transition = 10, overlap = 5;
var period = transition*2+sustain/overlap;
var e = EnvGen.kr(Env.linen(atk, sus, rel, 1, 4), gate:gate, doneAction: Done.freeSelf);
var i = WhiteNoise.ar(0.0012);
var z = Klank.ar(`[freqs, nil, rings], i);
Out.ar(out, Pan2.ar(z*e*amp, pan));
}).add;
)
//Create controllers
//button1 -> start/stop routine
(
OSCdef.new(key: \toggle1,
func:
{
arg msg;
msg.postln;
(msg[1] > 0.5).if({
r = Routine{
var sustain = 6, transition = 10, overlap = 5;
var period = transition*2+sustain/overlap;
0.5.wait; // wait for the synthdef to be sent to the server
inf.do {
~synth = Synth(\mixedklanks, [
\gate, 1,
\atk, 10,
\sus, 6,
\rel, 10,
\pan, 1.0.rand2,
\freqs, {((#[0,2,4,5,7,9,11].choose + #[24,36,48,60,72,84].choose + 5).midicps)}.dup(12),
\rings, {0.1.rrand(3)}.dup(12)
]);
period.wait;
}
}.play;
}, {
r.stop;
});
},
path: '/1/toggle1'
);
//fader1 -> control amp
OSCdef.new(
\fader1,
{
arg msg, time, addr, port;
msg.postln;
~synth.set(\amp, msg[1]);
},
'/1/fader1'
);
)