File: scopeResponse.sc

package info (click to toggle)
supercollider 1%3A3.6.6~repack-2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,792 kB
  • ctags: 25,269
  • sloc: cpp: 177,129; lisp: 63,421; ansic: 11,297; python: 1,787; perl: 766; yacc: 311; sh: 286; lex: 181; ruby: 173; makefile: 168; xml: 13
file content (96 lines) | stat: -rw-r--r-- 2,476 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Server.default = s = Server.internal.boot;

{|in| MoogFF.ar(in, freq: LFCub.kr(0.2).exprange(10, 10000))}.scopeResponse
{|in| MoogFF.ar(in)}.scopeResponse

LPF.scopeResponse
HPF.scopeResponse
MoogFF.scopeResponse
BLowPass.scopeResponse
BBandPass.scopeResponse
BLowShelf.scopeResponse // by default BLowShelf doesn't mangle much
Resonz.scopeResponse
BRF.scopeResponse
Integrator.scopeResponse
Formlet.scopeResponse
Median.scopeResponse // nonlinear, and therefore interesting
Slew.scopeResponse

*/

+ Function {
	scopeResponse{ |server, freqMode=1, label="Empirical Frequency response", mute = false|

		var bus1, bus2, synth, win, fs;

		if (server.isNil) {
			server = GUI.freqScopeView.server;
		} {
			if (server != GUI.freqScopeView.server) {
				"Function-scopeReponse: resetting GUI.freqScopeView.server".warn;
				GUI.freqScopeView.server = server;
			};
		};

		// Create two private busses
		bus1 = Bus.audio(server, 1);
		bus2 = Bus.audio(server, 1);

		// Create the SCFreqScope.response using the same simple window as in the helpfile
		// Also, onClose must free the synth and the busses

		win = GUI.window.new(label, Rect(100, 100, 511, 300));
		fs = GUI.freqScopeView.response(win, win.view.bounds, bus1, bus2, freqMode);

		win.onClose_ {
			fs.kill;
			synth.release;
		};

		win.front;
		fs.active_(true);

		// Create a synth using this function and the busses
		synth = { |gate = 1|
			var noise = PinkNoise.ar;
			var filtered = this.value(noise);
			var env = EnvGen.kr(Env.asr(0.1, 1, 0.1, \sine), gate, 0.1, doneAction: 2);
			if (not(mute)) {
				Out.ar(0, (filtered * env) ! 2);   // filter only
			};
			Out.ar(bus1, noise);
			Out.ar(bus2, filtered);
		}.play(server.defaultGroup);
		synth.register;
		synth.onFree {
			{
				[bus1, bus2].do(_.free);
				fs.active_(false);
				win.close;
			}.defer;
		}

		^fs
	}
}


+ Filter {
	*scopeResponse { |server, freqMode=1, label, args|
		var argNames = this.class.findRespondingMethodFor(\ar).argNames;
		var hasFreqInput = argNames.includes(\freq);

		^if(hasFreqInput){
			{|in| this.ar(in: in, freq:MouseX.kr(10, SampleRate.ir / 4, 1)) * Line.ar(0,1,0.1) }
				.scopeResponse(server, freqMode,
					label ?? {"%: empirical frequency response (move mouse to change freq)".format(this.asString)}
					)
		}{ // no freq input
			{|in| this.ar(in: in) * Line.ar(0,1,0.1) }
				.scopeResponse(server, freqMode,
					label ?? {"%: empirical frequency response".format(this.asString)}
					)
		}
	}
}