Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / SCClassLibrary / Common / GUI / PlusGUI / Control / server-scope.sc
blob1573ab84b8ce7fa1d9625c3a19bb6dae415e64d9
1 + Server {
2         scope { arg numChannels, index = 0, bufsize = 4096, zoom = 1, rate = \audio;
3                 numChannels = (numChannels ? 2).min(16);
4                 zoom = zoom ? 1.0;
6                 if(scopeWindow.isNil) {
7                         scopeWindow = Stethoscope(this, numChannels, index, bufsize, zoom, rate, nil,
8                                 this.options.numBuffers);
9                                 // prevent buffer conflicts by using reserved bufnum
10                         scopeWindow.window.onClose = scopeWindow.window.onClose.addFunc({ scopeWindow = nil });
11                         ServerTree.add(this, this);
12                 } {
13                         scopeWindow.setProperties(numChannels, index, bufsize, zoom, rate);
14                         scopeWindow.run;
15                         scopeWindow.window.front;
16                 };
17                 ^scopeWindow
18         }
20         freqscope {
21                 GUI.current.freqScopeView.tryPerform('server_', this);
22                 // FIXME: Can not change server in SwingOSC GUI.
23                 ^GUI.freqScope.new;
24         }
27 + Bus {
28         scope { arg bufsize = 4096, zoom;
29                 ^server.scope(numChannels, index, bufsize, zoom, rate);
30         }
34 + Function {
35         scope { arg numChannels, outbus = 0, fadeTime = 0.05, bufsize = 4096, zoom;
36                 var synth, synthDef, bytes, synthMsg, outUGen, server;
38                 server = GUI.stethoscope.defaultServer;
39                 if(server.serverRunning.not) {
40                         (server.name.asString ++ " server not running!").postln;
41                         ^nil
42                 };
44                 synthDef = this.asSynthDef(name: SystemSynthDefs.generateTempName, fadeTime:fadeTime);
45                 outUGen = synthDef.children.detect { |ugen| ugen.class === Out };
47                 numChannels = numChannels ?? { if(outUGen.notNil) { (outUGen.inputs.size - 1) } { 1 } };
48                 synth = Synth.basicNew(synthDef.name, server);
49                 bytes = synthDef.asBytes;
50                 synthMsg = synth.newMsg(server, [\i_out, outbus, \out, outbus], \addToHead);
51                 server.sendMsg("/d_recv", bytes, synthMsg);
52                 server.scope(numChannels, outbus, bufsize, zoom, outUGen.rate);
53                 ^synth
54         }
56         freqscope {
57                 var server = if (GUI.id === \swing)
58                         { GUI.freqScopeView.audioServer } { GUI.freqScopeView.server };
59                 this.play(server);
60                 ^GUI.freqScope.new
61         }