-
Notifications
You must be signed in to change notification settings - Fork 4
/
VoicerGUI.sc
236 lines (205 loc) · 7.04 KB
/
VoicerGUI.sc
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
VoicerGUI : ObjectGui {
// override gui and guify -- this object should make NO VIEWS
// *new should return not a VoicerGUI but a VoicerProxyGui
// perhaps misleading but I want aVoicer.gui to set up the proxy and the gui transparently
// so that none of my old code gets broken
*new { arg model;
model.proxy.isNil.if({
/* model.proxy = */ VoicerProxy.new(model); // creating object assigns into voicer
});
^VoicerProxyGui.new(model.proxy); // then Object-gui calls .gui on the proxyGui
}
smallGui {} // need this to trick Object-smallGui into thinking I implement the method
}
// todo: check all references to model
VoicerProxyGui : ObjectGui {
// manages gui editing for voicers
// includes a flowview for global controls
// and a flowview for player processes which can be assigned to buttons
// presently not resizeable (until I learn more about flowviews)
classvar height = 500, width1 = 300,
width2 = 140; // width1 is for controlView; width2 for processView
// allow pre-population of gui objects for non-existent controls
classvar <>drawEmptyControlProxies = true;
var <mainView,
<panicButton, <runButton,
<controlView, <processView, // flowviews
<dragSink, // you'll be dropping things in here
<masterLayout, <layout, iMadeMasterLayout = false;
var myModel;
guify { arg lay,bounds,title, small=false;
if(lay.isNil,{
masterLayout = lay = ResizeHeightFlowWindow
(title ?? { model.asString.copyRange(0,50) },
Rect(0, 0, width1 + if(small, 10, width2 + 30), height));
iMadeMasterLayout = true; // now when I'm removed, I'll close the window too
},{
masterLayout = lay; // should only pass in the FixedWidthMultiPageLayout
lay = lay.asPageLayout(title,bounds);
});
// i am not really a view in the hierarchy
lay.removeOnClose(this);
^lay
}
// if doResize is false, view will be left too big
// use that if you want to create many guis in the same window
// and resize them all at the end
guiBody { arg lay, backgr, controlBackgr, processBackgr, doResize = true;
mainView.isNil.if({ // init the views only if we need a new window
layout = lay;
dragSink = GUI.dragSink.new(layout, Rect(0, 0, 30, 20))
.action_({ arg rec; // receiver is an SCDragSource
// different classes will handle this differently
// do nothing if it's not a supported object
rec.object.tryPerform(\draggedIntoVoicerGUI, this);
});
panicButton = ActionButton(layout, "panic", {
model.voicer.panic
});
// ActionButton.defaultHeight is deprecated for future sc versions
// but needed for backward (i.e., 3.2) compatibility here
runButton = GUI.button.new(layout, Rect(0, 0, 31, ActionButton.defaultHeight))
.states_([["run"], ["idle"]])
.font_(GUI.font.new(*GUI.skin.fontSpecs))
.action_({ |v|
model.run(v.value == 0);
});
layout.startRow;
mainView = FixedWidthFlowView.new(layout, Rect(0, 0, width1 + width2 + 10, height),
margin: 2@2)
.background_(backgr ? Color.grey);
controlView = FixedWidthFlowView.new(mainView, Rect(0, 0, width1, height), margin: 2@2)
.background_(controlBackgr ? Color.grey);
processView = FixedWidthFlowView.new(mainView, Rect(0, 0, width2, height), margin: 2@2)
.background_(processBackgr ? Color.grey);
processView.decorator.nextLine;
model.editor = this;
this.makeViews;
doResize.if({
{ this.sizeWindow; }.defer(0.25);
});
myModel = model;
});
}
smallGuiBody { arg lay, backgr, controlBackgr, processBackgr, doResize = true;
mainView.isNil.if({ // init the views only if we need a new window
layout = lay;
dragSink = GUI.dragSink.new(layout, Rect(0, 0, 30, 20))
.action_({ arg rec; // receiver is an SCDragSource
// different classes will handle this differently
// do nothing if it's not a supported object
rec.object.tryPerform(\draggedIntoVoicerGUI, this);
});
panicButton = ActionButton(layout, "panic", {
model.voicer.panic
});
runButton = GUI.button.new(layout, Rect(0, 0, 31, ActionButton.defaultHeight))
.states_([["run"], ["idle"]])
.font_(GUI.font.new(*GUI.skin.fontSpecs))
.action_({ |v|
model.run(v.value == 0);
});
layout.startRow;
mainView = FixedWidthFlowView.new(layout, Rect(0, 0, width1 + 10, height), margin: 2@2)
.background_(backgr ? Color.grey);
controlView = FixedWidthFlowView.new(mainView, Rect(0, 0, width1, height), margin: 2@2)
.background_(controlBackgr ? Color.grey);
model.editor = this;
this.makeViews;
doResize.if({
{ this.sizeWindow; }.defer(0.25);
});
});
}
writeName { arg layout;
var n;
n = model.asString;
block { |break|
['InspButton', 'InspectorLink'].do { |classname|
if(classname.asClass.notNil) {
classname.asClass.icon(model, layout);
break.();
};
};
};
dragSource = GUI.dragSource.new(layout,Rect(0,0,(n.size * 7.5).max(160),17))
.stringColor_(Color.new255(70, 130, 200))
.background_(Color.white)
.align_(\center)
.beginDragAction_({ model })
.object_(n);
}
makeViews {
drawEmptyControlProxies.if({ model.controlProxies }, { model.globalControlsByCreation })
.do({ arg gc;
gc.allowGUI.if({
// "this" is needed because gc might be inactive, and
// the gc gui object needs to know about the VoicerProxyGui
gc.makeGUI(false, this);
});
});
processView.notNil.if({
model.processes.do({ arg p;
p.makeGUI;
});
});
}
sizeWindow {
// if I'm the creator of the window, resize the whole window
// otherwise just resize my container view
{ iMadeMasterLayout.if({
masterLayout.recursiveResize;
}, {
mainView.recursiveResize;
});
nil
}.defer;
}
remove {
if(myModel.notNil) {
myModel.controlProxies.do({ arg gc;
gc.gui.remove(false, false); // don't remove views or resize
// just break connections--why?
gc.gui = nil; // -- view.remove removes all its children
});
myModel.editor = nil;
myModel = nil;
(view.notNil and: { view.notClosed }).if({
view.remove;
});
iMadeMasterLayout.if({
masterLayout.close;
});
// garbage
panicButton = runButton = controlView = processView = dragSink =
masterLayout = myModel = nil;
};
}
updateStatus {
var i, oldNumGCs;
// if model is nil, I must have been removed already
if(model.notNil) {
oldNumGCs = model.controlProxies.size;
{ dragSource.object_(model.asString); // cf ObjectGui-writeName
runButton.value = model.isRunning.not.binaryValue;
nil
}.defer;
i = 0; // index to controlProxies
// proxies should all be updated by this point
// only gui guiable controls; sort them in order of creation
model.globalControlsByCreation.do({ arg gc;
gc.makeGUI(false); // don't resize now; makeGUI adds gcproxy to voicerproxy
// note that makeGUI doesn't make a gui if there already is one
i = i+1;
});
// resize the window only if the number of controlproxies has changed
(oldNumGCs != model.controlProxies.size).if({
this.sizeWindow;
});
};
}
refresh {
this.sizeWindow;
}
minNameWidth { ^200 }
}