Μουσική Πληροφορική SC Ex.2
// This is an example of using two sliders in order to control the frequency and velocity of a Synth
SynthDef(\testsaw, {|freq = 400, amp = 0.01|
Out.ar(0 , Saw.ar(freq, amp))}).send(s);
Synth(\testsaw);
(
var slid, syn, slid2, text;
w = Window(“Demo Slider”, Rect(500, 500, 500, 200));
slid = Slider(w, Rect(20, 40, 150, 20)).background_(Color.rand);
slid2 = Slider(w, Rect(20, 140, 150, 20)).background_(Color.rand);
c = NumberBox(w, Rect(20, 70, 150, 20));
d = NumberBox(w, Rect(20, 170, 150, 20));
text = StaticText(w, Rect(200, -50, 250, 200));
text.string = (“This is an example of using two sliders in order to control the frequency and velocity of a Synth”);
text.font = Font(“Monaco”, 11);
b = Button(w, Rect(250,100,140,50));
b.states = ([
[“press to start synth”, Color.black, Color.red],
[“press to stop synth”, Color.white, Color.black],
]);
b.action = ({ |butt|
if (butt.value == 1, {syn = Synth(\testsaw);}, {syn.free});
butt.value.postln;
});
slid.action = ({
c.value = 100 + (1000 * slid.value;);
syn.set(\freq, 100 + (1000 * slid.value));
});
slid2.action = ({
d.value = slid2.value;
syn.set(\amp, slid2.value);
});
w.front;
w.onClose = {syn.free;};
)
Cygnus Thu, 09 December 2010, 12:05PM