-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathQSetup.py
279 lines (225 loc) · 8.73 KB
/
QSetup.py
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# thanks to https://www.untergeek.de/de/2014/11/taming-arturias-beatstep-sysex-codes-for-programming-via-ipad/#Sysex_for_the_Pads
# for unravelling sysx messages for BeatStep
class QSetup(object):
"""
##### BUTTON
set_B_......... (ID, val)
ID: the button number (1-16), or one of ('play', 'stop', 'cntrl', 'sync', 'recall', 'store', 'shift', 'chan')
mode: set button mode
(0=off, 1=silent, 2=silent cc switch, 7=mmc, 8=cc, 9=note)
channel: set midi channel
(0-15) (65 to follow the global channel)
cc: set midi CC
(0-127)
off: set midi off value
(0-127)
on: set midi on value
(0-127)
behaviour: set button behaviour
(0=toggle, 1=gate)
color: set button LED color [only works if button is set to note]
(0=black, 1=red, 16=blue, 17=magenta)
set_B_velocity(value): set button velocity curve (global)
(0=linear, 1=logarithmic, 2=exponential, 3=full)
##### ENCODER
set_E_......... (ID, val)
ID: the encoder number (1-16)
mode: set encoder mode
(0=off, 1=Midi cc, 4=RPN/NRPN)
channel: set midi channel
(0-15) (65 to follow the global channel)
cc: set midi CC
(0-127)
off: set lowest possible value [only if encoder is set to absolute]
(0-127)
on: set highest possible value [only if encoder is set to absolute]
(0-127)
behaviour set encoder behaviour
(0=absolute, 1-3=relative mode 1-3)
set_E_acceleration(value): set encoder acceleration (global)
(0=slow, 1=medium, 2=fast)
##### SEQUENCER
set_S_...(val)
mode: set the mode
(0=forward, 1=reverse, 2=alternating, 3=random)
channel: set midi channel
(0-15)
rate: set rate (e.g. speed)
(0-4)
transpose: base note is C5=60, to transpose down 12 semitones to C4, nn=48 and so on
(0-127)
scale: set the scale
(0=chromatic, 1=major, 2=minor, 3=dorian, 4=mixolydian, 5=harmonic minor, 6=blues, 7=user)
stepsize: set the step-size
(0=1/4, 1=1/8, 2=1/16, 3=1/32)
length: set pattern-length to 1-16 steps
(0-15)
swing: set swing
(50=no swing, 75=maximal swing)
gate: set gate (0-99%)
(0-99)
legato: set legato
(0=off, 1=on, 2=reset)
set_S_on(ID): turn on step
(0-15)
set_S_off(ID): turn off step
(0-15)
set_S_note(ID, val): set note (val) for step (ID)
(0-15), (1-127)
#### GLOBAL
set_global_channel(c): set the global midi-channel
(0-15)
"""
def __init__(self):
# a dict with the button IDS
self._B = dict(
play=88, # white
stop=89, # no light
cntrl=90, # red or blue
sync=91, # blue
recall=92, # blue
store=93, # red
shift=94, # blue
chan=95, # blue
)
# a dict with the encoder IDS
self._E = dict(transpose=48)
for i in range(1, 17):
self._B[i] = 111 + i
self._E[i] = 31 + i
self._funcdict = dict(
mode=1, channel=2, cc=3, off=4, on=5, behaviour=6, color=16
)
self._S_funcdict = dict(
channel=1,
transpose=2,
scale=3,
mode=4,
stepsize=5,
length=6,
swing=7,
gate=8,
legato=9,
)
self._B_START_MSG = (
240,
0,
32,
107,
127,
66,
2,
0,
) # F0 00 20 6B 7F 42 02 00 c ID val F7
self._B_REQUEST_MSG = (
240,
0,
32,
107,
127,
66,
1,
0,
) # F0 00 20 6B 7F 42 01 00 c ID F7
# set button and encoder getters and setters
for key, c in self._funcdict.items():
funcs = self._get_callbacks(c)
setattr(self, "set_B_" + key, funcs[0])
setattr(self, "get_B_" + key, funcs[1])
setattr(self, "set_E_" + key, funcs[2])
setattr(self, "get_E_" + key, funcs[3])
E_acc_set, E_acc_get = self._get_acceleration_callback()
setattr(self, "set_E_acceleration", E_acc_set)
setattr(self, "get_E_acceleration", E_acc_get)
B_velocity_set, B_velocity_get = self._get_velocity_callback()
setattr(self, "set_B_velocity", B_velocity_set)
setattr(self, "get_B_velocity", B_velocity_get)
# set sequencer setters
for key, c in self._S_funcdict.items():
funcs = self._get_S_callbacks(c)
setattr(self, "set_S_" + key, funcs[0])
setattr(self, "get_S_" + key, funcs[1])
S_note_set, S_note_get = self._get_S_note_callback()
setattr(self, "set_S_note", S_note_set)
setattr(self, "get_S_note", S_note_get)
setattr(self, "set_S_on", self._get_S_toggle_callback(127))
setattr(self, "set_S_off", self._get_S_toggle_callback(0))
setattr(self, "get_S_onoff", self._get_S_toggle_get_callback())
def recall_preset(self, slot):
return (240, 0, 32, 107, 127, 66, 5, slot, 247)
def store_preset(self, slot):
return (240, 0, 32, 107, 127, 66, 6, slot, 247)
def set_global_channel(self, val):
return self._send_change(64, 6, val)
def get_global_channel(self):
return self._send_request(64, 6)
def _send_change(self, c, ID, val):
return self._B_START_MSG + (c, ID, val, 247)
def _send_request(self, c, ID):
return self._B_REQUEST_MSG + (c, ID, 247)
def _get_callbacks(self, c):
# do this to ensure function-name closure!
def changeB(ID, val):
return self._send_change(c, self._B[ID], val)
def requestB(ID):
return self._send_request(c, self._B[ID])
def changeE(ID, val):
return self._send_change(c, self._E[ID], val)
def requestE(ID):
return self._send_request(c, self._E[ID])
return changeB, requestB, changeE, requestE
def _get_velocity_callback(self):
def set_callback(val):
return self._send_change(65, 3, val)
def get_callback():
return self._send_request(65, 3)
return set_callback, get_callback
def _get_acceleration_callback(self):
def set_callback(val):
return self._send_change(65, 4, val)
def get_callback():
return self._send_request(65, 4)
return set_callback, get_callback
def _get_S_callbacks(self, c):
def set_callback(val):
return self._send_change(80, c, val)
def get_callback():
return self._send_request(80, c)
return set_callback, get_callback
def _get_S_note_callback(self):
def set_callback(ID, val):
return self._send_change(82, ID, val)
def get_callback(ID):
return self._send_request(82, ID)
return set_callback, get_callback
def _get_S_toggle_callback(self, val):
def set_callback(ID):
return self._send_change(83, ID, val)
return set_callback
def _get_S_toggle_get_callback(self):
def get_callback(ID):
return self._send_request(83, ID)
return get_callback
def decode(self, b):
whatQ, control, val = None, None, None
if not b[:8] == self._B_START_MSG:
pass
else:
Q, ID, value = b[8:11]
for key, val in self._B.items():
if val == ID:
control = "button_" + str(key)
break
else:
continue
if control is None:
for key, val in self._E.items():
if val == ID:
control = "encoder_" + str(key)
break
else:
continue
for key, val in self._funcdict.items():
if val == Q:
whatQ = key
return whatQ, control, value