clean up indentation and spacing
[supercollider.git] / SCClassLibrary / Common / GUI / PlusGUI / Control / SynthDescLibPlusGUI.sc
blobba5f39325809bae856fc4a10684ded37c4db93a8
1 + SynthDescLib {
2         browse {
3                 var w;
4                 var synthDescLib;
5                 var synthDescLibListView;
6                 var synthDescListView;
7                 var ugensListView;
8                 var controlsListView;
9                 var inputsListView;
10                 var outputsListView;
11                 var synthDescList;
12                 var hvBold12;
13                 var updateSynthDefs;
14                 var updateSynthDefData;
15                 var btn, testFn;
16                 var fntMono, gui;
18                 gui = GUI.current;
20                 hvBold12 = Font.sansSerif( 12 ).boldVariant;
21                 fntMono = Font.monospace( 10 );
23                 w = gui.window.new("SynthDef browser", Rect(128, (gui.window.screenBounds.height - 638).clip(0, 320),
24                         700, 608));
25                 w.view.decorator = FlowLayout(w.view.bounds);
27                 w.view.decorator.shift(220);
29                 testFn = {
30                         var synth, item;
31                         item = this[synthDescListView.item.asSymbol];
32                         if (item.notNil) {
33                                 synth = Synth(item.name);
34                                 synth.postln;
35                                 synth.play;
36                                 SystemClock.sched(3, {
37                                         if (item.hasGate)
38                                                 { synth.release }
39                                                 { synth.free };
40                                 });
41                         };
42                 };
44                 btn = gui.button.new(w, 48 @ 20);
45                 btn.states = [["test"]];
46                 btn.action = testFn;
48                 btn = gui.button.new(w, 48 @ 20);
49                 btn.states = [["window"]];
50                 btn.action = {
51                         var item;
52                         item = this[synthDescListView.item.asSymbol];
53                         if (item.notNil) {
54                                 GUI.use( gui, { item.makeWindow });
55                         }
56                 };
58                 w.view.decorator.nextLine;
59                 gui.staticText.new(w, Rect(0,0,220,24)).string_("SynthDescLibs").font_(hvBold12);
60                 gui.staticText.new(w, Rect(0,0,220,24)).string_("SynthDefs").font_(hvBold12);
61                 gui.staticText.new(w, Rect(0,0,220,24)).string_("UGens").font_(hvBold12);
62                 w.view.decorator.nextLine;
64                 synthDescLibListView = gui.listView.new(w, Rect(0,0, 220, 320)).focus;
65                 synthDescListView = gui.listView.new(w, Rect(0,0, 220, 320));
66                 synthDescListView.beginDragAction_({arg v;
67                         v.items[v.value].asSymbol;
68                 });
69                 ugensListView = gui.listView.new(w, Rect(0,0, 220, 320));
71                 w.view.decorator.nextLine;
72                 gui.staticText.new(w, Rect(0,0,240,24)).string_("SynthDef Controls")
73                         .font_(hvBold12).align_(\center);
74                 gui.staticText.new(w, Rect(0,0,200,24)).string_("SynthDef Inputs")
75                         .font_(hvBold12).align_(\center);
76                 gui.staticText.new(w, Rect(0,0,200,24)).string_("SynthDef Outputs")
77                         .font_(hvBold12).align_(\center);
78                 w.view.decorator.nextLine;
80                 controlsListView = gui.listView.new(w, Rect(0,0, 240, 160));
81                 inputsListView = gui.listView.new(w, Rect(0,0, 200, 160));
82                 outputsListView = gui.listView.new(w, Rect(0,0, 200, 160));
83                 controlsListView.resize = 4;
84                 inputsListView.resize = 4;
85                 outputsListView.resize = 4;
87                 if (GUI.id == \qt) {
88                         [controlsListView, inputsListView, outputsListView].do {
89                                 |listview| listview.selectionMode = \none
90                         };
91                 } {
92                         // this is a trick to not show hilighting.
93                         controlsListView.hiliteColor = Color.clear;
94                         inputsListView.hiliteColor = Color.clear;
95                         outputsListView.hiliteColor = Color.clear;
96                         controlsListView.selectedStringColor = Color.black;
97                         inputsListView.selectedStringColor = Color.black;
98                         outputsListView.selectedStringColor = Color.black;
99                 };
101                 controlsListView.font   = fntMono;
102                 inputsListView.font     = fntMono;
103                 outputsListView.font    = fntMono;
105                 w.view.decorator.nextLine;
107                 synthDescLibListView.items_(SynthDescLib.all.keys.asArray.sort)
108                         .value_(synthDescLibListView.items.indexOf(name) ? 0);
109                 synthDescLibListView.action = {
110                         synthDescListView.value = 0;
111                         updateSynthDefs.value;
112                 };
114                 synthDescListView.items = [];
115                 synthDescListView.action = {
116                         updateSynthDefData.value;
117                 };
118                 synthDescListView.enterKeyAction = testFn;
120                 updateSynthDefs = {
121                         var libName;
123                         libName = synthDescLibListView.item;
124                         synthDescLib = SynthDescLib.all[libName];
125                         synthDescList = synthDescLib.synthDescs.values.sort {|a,b| a.name <= b.name };
126                         synthDescListView.items = synthDescList.collect {|desc| desc.name.asString };
128                         updateSynthDefData.value;
129                 };
131                 updateSynthDefData = {
132                         var synthDesc;
134                         synthDesc = synthDescList[synthDescListView.value];
136                         if (synthDesc.isNil) {
137                                 ugensListView.items = [];
138                                 inputsListView.items = [];
139                                 outputsListView.items = [];
140                                 controlsListView.items = [];
141                         }{
142                                 ugensListView.items = synthDesc.def.children.collect { |x, i|
143                                         i.asString.copy.extend(7, $ ) ++ x.class.name.asString;
144                                 };
146                                 inputsListView.items = synthDesc.inputs.collect { |x|
147                                         var string;
148                                         string = x.rate.asString.copy;
149                                         string = string.extend(9, $ ) ++ " " ++ x.startingChannel;
150                                         string = string.extend(19, $ ) ++ " " ++ x.numberOfChannels;
151                                 };
152                                 outputsListView.items = synthDesc.outputs.collect { |x|
153                                         var string;
154                                         string = x.rate.asString.copy;
155                                         string = string.extend(9, $ ) ++ " " ++ x.startingChannel;
156                                         string = string.extend(19, $ ) ++ " " ++ x.numberOfChannels;
157                                 };
158                                 controlsListView.items = synthDesc.controls.reject {|a|
159                                         a.name == '?'
160                                 }.collect { |x|
161                                         var string;
162                                         string = if (x.name.notNil) { x.name.asString.copy; }{ "" };
163                                         if (x.rate.notNil) {
164                                                 string = string.extend(12, $ ) ++ " " ++ x.rate;
165                                         };
167                                         if (x.defaultValue.notNil) {
168                                                 if (x.defaultValue.isArray) {
169                                                         string = string.extend(22, $ ) ++ " " ++ x.defaultValue.collect(_.asStringPrec(6));
170                                                 } {
171                                                         string = string.extend(22, $ ) ++ " " ++ x.defaultValue.asStringPrec(6);
172                                                 }
173                                         };
174                                 };
175                         };
176                 };
178                 updateSynthDefs.value;
180                 w.front;
181         }