-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGRMonome.sc
85 lines (73 loc) · 1.76 KB
/
GRMonome.sc
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
GRMonome : GRController {
classvar
<all
;
var
<>onGridRouted,
<>onGridUnrouted,
client,
name
;
*new { |numCols=16, numRows=8, name, view, origin, createTopViewIfNoneIsSupplied=true|
^super.new(numCols, numRows, view, origin, createTopViewIfNoneIsSupplied).initGRMonome(name);
}
*initClass {
all = [];
}
initGRMonome { |argName|
var gridSpec;
name = argName;
gridSpec = (numCols: numCols, numRows: numRows);
SerialOSCClient.new(name, gridSpec, \none) { |serialOSCClient|
serialOSCClient.gridRefreshAction = { this.refresh };
serialOSCClient.gridKeyAction = { |client, x, y, state|
if (this.containsPoint(x@y)) {
this.emitButtonEvent(Point.new(x, y), state.asBoolean);
} {
"%x% is outside of current bounds: %x%".format(x, y, numCols, numRows).warn;
};
};
serialOSCClient.onFree = { this.remove };
serialOSCClient.onGridRouted = { |client, grid|
client.refreshGrid;
onGridRouted.value(this, grid);
};
serialOSCClient.onGridUnrouted = { |client, grid| onGridUnrouted.value(this, grid); };
fork {
0.5.wait;
client = serialOSCClient;
client.refreshGrid;
}
};
all = all.add(this);
}
*newDetached { |numCols, numRows, name|
^this.new(numCols, numRows, name, nil, nil, false);
}
handleViewLedRefreshedEvent { |point, on|
client !? { |client|
client.ledSet(
point.x.asInteger,
point.y.asInteger,
if (on.asBoolean, 1, 0)
);
};
}
cleanup {
client !? { |client|
if (client.active) { client.free };
};
}
spawnGui {
^GRScreenGrid.new(numCols, numRows, view, origin)
}
grabDevices {
client !? _.grabDevices;
}
grabGrid {
client !? _.grabGrid;
}
asSerialOscClient {
^if (client.notNil) { client } { Error("No client instantiated").throw };
}
}