// -----------  SwingOSC as an alternative GUI system -------------

// on Linux or Win install SwingOSC first
// see SwingOSC/SuperCollider/readme.html

// assign the SwingOSC GUI server to g (as s is assigned to Server.local)
g = SwingOSC.default;
g.boot;

// test:
JSCWindow.viewPalette;

GUI.cocoa;
GUI.swing;

( // to see a server window via the GUI class (i.e. cross-platform), execute this:
if( s.window.notNil, { s.window.close });
s.makeWindow;
)

//  whith SwingOSC Server scope works also on the local server!
s.scope;

// a synth to see something in the scope:
Synth("default")

// also does loadDialog ...
b = Buffer.loadDialog
b = Buffer.read(s, <path>);

// .. and plot
b.plot

Env.perc(0.1, 1.0).plot

Array.rand(30, 0.0, 1.0).plot

{ SinOsc.ar(100, 0, EnvGen.kr(Env.perc(0.1, 1.0))) }.plot(1.1)

// working with windows and GUI elements

(
var w, bt, sl1, sl2, sl3;
var synth;

SynthDef("irgendwas", { arg freq=100, amp=0.1, lfo=7;
	var sig, mod;
	
	freq = freq.clip(10, 10000);
	mod = LFSaw.ar(lfo * -1.0).exprange(0.01, 1);
	sig = Pulse.ar(freq * [0.99, 1.01], 0.5, amp * mod);
	sig = RLPF.ar(sig, Amplitude.ar(sig, 0.002, 0.01).exprange(freq*1, freq*17), 0.1);
	Out.ar(0, sig);
}, [0.1, 0.1, 0.1]).store;

w = GUI.window.new( "testwindow", Rect( 200, 400, 340, 360 ));
//w.alpha = 0.3;
// w.alpha_(0.3)
//SCWindow			JSCWindow
//SCStaticText
//SCSlider

GUI.staticText.new(w, Rect(20, 20, 200, 20)).string_("pitch");

sl1 = GUI.slider.new(w, Rect(10, 40, 200, 20))
	.action_({ arg view;
		synth.set(\freq, (view.value * 36 + 48).midicps);
	});

GUI.staticText.new(w, Rect(20, 70, 200, 20)).string_("lfo");

sl2 = GUI.slider.new(w, Rect(10, 90, 200, 20));
sl2.action_({ arg view;
	synth.set(\lfo, view.value * 30 + 0.1);
	});

GUI.staticText.new(w, Rect(20, 120, 200, 20)).string_("amp");

sl3 = GUI.slider.new(w, Rect(10, 140, 200, 20));
sl3.action = { arg view;
	synth.set(\amp, (view.value * 60 - 60).dbamp);
	};

bt = GUI.button.new(w, Rect(80, 200, 100, 30));
bt.font = GUI.font.new("Arial", 22);
bt.states = [["mute", Color.red(0.7), Color.black], ["muted", Color.black, Color.red]];
bt.action = { arg view;
	synth.run( [true, false].at(view.value) );
	};

w.front;
w.onClose = { synth.free };

{ synth = Synth("irgendwas") }.defer(1.0);
//synth = Synth("default");

)