-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example16.scd
110 lines (102 loc) · 2.75 KB
/
Example16.scd
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
//Example16 - amptrack
(
s.latency= 0.05;
s.waitForBoot{
c= Buffer.read(s, Platform.resourceDir+/+"sounds/a11wlk01.wav");
SynthDef(\avTrk, {|in, t_trig, time= 0.01, cutoff= 400, index= 0|
var z= In.ar(in, 1);
var val= Amplitude.kr(BPF.ar(BPF.ar(z, cutoff, 0.1, 5), cutoff, 0.1, 5), time, time);
SendTrig.kr(t_trig, index, val);
}).send(s);
SynthDef(\avSnd, {|out= 0, bufnum|
var z= PlayBuf.ar(
1,
bufnum,
BufRateScale.ir(bufnum)*LFPulse.kr(0.05, 0, 0.5, 0.2, -1.5),
Impulse.kr(LFPulse.kr(0.1, 0, 0.1, 2, 1)),
BufFrames.ir(bufnum)*LFNoise0.kr(0.2, 0.5, 0.5).round(0.2),
1
);
Out.ar(out, Pan2.ar(z));
}).send(s);
};
)
(
//--window setup
var width= 500, height= 500;
var w= Window("Example16 - amptrack", Rect(99, 99, width, height), false);
var u= UserView(w, Rect(0, 0, width, height));
//--variables
var num= 100; //number of tuned filter synths
var cnt= 0; //vertical drawing position
var amps= 0.dup(num); //array of current amplitudes
var o= OSCresponder(s.addr, '/tr', {|t, r, m| amps= amps.put(m[2], m[3])}).add;
var syns= {|i| //each tracker with an unique peakfilter
Synth(\avTrk, [\in, 0, \index, i, \cutoff, i.linexp(0, num-1, 200, 6000)]);
}.dup(num);
var snd= Synth(\avSnd, [\out, 0, \bufnum, c]); //something that generates sound
//--interface
~width= 120;
~speed= 1;
~version= 1;
//--main loop
u.drawFunc= {
var wn= width/num;
switch(~version,
0, {
Pen.translate(wn*0.5, cnt%height);
amps.do{|amp, i|
Pen.fillColor= Color.grey((amp).clip(0, 1));
Pen.fillRect(Rect.aboutPoint(Point(wn*i, 0), wn*0.5, ~width));
};
cnt= cnt+~speed;
},
1, {
amps.do{|amp, i|
Pen.rotate(cnt, width*0.5, height*0.5);
Pen.strokeColor= Color.grey(amp.clip(0, 1));
Pen.strokeRect(Rect.aboutPoint(Point(wn*i, 0), ~width*0.1, ~width));
cnt= cnt+(~speed*0.000001);
};
},
2, {
Pen.rotate(cnt, width*0.5, height*0.5);
Pen.translate(width*0.5, height*0.5);
amps.do{|amp, i|
Pen.strokeColor= Color.grey(amp.clip(0, 1));
Pen.strokeOval(Rect.aboutPoint(Point(i*~speed, 0), ~width*0.5, ~width*0.5));
};
cnt= cnt+(~speed*0.01);
}
);
syns.do{|x| x.set(\t_trig, 1)}; //request amp data
};
//--window management
u.clearOnRefresh= false; //do not erase - just draw on top of
w.onClose= {
snd.free;
syns.do{|x| x.free};
o.remove;
};
w.front;
u.animate= true;
CmdPeriod.doOnce({if(w.isClosed.not, {w.close})});
)
//change these while the program is running
~width= 220;
~speed= 2;
~speed= -0.1;
~speed= pi;
~version= 0;
~width= 1;
~speed= 1;
~width= 10;
~speed= 10;
~width= 500;
~version= 2;
~width= 100;
~speed= 1;
~speed= -1.5;
~width= 20;
//close the window to stop or press cmd+.
c.free; //free the soundfile buffer