1 // basic gui for a proxy, with monitor or not.
5 classvar <>lastOutBus = 99;
8 var <ampSl, <playBut, <setOutBox, <playNDialogBut, <fadeBox;
11 Class.initClassTree(Spec);
12 Spec.add(\ampx4, [0, 4, \amp]);
13 Spec.add(\fadePx, [0, 100, \amp, 0, 0.02]);
15 // options can be: \playN, \level, \name, \fade
16 *new { |object, parent, bounds, makeSkip=true, options = #[]|
17 ^super.newCopyArgs(object, 0, parent, bounds).init(makeSkip, options)
20 setDefaults { |options|
23 level: options.includes(\level),
24 playN: options.includes(\playN),
25 name: options.includes(\name),
26 fade: options.includes(\fade)
29 if (parent.notNil) { skin = skin.copy.put(\margin, 0@0) };
31 // a lot more negotiations, based on which options should be there
36 if (config.level) { minWidth = minWidth + 60 };
37 if (config.name) { minWidth = minWidth + 60 };
38 if (config.playN) { minWidth = minWidth + 20 };
39 if (config.fade) { minWidth = minWidth + 60 };
40 minSize = minWidth @ (skin.buttonHeight + (skin.margin.y * 2));
41 /// "MonitorGui-minSize: %\n".postf(minSize);
46 var fullWid = zone.bounds.width;
47 var height = zone.bounds.height - (skin.margin.y * 2);
49 var levelWid = if (config.level, 60, 0);
50 var nameWid = if (config.name, 60, 0);
51 var fadeWid = if (config.fade, 60, 0);
52 var playWid = 40, outWid = 30;
53 var playNWid = if (config.playN, 20, 0);
55 var sliderWidth = fullWid - (levelWid + playWid + outWid + playNWid + nameWid + fadeWid) - 4;
57 zone.decorator.margin_(0@0);
61 this.makeVol(sliderWidth + levelWid, height);
62 this.makePlayOut(playWid, outWid, height);
64 if(config.playN) { this.makePlayNDialogBut(playNWid, height) };
65 if (config.name) { this.makeNameView(nameWid, height) };
66 if (config.fade) { this.makeFade(fadeWid, height) };
70 ^(obj.isNil or: { obj.isKindOf(NodeProxy) })
73 makeNameView { |width, height|
74 nameView = DragSource(zone, Rect(0,0, width, height))
75 .font_(font).align_(0).resize_(3)
78 makeFade { |width = 60, height = 18|
79 fadeBox = EZNumber(zone, width@height, \fade, \fadePx,
80 { |num| try { object.fadeTime_(num.value) } },
81 try { object.fadeTime } ? 0.02,
83 numberWidth: width - 28
86 fadeBox.labelView.font_(font).background_(Color.clear);
87 fadeBox.numberView.font_(font).background_(Color.clear);
88 fadeBox.view.resize_(3);
91 makeVol { |width, height|
92 var showLev = config.level.binaryValue;
94 ampSl = EZSlider(zone, (width @ height), \vol, \amp,
95 { arg sl; if(object.notNil) { object.vol_(sl.value) } },
97 labelWidth: showLev * 20,
98 numberWidth: showLev * 40);
100 ampSl.labelView.font_(font).align_(0);
101 ampSl.view.resize_(2);
104 makePlayOut { |playWid, outWid, height|
106 playBut = Button(zone, Rect(0,0, playWid, height))
107 .font_(font).resize_(3)
109 [ if (config.playN, \playN, \play), skin.fontColor, skin.offColor],
110 [ \stop, skin.fontColor, skin.onColor ]
113 this.playNMode_(config.playN);
115 setOutBox = EZNumber(zone, outWid@height, "", [0, lastOutBus, \lin, 1],
118 if (object.monitor.isNil) {
119 "MonitorGui - monitor is nil, cannot set outs yet.".postln;
122 object.monitor.out_(box.value.asInteger);
125 }, 0, labelWidth: 1, unitWidth: 1); // 1 is workaround for EZNumber resize bug
126 setOutBox.view.resize_(3);
127 setOutBox.numberView.font_(font).align_(\center);
130 makePlayNDialogBut { |playNDWid, height|
132 playNDialogBut = GUI.button.new(zone, Rect(0,0, playNDWid, height))
133 .font_(font).resize_(3)
135 ["-=", skin.fontColor, skin.offColor],
136 ["-<", skin.fontColor, skin.onColor]
138 .action_({ |box, mod|
140 object.playNDialog(usePlayN:
141 try { object.monitor.usedPlayN } { config.playN }
144 box.value_(1 - box.value);
148 playNMode_ { |flag = true|
149 var playName, stopName, func;
150 if (flag.isNil) { "MonitorGui.playNMode_ : flag is nil? should not happen.".postln; flag = false };
153 playName = \playN; stopName = \stopN; func = { object.playN };
155 playName = \play; stopName = \stop; func = { object.play };
159 [(playBut.states[0][0] = playName),
160 (playBut.states[1][0] = stopName) ]);
163 playBut.action_({ arg btn, modif;
164 var alt = modif.notNil and: { modif.isAlt };
166 [ { if (alt) { object.end } { object.stop }; },
167 { if (alt) { object.vol_(0) };
170 ].at(btn.value).value;
171 btn.value_((try { object.monitor.isPlaying } ? false).binaryValue);
173 "MonitorGui - no proxy to play!".warn;
180 var isAudio, newState;
181 var monitor, outs, amps, newHasSeriesOut;
182 var plays = 0, playsSpread = false;
196 if (object.isNil) { ^newState };
201 \isAudio, object.rate == \audio
204 monitor = object.monitor;
211 \monPlaying, monitor.isPlaying.binaryValue,
213 \usedPlayN, monitor.usedPlayN,
214 \out, monitor.out ? 0,
215 \playsSpread, monitor.hasSeriesOuts.not,
216 \monFade, monitor.fadeTime
223 var newState = this.getState;
225 // // don't know why early exit suppresses changes in play state. fix later...
226 // if (newState == prevState) { ^this };
229 if (newState[\object] != prevState[\object]) {
230 zone.visible_(newState[\object].notNil);
233 if (newState[\isAudio] != prevState[\isAudio]) {
234 zone.enabled_(newState[\isAudio]);
237 if (nameView.notNil) {
238 if (newState[\name] != prevState[\name]) {
239 nameView.object_(newState[\object])
240 .string_(newState[\name].asString);
244 if (newState[\vol] != prevState[\vol]) {
245 ampSl.value_(newState[\vol]);
247 if (newState[\monPlaying] != prevState[\monPlaying]) {
248 playBut.value_(newState[\monPlaying]);
250 if (newState[\usedPlayN] != prevState[\usedPlayN]) {
251 this.playNMode_ (newState[\usedPlayN]);
253 if (newState[\out] != prevState[\out]) {
254 setOutBox.value_(newState[\out]);
257 if (playNDialogBut.notNil) {
258 if (newState[\playsSpread] != prevState[\playsSpread]) {
259 // "playsSpread: %\n".postf(newState[\playsSpread].binaryValue);
260 playNDialogBut.value_(newState[\playsSpread].binaryValue)
264 if (fadeBox.notNil) {
265 if (newState[\monFade] != prevState[\monFade]) {
266 fadeBox.value_(newState[\monFade] ? 0.02);
270 prevState = newState;