I have a problem with this code. It’s supposed to make it so my TouchOsc on my iPhone works like a keyboard with the sound being generated by Supercollider. What happens though is occasionally the scsynth does not release the node, which I can see on the Node tree. The old nodes usually don’t sound, but they should disappear, and there seems to be some sluggishness when they are many. I think the problem comes from some interaction in Synth between the sclang and the scsynth. The f is set to one of the fmgen’s from 100 FM Synths that came with the Supercollider package, modified to be a sustaining instrument like it says in the file.
(
~oldlatency = s.latency;
s.latency = 0;
// s.latency = ~oldlatency; do this when done
~bus = 0;
)
(
~pushb = Array.newClear(16);
~synths = Array.newClear(16);
f = ("fmgen_s_" ++ 100.rand);
("f is " ++ f).postln;
~bias = 80; // GS bottom-1
[13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]
.do(
{ |button, i|
~pushb.put(
i,
OSCdef.new(
'push'++(i+1).asString,
{ |msg, time, addr, port|
if (
msg[1] == 1,
{
if ((~synths[i].notNil), { ~synths[i].set(\gate, 0)});
~synths.put(i, Synth(f, [out: ~bus, freq: (~bias+i).midicps]));
},
{ ~synths[i].set(\gate, 0); ~synths[i] = nil }
);
},
'/2/push'++button.asString
)
)
}
);
)