File: SynthDescPlusGUI.sc

package info (click to toggle)
supercollider 1%3A3.6.6~repack-2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,792 kB
  • ctags: 25,269
  • sloc: cpp: 177,129; lisp: 63,421; ansic: 11,297; python: 1,787; perl: 766; yacc: 311; sh: 286; lex: 181; ruby: 173; makefile: 168; xml: 13
file content (129 lines) | stat: -rw-r--r-- 3,294 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
+SynthDesc {
	makeWindow{
		if (Platform.makeSynthDescWindowAction.notNil) {
			^Platform.makeSynthDescWindowAction.value(this)
		} {
			^this.makeGui;
		}
	}

	makeGui {
		var w, startButton, sliders;
		var synth, cmdPeriodFunc;
		var usefulControls, numControls;
		var getSliderValues, gui;

		gui = GUI.current;

		usefulControls = controls.select {|controlName, i|
			var ctlname;
			ctlname = controlName.name.asString;
			(ctlname != "?") && (msgFuncKeepGate or: { ctlname != "gate" })
		};

		numControls = usefulControls.collect(_.defaultValue).flatten.size;
		sliders = IdentityDictionary(numControls);

		// make the window
		w = gui.window.new("another control panel", Rect(20, 400, 440, numControls * 28 + 32));
		w.view.decorator = FlowLayout(w.view.bounds);

		w.view.background = Color.rand(0.5, 1.0);

		// add a button to start and stop the sound.
		startButton = gui.button.new(w, 75 @ 24);
		startButton.states = [
			["Start", Color.black, Color.green],
			["Stop", Color.white, Color.red]
		];

		getSliderValues = {
			var envir;

			envir = ();
			usefulControls.do {|controlName, i|
				var ctlname = controlName.name.asString;
				var sliderEntry;
				if(ctlname[1] == $_ and: { "ti".includes(ctlname[0]) }) {
					ctlname = ctlname[2..];
				};

				if (sliderEntry.isArray) {
					envir.put(controlName.name, sliderEntry.collect(_.value));
				} {
					envir.put(controlName.name, sliderEntry.value);
				}
			};
			envir.use {
				msgFunc.valueEnvir
			};
		};


		startButton.action = {|view|
			if (view.value == 1) {
				Server.default.bind {
					synth = Synth(name, getSliderValues.value.postln).register;
				};
			} {
				if (this.hasGate) {
					synth.release;
				} {
					synth.free
				};
				synth = nil;
			};
		};

		// create controls for all parameters
		usefulControls.do {|controlName|
			var ctlname, ctlname2, capname, spec, controlIndex, slider;
			ctlname = controlName.name;
			capname = ctlname.asString;
			capname[0] = capname[0].toUpper;
			w.view.decorator.nextLine;
			ctlname = ctlname.asSymbol;
			if((spec = metadata.tryPerform(\at, \specs).tryPerform(\at, ctlname)).notNil) {
				spec = spec.asSpec
			} {
				spec = ctlname.asSpec;
			};

			if (spec.notNil) {
				slider = EZSlider(w, 400 @ 24, capname, spec,
					{ |ez|
						if(synth.isPlaying) { synth.set(ctlname, ez.value) }
					}, controlName.defaultValue);
			} {
				spec = ControlSpec(-1e10, 1e10);
				if (controlName.defaultValue.isNumber) {
					slider = EZNumber(w, 400 @ 24, capname, spec,
						{ |ez|
							if(synth.isPlaying) { synth.set(ctlname, ez.value) }
						}, controlName.defaultValue)
				} {
					slider = Array(controlName.defaultValue.size);
					controlName.defaultValue.do {|value, i|
						slider.add(EZNumber(w, 400 @ 24, "%[%]".format(capname, i), spec,
							{ |ez|
								if(synth.isPlaying) { synth.set(controlName.index + i, ez.value) }
							}, value))
					}
				}
			};
			sliders.put(ctlname, slider)
		};

		// set start button to zero upon a cmd-period
		cmdPeriodFunc = { startButton.value = 0; };
		CmdPeriod.add(cmdPeriodFunc);

		// stop the sound when window closes and remove cmdPeriodFunc.
		w.onClose = {
			synth.release;
			CmdPeriod.remove(cmdPeriodFunc);
		};

		^w.front; // make window visible and front window.
	}
}