-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.scd
64 lines (50 loc) · 1.79 KB
/
Demo.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
/* Demo.scd
* Author: Marc J. Szalkiewicz
* Date: 2014 Jan 25
*/
(
var devID, t;
/* Set this before starting!
* You can get your deviceID from the Max/MSP serialosc.maxpat. */
devID = \m0001021;
t = Task({
var devices, grid, newKeyFx;
/* Let's listen for monome devices! */
devices = SerialOSCHandler.new;
/* Now I will get a direct reference to my grid. */
1.wait; grid = devices[devID];
/* Tilt can be turned on and off. */
1.wait; "Tilt on. ".postln; grid.tiltSet(0, 1);
2.wait; grid.tiltSet(0, 0); "Tilt off.".postln;
/* If you press keys here, nothing useful will happen. */
"Press some keys.".postln;
/* Let's handle the keys in a new way.
* You should never change the arguments to this function
* without modifying the MonomeGrid class. */
newKeyFx = { |x, y, s, self|
/* A simple LED toggler. */
/* You must always use the `self' variable to reference
* variables and functions in MonomeGrid and MonomeArc. */
/* One important variable is the self-explanatory `gridState' */
var nextState = (self.getGridState(x, y) == 0).asInt;
if(s != 0, {
/* Update the state like so. */
self.setGridState(x, y, nextState);
/* LED functions can be found in MonomeGrid.sc near the bottom.
* be sure to use `f.value(args)' notation with these handlers. */
self.ledHandler.value(x, y, nextState);
});
};
/* You can write a tilt or led handler in a similar fashion.
* You can call the functions from each other, as above. */
5.wait; grid.keyHandler = newKeyFx;
"Now, keys will stay lit. Try pressing a few keys.".postln;
/* Before reinstantiating a new SerialOSCHandler,
* or before terminating your program, close the
* current SerialOSCHandler. */
5.wait;
grid.ledAll(0); // This is a "bug." it should be handled by devices.close.
devices.close;
});
t.play;
)