clean up indentation and spacing
[supercollider.git] / SCClassLibrary / Common / GUI / PlusGUI / Control / scopeResponse.sc
blob69dcba76c00adba416b7974baf87007d78fa5dbc
1 /*
2 Server.default = s = Server.internal.boot;
4 {|in| MoogFF.ar(in, freq: LFCub.kr(0.2).exprange(10, 10000))}.scopeResponse
5 {|in| MoogFF.ar(in)}.scopeResponse
7 LPF.scopeResponse
8 HPF.scopeResponse
9 MoogFF.scopeResponse
10 BLowPass.scopeResponse
11 BBandPass.scopeResponse
12 BLowShelf.scopeResponse // by default BLowShelf doesn't mangle much
13 Resonz.scopeResponse
14 BRF.scopeResponse
15 Integrator.scopeResponse
16 Formlet.scopeResponse
17 Median.scopeResponse // nonlinear, and therefore interesting
18 Slew.scopeResponse
22 + Function {
23         scopeResponse{ |server, freqMode=1, label="Empirical Frequency response", mute = false|
25                 var bus1, bus2, synth, win, fs;
27                 if (server.isNil) {
28                         server = GUI.freqScopeView.server;
29                 } {
30                         if (server != GUI.freqScopeView.server) {
31                                 "Function-scopeReponse: resetting GUI.freqScopeView.server".warn;
32                                 GUI.freqScopeView.server = server;
33                         };
34                 };
36                 // Create two private busses
37                 bus1 = Bus.audio(server, 1);
38                 bus2 = Bus.audio(server, 1);
40                 // Create the SCFreqScope.response using the same simple window as in the helpfile
41                 // Also, onClose must free the synth and the busses
43                 win = GUI.window.new(label, Rect(100, 100, 511, 300));
44                 fs = GUI.freqScopeView.response(win, win.view.bounds, bus1, bus2, freqMode);
46                 win.onClose_ {
47                         fs.kill;
48                         synth.release;
49                 };
51                 win.front;
52                 fs.active_(true);
54                 // Create a synth using this function and the busses
55                 synth = { |gate = 1|
56                         var noise = PinkNoise.ar;
57                         var filtered = this.value(noise);
58                         var env = EnvGen.kr(Env.asr(0.1, 1, 0.1, \sine), gate, 0.1, doneAction: 2);
59                         if (not(mute)) {
60                                 Out.ar(0, (filtered * env) ! 2);   // filter only
61                         };
62                         Out.ar(bus1, noise);
63                         Out.ar(bus2, filtered);
64                 }.play(server.defaultGroup);
65                 synth.register;
66                 synth.onFree {
67                         {
68                                 [bus1, bus2].do(_.free);
69                                 fs.active_(false);
70                                 win.close;
71                         }.defer;
72                 }
74                 ^fs
75         }
79 + Filter {
80         *scopeResponse { |server, freqMode=1, label, args|
81                 var argNames = this.class.findRespondingMethodFor(\ar).argNames;
82                 var hasFreqInput = argNames.includes(\freq);
84                 ^if(hasFreqInput){
85                         {|in| this.ar(in: in, freq:MouseX.kr(10, 10000, 1)) * Line.ar(0,1,0.1) }
86                                 .scopeResponse(server, freqMode,
87                                         label ?? {"%: empirical frequency response (move mouse to change freq)".format(this.asString)}
88                                         )
89                 }{ // no freq input
90                         {|in| this.ar(in: in) * Line.ar(0,1,0.1) }
91                                 .scopeResponse(server, freqMode,
92                                         label ?? {"%: empirical frequency response".format(this.asString)}
93                                         )
94                 }
95         }