2 classvar <>lastOutBus = 99;
4 var <proxy, <usesPlayN = false, <usesName, <usesPausSend;
5 var <win, <zone, <flow;
6 var <ampSl, <playBut, <nameView, <setOutBox, <playNDialogBut, <pauseBut, <sendBut;
7 var <skipjack, <oldState = #[];
9 *new { |proxy, w, bounds, showLevel=false, showPlayN=true, showName=true, showPauseSend = true,
10 makeWatcher=true, skin|
12 ^super.new.init(w, bounds, showLevel, showPlayN, showName, showPauseSend, makeWatcher, skin)
16 if (proxy.isNil or: proxy.isKindOf(NodeProxy)) {
20 warn("ProxyMonitorGui: % is not a nodeproxy.".format(inproxy))
24 init { |w, bounds, showLevel, showPlayN, showName, showPauseSend, makeWatcher, skin|
30 var pausSendWid = playWid * 2;
31 var defaultBounds = 400@20;
33 var widthSum, sliderWidth, winBounds, viewBounds;
35 skin = skin ? GUI.skins[\jitSmall];
36 font = GUI.font.new(*skin.fontSpecs);
38 usesPlayN = showPlayN;
40 usesPausSend = showPauseSend;
41 bounds = bounds ? defaultBounds;
45 viewBounds = bounds ? defaultBounds;
48 if (bounds.isKindOf(Point)) {
49 winBounds = Rect(80,400,0,0).setExtent(bounds.x, bounds.y);
53 // [\winBounds, winBounds, \viewBounds, viewBounds].postln;
54 win = Window(this.class.name.asString, winBounds, false).front;
58 zone = GUI.compositeView.new(win, viewBounds);
59 zone.background_(skin.foreground);
60 flow = FlowLayout(zone.bounds, 0@0, 0@0);
61 zone.decorator = flow;
64 if (viewBounds.isKindOf(Rect)) { viewBounds = viewBounds.extent };
66 // [\bounds, bounds, \winBounds, winBounds, \viewBounds, viewBounds].postln;
68 (showName.binaryValue * nameWid)
70 + (showPlayN.binaryValue * playNWid)
71 + (showPauseSend.binaryValue * pausSendWid);
72 sliderWidth = viewBounds.x - widthSum;
74 height = viewBounds.y;
76 ampSl = EZSlider(zone, (sliderWidth @ height), \vol, \db,
79 proxy.vol_(slid.value.dbamp);
82 labelWidth: showLevel.binaryValue * 20,
83 numberWidth: showLevel.binaryValue * 40);
84 ampSl.labelView.font_(font).align_(0);
85 ampSl.view.resize_(2);
88 // should have four states: ...
90 playBut = Button(zone, Rect(0,0,playWid, height))
91 .font_(font).resize_(3)
93 [ if (usesPlayN, \playN, \play), skin.fontColor, skin.offColor],
94 [ \stop, skin.fontColor, skin.onColor ]
97 playBut.action_({ arg btn, modif;
99 [ { if (modif.isAlt) { proxy.end } { proxy.stop }; },
100 { if (modif.isAlt) { proxy.vol_(0) };
101 if (usesPlayN) { proxy.playN } { proxy.play }
103 ].at(btn.value).value
107 setOutBox = EZNumber(zone, outWid@height, nil, [0, lastOutBus, \lin, 1],
110 if (proxy.monitor.isNil) {
111 "ProxyMonitorGui - cant set outs yet.".postln
113 proxy.monitor.out_(box.value.asInteger);
118 setOutBox.view.resize_(3);
119 setOutBox.numberView.font_(font).align_(0);
122 playNDialogBut = GUI.button.new(zone, Rect(0,0, playNWid, height))
123 .font_(font).resize_(3)
125 ["-=", skin.fontColor, skin.offColor],
126 ["-<", skin.fontColor, skin.onColor]
128 .action_({ |box, mod|
129 if (proxy.notNil) { proxy.playNDialog };
130 box.value_(1 - box.value);
135 nameView = DragBoth(zone, Rect(0,0, nameWid, height));
136 nameView.font_(font).align_(0).resize_(3)
138 .receiveDragHandler = { this.proxy_(View.implClass.currentDrag) };
142 pauseBut = GUI.button.new(zone, Rect(0,0,34,height))
143 .font_(font).resize_(3)
145 ["paus", skin.fontColor, skin.onColor],
146 ["rsum", skin.fontColor, skin.offColor]
150 [ { proxy.resume; }, { proxy.pause; } ].at(btn.value).value;
154 sendBut = Button(zone, Rect(0,0,34,height))
155 .font_(font).resize_(3)
157 ["send", skin.fontColor, skin.offColor],
158 ["send", skin.fontColor, skin.onColor]
160 .action_({ arg btn, mod;
161 if(proxy.notNil and: (btn.value == 0)) {
162 if (mod.isAlt) { proxy.rebuild } { proxy.send }
164 btn.value_(1 - btn.value)
168 if (makeWatcher) { this.makeWatcher };
173 skipjack = SkipJack({ this.updateAll },
174 0.5,
\r { win.isClosed },
\r ("ProxyMon" + try { proxy.key }).asSymbol
\r );
\r skipjack.start;
\r }
\r \r updateAll {
\r var monitor, outs, amps, newHasSeriesOut;
177 var currVol=0, pxname='<no proxy>', isAudio=false, plays=0, playsSpread=false, pauses=0, canSend=0;
180 if (win.isClosed) {skipjack.stop; ^this };
184 pxname = proxy.key ? 'anon';
185 type = proxy.typeStr;
186 canSend = proxy.objects.notEmpty.binaryValue;
187 pauses = proxy.paused.binaryValue;
189 isAudio = proxy.rate == \audio;
190 monitor = proxy.monitor;
191 plays = monitor.isPlaying.binaryValue;
193 if (monitor.notNil, {
194 currVol = proxy.monitor.vol;
195 playsSpread = proxy.monitor.hasSeriesOuts.not;
200 currState = [currVol, pxname, isAudio, plays, outs, playsSpread, pauses, canSend];
202 if (currState != oldState) {
203 // "ProxyMonitorGui - updating.".postln;
204 if (currVol.notNil) { ampSl.value_(currVol.ampdb) };
205 if (usesName) { nameView.object_(proxy).string_(pxname) };
207 playBut.value_(plays);
209 pauseBut.value_(pauses);
210 sendBut.value_(canSend);
213 if (isAudio != oldState[2]) {
214 [ampSl, playBut, setOutBox, playNDialogBut].reject(_.isNil).do(_.enabled_(isAudio));
216 // dont update if typing into numberbox - should be tested with SwingOSC!
217 if (setOutBox.numberView.hasFocus.not) {
218 setOutBox.value_(try { outs[0] } ? 0);
220 playNDialogBut.value_(playsSpread.binaryValue)
224 oldState = currState;
226 clear { proxy = nil }