«A Simple Synthesizer Keyboard» by prko

on 14 Aug'22 03:47 in keyboard
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
(
s.waitForBoot{
	var w, n, b, bs, k, ks, x, lay, ctl, kAct;
	k = (\a:0, \w:1, \s:2, \e:3, \d:4, \f:5, \t:6, \g:7, \y:8, \h:9, \u:10, \j:11, \k:12, \o:13, \l:14,
		\p:15, ';':16);
	n = k.size;
	x = { |i|
		{ |g = 0|
			LFTri.ar((i + 69 + [0, 0.15]).midicps)
			* 0.1
			* Env.adsr.kr(gate:g);
		}.play
	}!n;
	ctl = { |i=0, gate=0|
		x[i].set(\g, gate)
	};
	w = Window("self ear-training", Rect(200, 200, 583, 136));
	w.front;
	w.onClose_{ { |i| x[i].free }!n };
	b = { |parent, label|
		Button(parent, 30@30)
		.states_([
			[label],
			[label, Color.white, Color.grey]
		])
		.mouseDownAction_{
			ctl.(label, 1);
			bs[label].value = 1
		}
		.action_{
			ctl.(label, 0);
			bs[label].value = 0
		}
	};
	lay = w.addFlowLayout;
	bs = { |i| b.(w, i) }!n;
	lay.nextLine;
	ks = { |i|
		StaticText(w, 30@30)
		.string_(k.findKeyForValue(i))
		.align_(\center)
	}!n;
	kAct = { |c, v|
		c = c.asSymbol;
		(k.trueAt(c) != false).if{
			ctl.(k[c], v);
			bs[k[c]].value = v
		}
	};
	StaticText(w, 572@60).string_("Press, hold and then release the keys under the numbered buttons using"
		+ "your computer keyboard. Alternatively, you might press, hold, and then release each button using"
		+ "the left button of the computer mouse. The multi-touch on touchscreen may function, but it"
		+ "hasn't been tested.");
	w.view
	.keyDownAction_{ |view, char|
		kAct.(char, 1)
	}
	.keyUpAction_{ |view, char, mod, unicode, keycode, key|
		kAct.(char, 0)
	}
}
)
raw 1506 chars (focus & ctrl+a+c to copy)
reception
comments