«Attack Detection and Amplitude Threshold Setter GUI» by eli.fieldsteel

on 15 Aug'11 00:28 in howtoamplitudethresholddetectionattackonsetgui

A modular GUI designed to detect amplitude attacks and set a globally retrievable threshold value.

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// VIDEO: http://www.youtube.com/watch?v=pFLj7yJzp60

(
s = Server.local;
~threshTest = nil;
s.waitForBoot({
	
	SynthDef(\threshTest, {
		arg thresh=(-30);
		var sig, amp, trig;
		sig = SoundIn.ar(0);
		amp = Amplitude.kr(sig).ampdb;
		amp = K2A.ar(amp);
		trig = amp >= thresh;
		SendReply.ar(Impulse.ar(50), 'trigVal', [trig]);
	}).add;
	
	w = Window.new("amplitude threshold tester", Rect(600, 250, 950, 220)).front;
	w.view.background_(Color.gray(0.75));
	w.onClose_({s.freeAll});
	
	~numberBox = NumberBox.new(w, Rect(180, 25, 450, 120))
		.font_(Font("Helvetica", 108))
		.value_(-30)
		.action_({
			|nb|
			nb.value.postln;
			~knob.value_((nb.value.dbamp) / (~maxValSlider.value.dbamp));
			if(~threshTest.notNil,
				{
					if(~threshTest.group.class == Group,
						{~threshTest.set(\thresh, nb.value)},
						{}
						);
				},
				{}
			);
		});
		
		~knob = Knob.new(w, Rect(20, 20, 150, 150))
			.background_(Color.gray(0.75))
			.color_([Color.blue(0.9,0.5), Color.green(0.65), Color.gray(0.6), Color.black])
			.value_(~numberBox.value.dbamp)
			.action_({
				|knob|
				~numberBox.valueAction_((knob.value * ~maxValSlider.value.dbamp).ampdb);
			});
			
		~maxValSlider = EZSlider(
			w, Rect(20, 160, 612, 40), "knob max",
			ControlSpec.new(-90,0,\lin,0.1,0,""),
			{
				|slider|
				~numberBox.valueAction_((~knob.value * slider.value.dbamp).ampdb)
			},
			1, false, 120, 65, 0, 20, \horz, 2@2, 2@2
			)
				.setColors(knobColor:Color.blue(0.9,0.5))
				.font_(Font("Helvetica", 24));
		
		~testButton = Button.new(w, Rect(650, 25, 160, 40))
			.states_([
				["start test", Color.white, Color.green(0.65)],
				["stop test", Color.white, Color.red(0.65)]
			])
			.action_({
				|but|
				case
				{but.value == 0} {~threshTest.free}
				{but.value == 1} {~threshTest = Synth(\threshTest, [\thresh, ~numberBox.value])};
			})
			.font_(Font("Helvetica", 32));
			
		~received = TextView(w, Rect(750, 95, 170, 60))
			.visible_(false)
			.editable_(false)
			.string_("received")
			.font_(Font("Helvetica", 42))
			.stringColor_(Color.black)
			.background_(Color.gray(0.725));
		
		w.drawHook = {
			|v|
			Pen.fillColor = Color.gray(0.75);
			Pen.strokeColor = Color.black;
			Pen.width = 3;
			Pen.addArc(700@125, 35, 0, 2pi);
			Pen.fillStroke;
		};
		w.refresh;
		
		~oscr1.remove;
		
		~oscr1 = OSCresponder(nil, 'trigVal', {
			|time, resp, msg|
			if(
				msg[3] == 1,
				{
					Routine {
						w.drawHook = { |v|
							Pen.fillColor = Color.green;
							Pen.strokeColor = Color.black;
							Pen.width = 3;
							Pen.addArc(700@125, 35, 0, 2pi);
							Pen.fillStroke;
						};
						w.refresh;
						~received.visible_(true);
						0.1.wait;
						w.drawHook = { |v|
							Pen.fillColor = Color.gray(0.75);
							Pen.strokeColor = Color.black;
							Pen.width = 3;
							Pen.addArc(700@125, 35, 0, 2pi);
							Pen.fillStroke;
						};
						w.refresh;
						~received.visible_(false);
					}.play(AppClock);
				},
				{}
			);
		}).add;		
})
)
descendants
«Re: Attack Detection and Amplitude Threshold Setter GUI» by anonymous (private)
full graph
raw 3112 chars (focus & ctrl+a+c to copy)
comments
eli.fieldsteel user 15 Aug'11 00:32

http://www.youtube.com/watch?v=pFLj7yJzp60

J. Simon van der Walt user 27 Aug'13 22:16

Interesting, thanks. For the sake of anyone else happening by here, in SC 3.6 'drawHook' appears to be deprecated, replace with 'drawFunc', and in line 78 the font size I think should be 32, not 42.

What key command were you hitting in the server window to get that popup which showed the synths being instantiated? And how do you do that in 3.6?

eli.fieldsteel user 04 Mar'15 00:46

s.plotTree;