1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// thor magnusson (2007)
// Example showing how SCScope can be used in a UI
GUI.cocoa; // use Mac OS X native GUI
GUI.swing; // use Java GUI
(
s = Stethoscope.defaultServer;
s.waitForBoot({
var sc;
b = Buffer.alloc(s,2048,2);
a = SynthDef(\scopeExample, { arg freq=400, rate=2, amp=0.4, pan=0;
var signal, scope;
signal = [LFSaw.ar(freq, 0, amp/2)*SinOsc.ar(rate),
Pulse.ar( freq, 0.51, amp)*SinOsc.ar(rate)];
signal = Balance2.ar(signal[0], signal[1], pan);
scope = if( GUI.id === \cocoa, \ScopeOut, \JScopeOut ).asClass;
scope.ar( signal, b );
Out.ar(0, signal);
}).play(s);
w = Window("scope in a gui", Rect(100, 400, 400, 300))
.onClose_({a.free;}) // free synth on closing window
.front;
MultiSliderView(w, Rect(10, 10, 90, 120))
.value_([0.4, 0.5, 0.6, 0.5])
.indexIsHorizontal_(false)
.isFilled_(true)
.strokeColor_(Color.new255(10, 55, 10))
.fillColor_(Color.new255(110, 155, 110).alpha_(0.6))
.indexThumbSize_(26)
.gap_(4)
.valueThumbSize_(1)
.action_({|sl|
sl.index.switch
{0} { a.set(\freq, 400+(sl.value[sl.index]*400)) }
{1} { a.set(\rate, (sl.value[sl.index]*10)) }
{2} { a.set(\amp, sl.value[sl.index]) }
{3} { a.set(\pan, (sl.value[sl.index]*2)-1) };
});
StaticText(w, Rect(14, 4, 90, 30))
.string_("Freq");
StaticText(w, Rect(14, 34, 90, 30))
.string_("Rate");
StaticText(w, Rect(14, 64, 90, 30))
.string_("Amp");
StaticText(w, Rect(14, 94, 90, 30))
.string_("Pan");
StaticText(w, Rect(10, 140, 90, 16))
.string_("xZoom:");
Slider(w, Rect(10, 160, 90, 24))
.action_({|sl| sc.xZoom_(sl.value*4)});
sc = ScopeView(w, Rect(120,10,260,260))
.bufnum_(b.bufnum)
.background_(Color.white)
.resize_(5)
.waveColors_([Color.black, Color.black]);
});
)
|