«Scanned Synthesis Visualisation» by Matthew Kane

on 25 Feb'14 17:39 in scanned synthesisvisualization

Visualization of scanned string synthesis.

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
~numsprings = 41;
(
SynthDef(\scansynth41, { arg amp=0.1, gate=1, pan=0, freq=440, spring, damp;
    var in, ou;
    var springs;
    var sel;
	var env;
	in = LPF.ar(LocalIn.ar(1), XLine.ar(1,10,0.3)) * 0.97 + (LPF.ar(Trig.ar(gate, 0.01),200) * WhiteNoise.ar.range(0.98,1));
	spring = spring.dup(~numsprings);
	damp = damp.dup(~numsprings);
    ou = in;
    springs = spring.collect { arg spr, i;
        ou = Spring.ar(ou, spr, damp[i]);
    };
    LocalOut.ar(ou);
	sel = VarSaw.ar(freq * [0.999,1,0.499,2,1.01] * 0.5, width: LFNoise2.ar(1/2).range(0.2,0.5)).range(0, spring.size-1);
	SendReply.ar(Impulse.ar(30), cmdName: '/sel', values: sel);
	SendReply.ar(Impulse.ar(30), cmdName: '/springs', values: springs);
	ou = Splay.ar(SelectX.ar(sel, springs), 1);
	env = EnvGen.ar(Env.adsr(0.3,0.1,0.8,0.1, peakLevel:1),gate:gate,doneAction:2);
	ou = Pan2.ar(ou, pan, amp);
	// ou.poll(label:"out");
	Out.ar(0, ou[0]);
	Out.ar(0, ou[1]);
}).load;
)

(
var window, view, redraw;

// OSC bridge from synth to language
if ( ~updateSelector != nil, {~updateSelector.free});
if ( ~updateSprings != nil, {~updateSprings.free});
o = OSCFunc({|msg, time, addr, recvPort|
	~sel = msg[3..];
}, '/sel');
n = OSCFunc({|msg, time, addr, recvPort|
	// ~springs = msg[3..];
	msg[3..].do { |item, i|
		~springs[i] = item;
	}
	// ~springs.postln;
}, '/springs');
~springs=Array.fill(~numsprings, 0);
~sel = Array.fill(5, 0);

// simulation window drawing
if (~max == nil) { ~max = 0.001; "max".postln; };
window = Window.new(bounds:Rect(0,0,800,600),server:s);
window.front;
CmdPeriod.doOnce({window.close});
view = UserView(window, window.bounds);
view.background = Color.white;
view.resize = 5;
view.drawFunc = {
	|view|
	var jumpwidth = view.bounds.width / (~numsprings-1);
	Pen.fillColor = Color.black;
	Pen.strokeColor = Color.black;
	~springs.do({
		|spring, i|
		var height = (spring/~max*view.bounds.height/2) + (view.bounds.height/2);
		var circlesize = (view.bounds.height.pow(2) + view.bounds.width.pow(2)).sqrt / 50;

		if (spring.abs > ~max, {
			~max = spring.abs;
			"maxspring"+~max.postln;
		});

		if (i == 0, {Pen.moveTo(Point(0, height))},
		{Pen.lineTo(Point(i*jumpwidth, height))});
		Pen.addOval(Rect(i*jumpwidth-(circlesize/2), height-(circlesize/2), circlesize, circlesize));
	});
	Pen.fillStroke;
	Pen.color = Color.red;
	~sel.do({
		|sel, i|
		Pen.moveTo(Point(sel*jumpwidth, view.bounds.height));
		Pen.lineTo(Point(sel*jumpwidth, 0));
	});
	Pen.fillStroke;
};
view.frameRate = 30;
view.animate = true;
~charmap = Dictionary.new(17);
~charmap.put($a, 45); // C
~charmap.put($w, 46); // C#
~charmap.put($s, 47); // D
~charmap.put($e, 48); // D#
~charmap.put($d, 49); // E
~charmap.put($f, 50); // F
~charmap.put($t, 51); // F#
~charmap.put($g, 52); // G
~charmap.put($y, 53); // G#
~charmap.put($h, 54); // A
~charmap.put($u, 55); // Bb
~charmap.put($j, 56); // B
~charmap.put($k, 57); // C
~charmap.put($o, 58); // C#
~charmap.put($l, 59); // D
~charmap.put($p, 60); // D#
~charmap.put($;, 61); // E

view.keyDownAction = {
	|view, char|
	//	("keydown" + char).postln;

	~lastchar = char;
	if (~charmap.at(char) != nil, {
		("kd freeing" + ~syn).postln;
		~syn.release(0.02);
		~max = 0.001;
		~syn = Synth(\scansynth41, [\freq, ~charmap.at(char).midicps, \spring, ~spring, \damp, ~damp, \pan, ~pan], s);
		("kd creating" + ~syn).postln;
	});
};
)

( // control window
var window, dampknob, damptext, springknob, springtext, resetbutton, panknob, pantext, newbounds;
window = Window.new(server:s);
damptext = StaticText.new();
damptext.string = "damping\n";
dampknob = Knob.new(window);
dampknob.mode = \vert;
dampknob.action = {
	|knob|
	var value = 100.pow(knob.value)*0.01;
	damptext.string_("damping\n"++value);
	value.postln;
	~damp = value;
	~syn.set(\damp, value);
};
springtext = StaticText.new();
springtext.string = "spring\n";
springknob = Knob.new(window);
springknob.mode = \vert;
springknob.action = {
	|knob|
	var value = 12.pow(knob.value)*0.01;
	springtext.string_("spring\n"++value);
	value.postln;
	~spring = value;
	~syn.set(\spring, value);
};
pantext = StaticText.new();
pantext.string = "pan\n";
panknob = Knob.new(window);
panknob.mode = \vert;
panknob.action = {
	|knob|
	var value = knob.value * 2 - 1;
	pantext.string_("pan\n"++value);
	value.postln;
	~pan = value;
	~syn.set(\pan, value);
};
springknob.valueAction_(0.5);
dampknob.valueAction_(0.5);
panknob.valueAction_(0.5);
resetbutton = Button(window).states_([['Reset', Color.black]]).action_({ ("resetting max to 0, was" + ~max).postln; ~max = 0;});
window.layout = VLayout(HLayout(springknob, springtext), HLayout(dampknob, damptext), HLayout(panknob, pantext), resetbutton);
window.bounds = Rect(800,0,400,400);
window.front;
)
raw 4885 chars (focus & ctrl+a+c to copy)
comments