3 QStethoscope created by copying SCStethoscope and adjusting code for Qt GUI.
8 var <server, <numChannels, <rate, <index;
9 var <bufsize, buffer, <window, synth;
10 var scopeView, indexView, nChanView, xZoomSlider, yZoomSlider;
11 var style=0, sizeToggle=0, zx, zy, ai=0, ki=0, audiospec, controlspec, zoomspec;
14 *new { arg server, numChannels = 2, index, bufsize = 4096, zoom, rate, view, bufnum;
15 if(server.inProcess.not, { "scope works only with internal server".error; ^nil });
16 ^super.newCopyArgs(server, numChannels, rate ? \audio).makeWindow(view)
17 .index_(index ? 0).zoom_(zoom).allocBuffer(bufsize, bufnum).run;
21 var screenBounds = QWindow.screenBounds;
22 var x = 520 + (ugenScopes.size * (223 + 5)) + 5;
24 var y = floor(right / screenBounds.width) * 297 + 10;
25 if(right > screenBounds.right) { x = floor(right % screenBounds.width / 223) * (223 + 5) };
29 makeBounds { arg size = 223; ^Rect(297, 5, size, size) }
31 makeWindow { arg view;
34 window = QWindow("stethoscope", this.makeBounds);
36 view.decorator = FlowLayout(window.view.bounds);
38 window.onClose = { this.free };
41 if(view.decorator.isNil, {
42 "QStethoscope: makeWindow added a decorator to view".warn;
43 view.decorator = FlowLayout(view.bounds);
46 scopeView = QScope(view,
47 Rect(0,0, view.bounds.width - 10 - 20 - 4, view.bounds.height - 40)
49 scopeView.background = Color.black;
51 view.keyDownAction = { arg view, char; this.keyDown(char) };
52 view.background = Color.grey(0.6);
53 zx = scopeView.xZoom.log2;
54 zy = scopeView.yZoom.log2;
56 audiospec = ControlSpec(0, server.options.numAudioBusChannels, step:1);
57 controlspec = ControlSpec(0, server.options.numControlBusChannels, step:1);
58 zoomspec = ControlSpec(0.125, 16, \exp);
60 xZoomSlider = QSlider(view, Rect(10, 10, view.bounds.width - 80, 20));
61 xZoomSlider.action = { arg x;
63 i = this.spec.map(x.value);
65 this.xZoom = zoomspec.map(x.value)
67 xZoomSlider.resize = 8;
68 xZoomSlider.value = zoomspec.unmap(this.xZoom);
69 xZoomSlider.background = Color.grey(0.6);
70 xZoomSlider.focusColor = Color.clear;
72 indexView = QNumberBox(view, Rect(10, 10, 30, 20))
73 .value_(0).decimals_(0).step_(1).scroll_step_(1);
74 indexView.action = { this.index = indexView.value; };
76 indexView.font = QFont("Monaco", 9);
77 nChanView = QNumberBox(view, Rect(10, 10, 25, 20))
78 .value_(numChannels).decimals_(0).step_(1).scroll_step_(1);
79 nChanView.action = { this.numChannels = nChanView.value.asInteger };
81 nChanView.font = QFont("Monaco", 9);
82 QStaticText(view, Rect(10, 10, 20, 20)).visible_(false);
87 view.decorator.shift(scopeView.bounds.right, 0);
89 yZoomSlider = QSlider(view, Rect(scopeView.bounds.right, 0, 20, scopeView.bounds.height));
90 yZoomSlider.action = { arg x;
91 this.yZoom = zoomspec.map(x.value)
93 yZoomSlider.resize = 6;
94 yZoomSlider.value = zoomspec.unmap(this.yZoom);
95 yZoomSlider.background = Color.grey(0.6);
96 yZoomSlider.focusColor = Color.clear;
100 if(char === $i) { this.toInputBus; ^this };
101 if(char === $o) { this.toOutputBus; ^this };
102 if(char === $ ) { this.run; ^this };
103 if(char === $s) { this.style = (style + 1) % 2; ^this };
104 if(char === $S) { this.style = 2; ^this };
105 if(char === $j or: { char.ascii === 0 }) { this.index = index - 1; ^this };
106 if(char === $k) { this.switchRate; ^this };
107 if(char === $l or: { char.ascii === 1 }) { this.index = index + 1 };
108 if(char === $-) { zx = zx + 0.25; this.xZoom = 2 ** zx; ^this };
109 if(char === $+) { zx = zx - 0.25; this.xZoom = 2 ** zx; ^this }; if(char === $*) { zy = zy + 0.25; this.yZoom = 2 ** zy; ^this };
110 if(char === $_) { zy = zy - 0.25; this.yZoom = 2 ** zy; ^this };
111 if(char === $A) { this.adjustBufferSize; ^this };
112 if(char === $m) { this.toggleSize; ^this };
113 if(char === $.) { if(synth.isPlaying) { synth.free } };
117 spec { ^if(rate === \audio) { audiospec } { controlspec } }
119 setProperties { arg numChannels, index, bufsize=4096, zoom, rate;
121 if(rate.notNil) { this.rate = rate };
122 if(index.notNil) { this.index = index };
123 if(numChannels.notNil) { this.numChannels = numChannels };
124 if(this.bufsize != bufsize) { this.allocBuffer(bufsize) };
125 if(zoom.notNil) { this.zoom = zoom };
128 allocBuffer { arg argbufsize, argbufnum;
129 bufsize = argbufsize ? bufsize;
130 if(buffer.notNil) { buffer.free };
131 buffer = Buffer.alloc(server, bufsize, numChannels, nil, argbufnum);
132 scopeView.bufnum = buffer.bufnum;
133 if(synth.isPlaying) { synth.set(\bufnum, buffer.bufnum) };
137 if(synth.isPlaying.not) {
138 synth = SynthDef("stethoscope", { arg in, switch, bufnum;
140 z = Select.ar(switch, [In.ar(in, numChannels), K2A.ar(In.kr(in, numChannels))]);
141 ScopeOut.ar(z, bufnum);
142 }).play(RootNode(server), [\bufnum, buffer.bufnum, \in, index, \switch]
143 ++ if('audio' === rate) { 0 } { 1 },
146 synth.isPlaying = true;
147 NodeWatcher.register(synth);
154 if(synth.isPlaying) { synth.free };
156 if(server.scopeWindow === this) { server.scopeWindow = nil }
164 numChannels_ { arg n;
167 if(n > 128) { "cannot display more than 128 channels at once".inform; n = 128 };
168 if(n != numChannels and: { n > 0 }) {
169 isPlaying = synth.isPlaying;
170 if(isPlaying) { synth.free; synth.isPlaying = false; synth = nil }; // immediate
175 if(isPlaying) { this.run };
183 index = spec.constrain(val);
184 if(synth.isPlaying) { synth.set(\in, index) };
185 if(rate === \audio) { ai = index } { ki = index };
186 indexView.value = index;
187 // xZoomSlider.value = spec.unmap(index)
190 rate_ { arg argRate=\audio;
191 if(rate === argRate) { ^this };
192 if(argRate === \audio)
194 if(synth.isPlaying) { synth.set(\switch, 0) };
201 if(synth.isPlaying) { synth.set(\switch, 1) };
209 size_ { arg val; if(window.notNil) { window.bounds = this.makeBounds(val) } }
210 toggleSize { if(sizeToggle == 0)
211 { sizeToggle = 1; this.size_(500) }
212 { sizeToggle = 0; this.size_(212) }
216 scopeView.xZoom = val;
218 xZoomSlider.value = zoomspec.unmap(val);
221 scopeView.yZoom = val;
223 yZoomSlider.value = zoomspec.unmap(val);
228 zoom_ { arg val; this.xZoom_(val ? 1) }
231 if(numChannels < 2 and: { val == 2 }) {
232 "QStethoscope: can't do x/y scoping with one channel".warn;
235 scopeView.style = style = val
241 scopeView.waveColors = if(\audio === rate) {
242 Array.fill(numChannels, { Color.new255(255, 218, 000) });
244 Array.fill(numChannels, { Color.new255(125, 255, 205) });
248 switchRate { if(rate === \control) { this.rate = \audio } { this.rate = \control } }
251 this.index = server.options.numOutputBusChannels;
252 this.numChannels = server.options.numInputBusChannels;
256 this.numChannels = server.options.numOutputBusChannels;
259 this.allocBuffer(max(256,nextPowerOfTwo(
260 asInteger(scopeView.bounds.width * scopeView.xZoom))))
265 if(ugenScopes.isNil, { ugenScopes = Set.new; });
270 * @return (Server) the default server to scope on
277 * @param aServer (Server) a server to test for scoping
278 * @return (Boolean) indication whether the server can be scope'ed
280 *isValidServer { arg aServer;