-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArcEncoder.sc
84 lines (61 loc) · 2.12 KB
/
ArcEncoder.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
/*
ArcEncoder lights one led as per position.
Returns -1 if rotation is negative and 1 for positive
rotation.
https://github.com/nthhisst
*/
ArcEncoder {
var arc;
var arc_map;
var current_led;
var gathered_delta;
var <>sensitivity;
*new { | your_arc, sensitivity_level |
^ super.new.initArcKnob(your_arc, sensitivity_level);
}
initArcKnob { | your_arc, sensitivity_level |
arc = your_arc;
sensitivity = Array.fill(4, sensitivity_level);
current_led = Array.fill(4, 0);
gathered_delta = Array.fill(4, 0);
arc_map = [
Array.fill(64,0),
Array.fill(64, 0),
Array.fill(64, 0),
Array.fill(64, 0)
];
for(0, 3, { arg i; arc_map[i][0] = 15; });
}
spin { | knob_n, delta |
if(delta.isStrictlyPositive)
{
gathered_delta[knob_n] = gathered_delta[knob_n] + delta;
while { gathered_delta[knob_n] >= sensitivity[knob_n] }
{
arc_map[knob_n][current_led @ knob_n] = 0;
current_led[knob_n] = current_led[knob_n] + 1;
current_led[knob_n] = current_led[knob_n].wrap(0, 63);
arc_map[knob_n][current_led @ knob_n] = 15;
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
};
arc.ringmap(knob_n, arc_map[knob_n]);
^ 127;
}
{ // if it's negative
gathered_delta[knob_n] = gathered_delta[knob_n] + delta.abs;
while { gathered_delta[knob_n] >= sensitivity[knob_n] }
{
arc_map[knob_n][current_led @ knob_n] = 0;
current_led[knob_n] = current_led[knob_n] - 1;
current_led[knob_n] = current_led[knob_n].wrap(0, 63);
arc_map[knob_n][current_led @ knob_n] = 15;
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
};
arc.ringmap(knob_n, arc_map[knob_n]);
^ 1;
};
}
focusKnob { | knob_n |
arc.ringmap(knob_n, arc_map[knob_n]);
}
}