-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArcRotaryTraktor.sc
173 lines (130 loc) · 5.63 KB
/
ArcRotaryTraktor.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
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
166
167
168
169
170
171
172
173
/*
ArcEncoder Rotary Traktor Style
https://github.com/nthhisst
*/
ArcRotaryTraktor : ArcRotary {
*new { | your_arc, sensitivity_level |
^ super.new(your_arc, sensitivity_level).initArcRotaryTraktor;
}
initArcRotaryTraktor {
for(0, 3,{ arg knob_n;
arc_map[knob_n] = [
2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 ];
});
for(0, 3, { arg knob_n;
current_led[knob_n] = 0;
arc.ringmap(knob_n, arc_map[knob_n]);
});
}
spin { | knob_n, delta |
// ---------------------------------------- 0 -> 32
if ((current_led[knob_n] <= 32) and:
(current_led[knob_n].isStrictlyPositive) and:
(delta.isStrictlyPositive))
{
gathered_delta[knob_n] = gathered_delta[knob_n] + delta;
while { (gathered_delta[knob_n] >= sensitivity[knob_n]) and: (current_led[knob_n] < 33) }
{
// sets the current_led value
arc_map[knob_n][current_led @ knob_n] = current_led[knob_n].linlin(0, 32, 2, 15).asInteger;
// moves current position up by 1
current_led[knob_n] = current_led[knob_n] + 1;
// collect gathered delta
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
};
arc.ringmap(knob_n, arc_map[knob_n]);
if ( current_led[knob_n] >= 32 )
{
current_led[knob_n] = 32;
gathered_delta[knob_n] = 0;
arc_map[knob_n] = [
2, 2, 2, 3, 3, 4, 4, 4,
5, 5, 6, 6, 6, 7, 7, 8,
8, 8, 9, 9, 10, 10, 10, 11,
11, 12, 12, 12, 13, 13, 14, 14,
15, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0];
^ current_led[knob_n].linlin(-32, 32, 0, 64);
};
};
if ((current_led[knob_n] <= 32) and:
(current_led[knob_n].isStrictlyPositive) and:
(delta.isNegative))
{
gathered_delta[knob_n] = gathered_delta[knob_n] + delta.abs;
while { gathered_delta[knob_n] >= sensitivity[knob_n] and: current_led[knob_n].isStrictlyPositive }
{
arc_map[knob_n][current_led @ knob_n] = 0;
current_led[knob_n] = current_led[knob_n] - 1;
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
};
arc.ringmap(knob_n, arc_map[knob_n]);
};
// ---------------------------------------- 0 -> 32
// ---------------------------------------- 0 -> -32
if ((current_led[knob_n] <= 0) and:
(current_led[knob_n] >= -32) and:
(delta.isNegative))
{
gathered_delta[knob_n] = gathered_delta[knob_n] + delta.abs;
while { (gathered_delta[knob_n] >= sensitivity[knob_n]) and: (current_led[knob_n] > -31) }
{
// adjust negative led position as arc protocol is 0-63
arc_map[knob_n][(current_led[knob_n]).abs.linlin(0, 32, 63, 32).asInteger]
= current_led[knob_n].abs.linlin(0, 32, 2, 15).asInteger;
current_led[knob_n] = current_led[knob_n] - 1;
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
};
arc.ringmap(knob_n, arc_map[knob_n]);
if( current_led[knob_n] <= -31 )
{
current_led[knob_n] = -32;
gathered_delta[knob_n] = 0;
arc_map[knob_n] = [
2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
15, 14, 13, 13, 12, 12, 12, 11,
11, 10, 10, 10, 9, 9, 8, 8,
8, 7, 7, 6, 6, 6, 5, 5,
4, 4, 4, 3, 3, 2, 2, 2 ];
^ current_led[knob_n].linlin(-32, 32, 0, 64);
};
};
if ((current_led[knob_n] <= 0) and:
(current_led[knob_n] >= -32) and:
(delta.isPositive))
{
gathered_delta[knob_n] = gathered_delta[knob_n] + delta.abs;
while { gathered_delta[knob_n] >= sensitivity[knob_n] }
{
if (current_led[knob_n] <= 0)
{
arc_map[knob_n][(current_led[knob_n]).abs.linlin(0, 32, 63, 32).asInteger] = 0;
current_led[knob_n] = current_led[knob_n] + 1;
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
} {
// sets the current_led value
arc_map[knob_n][current_led @ knob_n] = current_led[knob_n].linlin(0, 32, 2, 15).asInteger;
// moves current position up by 1
current_led[knob_n] = current_led[knob_n] + 1;
// collect gathered delta
gathered_delta[knob_n] = gathered_delta[knob_n] - sensitivity[knob_n];
}
};
arc.ringmap(knob_n, arc_map[knob_n]);
};
// ---------------------------------------- 0 -> -32
^ current_led[knob_n].linlin(-32, 32, 0, 64);
}
}