forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_xone.py
executable file
·665 lines (585 loc) · 18.6 KB
/
make_xone.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
#!/usr/bin/python
#############################################################################
# make_xone.py - Ugly script which automatically
# creates a midi mapping for the Xone K2.
# Lots of this is boilerplate...
# -------------------
# begin : Fri Aug 31 18:45:00 EDT 2012
# copyright : (C) 2012 Owen Williams
# email : [email protected]
#############################################################################
import sys
import getopt
def help():
print("usage: make_xone [args] outputfilename")
print("optional args: ")
print(" --4decks ", end="")
print("to generate a layout for 4 deck-enabled versions of mixxx")
print(" --sync-lock ", end="")
print("to generate alternative layout for sync_lock testing")
if len(sys.argv) < 2:
help()
sys.exit(1)
SYNC_LOCK_LAYOUT = False
MAX_DECKS = 2
fname = ""
DECK_ORDER = range(0, 2)
try:
opts, args = getopt.getopt(sys.argv[1:], "", ["sync-lock", "4decks"])
for o, a in opts:
if o == "--sync-lock":
# This is an alternative layout for my work on sync lock
SYNC_LOCK_LAYOUT = True
elif o == "--4decks":
MAX_DECKS = 4
DECK_ORDER = (2, 0, 1, 3)
if len(args) > 0:
fname = args[0]
except Exception as e:
print(str(e))
help()
sys.exit(1)
if fname == "":
help()
sys.exit(1)
try:
fh = open(fname, "w")
except Exception as e:
print("Error opening file for write:", str(e))
sys.exit(1)
button_definitions = """0x34 0x35 0x36 0x37
0x58 0x59 0x5A 0x5B
0x7C 0x7d 0x7e 0x7f
0x30 0x31 0x32 0x33
0x54 0x55 0x56 0x57
0x78 0x79 0x7A 0x7b
0x2c 0x2d 0x2e 0x2f
0x50 0x51 0x52 0x53
0x74 0x75 0x76 0x77
0x28 0x29 0x2a 0x2b
0x4c 0x4d 0x4e 0x4f
0x70 0x71 0x72 0x73
0x24 0x25 0x26 0x27
0x48 0x49 0x4a 0x4b
0x6c 0x6d 0x6e 0x6f
0x20 0x21 0x22 0x23
0x44 0x45 0x46 0x47
0x68 0x69 0x6a 0x6b
0x1c 0x1d 0x1e 0x1f
0x40 0x41 0x42 0x43
0x64 0x65 0x66 0x67
0x18 0x19 0x1A 0x1b
0x3c 0x3d 0x3e 0x3f
0x60 0x61 0x62 0x63"""
controls = [
"spinknob",
"knoblight1",
"knoblight2",
"knoblight3",
"button1",
"button2",
"button3",
"button4",
]
controls.reverse()
colors = ["red", "orange", "green"]
cur_color = 0
# {'spinknob': [{'red':1,'orange':2,'green':3},
# {'red':4,'orange':5,'green':6}, ...
midi = {}
current_control = controls.pop()
for line in button_definitions.split("\n"):
if len(line.strip()) == 0:
continue
hexlist = line.split()
if current_control not in midi:
midi[current_control] = [{}, {}, {}, {}]
for i, h in enumerate(hexlist):
midi[current_control][i][colors[cur_color]] = h
cur_color = (cur_color + 1) % len(colors)
if cur_color == 0:
try:
current_control = controls.pop()
except Exception:
break
# ok now we have a mapping between control and hex key
# now we need midi CC's -- these just increment simply
cc_controls = ["spinknob", "eq1", "eq2", "eq3", "slider"]
cc_code = 0
midi_cc = {}
for cc in cc_controls:
midi_cc[cc] = []
for i in range(0, 4):
midi_cc[cc].append("0x%x" % cc_code)
cc_code += 1
# now we need a mapping of control and controlobject
# controls = ['spinknob', 'knoblight1', 'knoblight2', 'knoblight3', 'button1',
# 'button2', 'button3', 'button4']
##################################################
# Actual stuff you can edit! #
##################################################
# Note that EQ control objects are munged in code to produce the correct
# control objects as of Mixxx 2.0.
cc_mapping = {
"spinknob": ["XoneK2.encoderJog", "<Script-Binding/>"],
"eq1": ["filterHigh", "<normal/>"],
"eq2": ["filterMid", "<normal/>"],
"eq3": ["filterLow", "<normal/>"],
"slider": ["volume", "<normal/>"],
}
button_mapping = {
"spinknob": ["beatsync", "<button/>"],
"knoblight1": ["filterHighKill", "<normal/>"],
"knoblight2": ["filterMidKill", "<normal/>"],
"knoblight3": ["filterLowKill", "<normal/>"],
"button1": {
"red": ["pfl", "<normal/>"],
"orange": ["beatloop_4", "<button/>"],
"green": ["hotcue_1_activate", "<button/>"],
},
"button2": {
"red": ["keylock", "<normal/>"],
"orange": ["loop_double", "<button/>"],
"green": ["hotcue_2_activate", "<button/>"],
},
"button3": {
"red": ["cue_default", "<button/>"],
"orange": ["loop_halve", "<button/>"],
"green": ["hotcue_3_activate", "<button/>"],
},
"button4": {
"red": ["play", "<normal/>"],
"orange": ["reloop_exit", "<button/>"],
"green": ["hotcue_4_activate", "<button/>"],
},
}
if SYNC_LOCK_LAYOUT:
button_mapping = {
"spinknob": ["XoneK2.encoderButton", "<Script-Binding/>"],
"knoblight1": ["keylock", "<button/>"],
"knoblight2": ["quantize", "<normal/>"],
"knoblight3": ["filterLowKill", "<normal/>"],
"button1": {
"red": ["pfl", "<button/>"],
"orange": ["beatloop_4", "<button/>"],
"green": ["hotcue_1_activate", "<button/>"],
},
"button2": {
"red": ["sync_enabled", "<button/>"],
"orange": ["loop_double", "<button/>"],
"green": ["hotcue_2_activate", "<button/>"],
},
"button3": {
"red": ["cue_default", "<button/>"],
"orange": ["loop_halve", "<button/>"],
"green": ["hotcue_3_activate", "<button/>"],
},
"button4": {
"red": ["play", "<button/>"],
"orange": ["reloop_exit", "<button/>"],
"green": ["hotcue_4_activate", "<button/>"],
},
}
light_mapping = { # 'spinknob':'jog',
"knoblight1": "filterHighKill",
"knoblight2": "filterMidKill",
"knoblight3": "filterLowKill",
"button1": {
"red": "pfl",
"orange": "beatloop_4",
"green": "hotcue_1_enabled",
},
"button2": {
"red": "keylock",
"orange": "loop_double",
"green": "hotcue_2_enabled",
},
"button3": {
"red": "cue_default",
"orange": "loop_halve",
"green": "hotcue_3_enabled",
},
"button4": {
"red": "play",
"orange": "loop_enabled",
"green": "hotcue_4_enabled",
},
}
if SYNC_LOCK_LAYOUT:
light_mapping = { # 'spinknob':'jog',
"knoblight1": "keylock",
"knoblight2": "quantize",
"knoblight3": "filterLowKill",
"button1": {
"red": "pfl",
"orange": "beatloop_4",
"green": "hotcue_1_enabled",
},
"button2": {
"red": "sync_enabled",
"orange": "loop_double",
"green": "hotcue_2_enabled",
},
"button3": {
"red": "cue_default",
"orange": "loop_halve",
"green": "hotcue_3_enabled",
},
"button4": {
"red": "play",
"orange": "loop_enabled",
"green": "hotcue_4_enabled",
},
}
# these aren't worth automating
main_knobs = """ <control>
<group>[Playlist]</group>
<key>XoneK2.rightBottomKnob</key>
<status>0xBF</status>
<midino>0x15</midino>
<options>
<Script-Binding/>
</options>
</control>
<control>
<group>[Playlist]</group>
<key>LoadSelectedIntoFirstStopped</key>
<status>0x9F</status>
<midino>0x0E</midino>
<options>
<normal/>
</options>
</control>
<control>
<group>[Master]</group>
<key>XoneK2.leftBottomKnob</key>
<status>0xBF</status>
<midino>0x14</midino>
<options>
<Script-Binding/>
</options>
</control>
<control>
<group>[Master]</group>
<key>XoneK2.shift_on</key>
<status>0x9F</status>
<midino>0xF</midino>
<options>
<Script-Binding/>
</options>
</control>
<control>
<group>[Master]</group>
<key>XoneK2.shift_on</key>
<status>0x8F</status>
<midino>0xF</midino>
<options>
<Script-Binding/>
</options>
</control>"""
if SYNC_LOCK_LAYOUT:
main_knobs = """ <control>
<group>[Playlist]</group>
<key>XoneK2.rightBottomKnob</key>
<status>0xBF</status>
<midino>0x15</midino>
<options>
<Script-Binding/>
</options>
</control>
<control>
<group>[Playlist]</group>
<key>LoadSelectedIntoFirstStopped</key>
<status>0x9F</status>
<midino>0x0E</midino>
<options>
<normal/>
</options>
</control>
<control>
<group>[Master]</group>
<key>XoneK2.leftBottomKnob</key>
<status>0xBF</status>
<midino>0x14</midino>
<options>
<Script-Binding/>
</options>
</control>
<control>
<group>[Master]</group>
<key>XoneK2.shift_on</key>
<status>0x9F</status>
<midino>0xF</midino>
<options>
<Script-Binding/>
</options>
</control>
<control>
<group>[Master]</group>
<key>XoneK2.shift_on</key>
<status>0x8F</status>
<midino>0xF</midino>
<options>
<Script-Binding/>
</options>
</control>"""
xml = []
xml.append(
"""<?xml version='1.0' encoding='utf-8'?>
<!-- This file automatically generated by make_xone.py. -->
<MixxxControllerPreset mixxxVersion="" schemaVersion="1">
<info>
<name>Allen&Heath Xone K2</name>
<author>Owen Williams</author>
<description>For this mapping to work:
- Set Xone:K2 midi channel to 16;
- Set Xone:K2 Latching Layers state to "Switch Matrix" (state 2).
(See product manual for details.)</description>
</info>
<controller id="XONE:K2">
<scriptfiles>
<file filename="Xone-K2-scripts.js" functionprefix="XoneK2"/>
</scriptfiles>
<controls>"""
)
xml.append("<!-- CC Controls (knobs and sliders) -->")
# for i, deck in enumerate(DECK_ORDER):
# xml.append(""" <control>
# <group>[Channel%i]</group>
# <key>XoneK2.encoderJog%i</key>
# <status>0xBF</status>
# <midino>%s</midino>
# <options>
# <Script-Binding/>
# </options>
# </control>""" % (deck+1, deck+1, midi_cc['spinknob'][i]))
########################################
########################################
########################################
# ok back to boilerplate...
def get_group_name(channel, key):
"""Optionally munge group name if an EQ"""
if "filter" in key:
return "[EqualizerRack1_[Channel%d]_Effect1]" % channel
return "[Channel%d]" % channel
def get_key_name(key):
"""Optionally munge key name if an EQ"""
if key == "filterLow":
return "parameter1"
if key == "filterMid":
return "parameter2"
if key == "filterHigh":
return "parameter3"
if key == "filterLowKill":
return "button_parameter1"
if key == "filterMidKill":
return "button_parameter2"
if key == "filterLowKill":
return "button_parameter3"
return key
# cc controls (no latching needed)
for i, channel in enumerate(DECK_ORDER):
for cc in cc_mapping:
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0xBF</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(channel + 1, cc_mapping[cc][0]),
get_key_name(cc_mapping[cc][0]),
midi_cc[cc][i],
cc_mapping[cc][1],
)
)
# Spin Knob buttons (no latching needed)
for i, channel in enumerate(DECK_ORDER):
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0x9F</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(channel + 1, button_mapping["spinknob"][0]),
get_key_name(button_mapping["spinknob"][0]),
midi["spinknob"][i]["red"],
button_mapping["spinknob"][1],
)
)
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0x8F</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(channel + 1, button_mapping["spinknob"][0]),
get_key_name(button_mapping["spinknob"][0]),
midi["spinknob"][i]["red"],
button_mapping["spinknob"][1],
)
)
xml.append("<!-- Upper Buttons -->")
# knoblight buttons (no latching)
for j, channel in enumerate(DECK_ORDER):
for knob in ["knoblight%i" % i for i in range(1, 4)]:
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0x9F</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(channel + 1, button_mapping[knob][0]),
get_key_name(button_mapping[knob][0]),
midi[knob][j]["red"],
button_mapping[knob][1],
)
)
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0x8F</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(channel + 1, button_mapping[knob][0]),
get_key_name(button_mapping[knob][0]),
midi[knob][j]["red"],
button_mapping[knob][1],
)
)
xml.append("<!-- Lower Button Grid -->")
# buttons
for j, channel in enumerate(DECK_ORDER):
for latch in ["red", "orange", "green"]:
for button in ["button%i" % i for i in range(1, 5)]:
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0x9F</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(
channel + 1, button_mapping[button][latch][0]
),
get_key_name(button_mapping[button][latch][0]),
midi[button][j][latch],
button_mapping[button][latch][1],
)
)
xml.append(
""" <control>
<group>%s</group>
<key>%s</key>
<status>0x8F</status>
<midino>%s</midino>
<options>
%s
</options>
</control>"""
% (
get_group_name(
channel + 1, button_mapping[button][latch][0]
),
get_key_name(button_mapping[button][latch][0]),
midi[button][j][latch],
button_mapping[button][latch][1],
)
)
xml.append("<!-- Special Case Knobs / buttons -->")
# a couple custom entries:
xml.append(main_knobs)
# done with controls
xml.append(
""" </controls>
<outputs>"""
)
# ok now the lights
if "spinknob" in light_mapping:
for i, channel in enumerate(DECK_ORDER):
xml.append(
""" <output>
<group>%s</group>
<key>%s</key>
<status>0x9F</status>
<midino>%s</midino>
<minimum>0.5</minimum>
</output>"""
% (
get_group_name(channel + 1, light_mapping["spinknob"]),
get_key_name(light_mapping["spinknob"]),
midi["spinknob"][i]["red"],
)
)
xml.append("<!-- Knob lights -->")
# knoblight buttons (no latching)
for j, channel in enumerate(DECK_ORDER):
for knob in ["knoblight%i" % i for i in range(1, 4)]:
xml.append(
""" <output>
<group>%s</group>
<key>%s</key>
<status>0x9F</status>
<midino>%s</midino>
<minimum>0.5</minimum>
</output>"""
% (
get_group_name(channel + 1, light_mapping[knob]),
get_key_name(light_mapping[knob]),
midi[knob][j]["red"],
)
)
xml.append("<!-- Button lights -->")
# buttons (latched)
for j, channel in enumerate(DECK_ORDER):
for latch in ["red", "orange", "green"]:
for button in ["button%i" % i for i in range(1, 5)]:
xml.append(
""" <output>
<group>%s</group>
<key>%s</key>
<status>0x9F</status>
<midino>%s</midino>
<minimum>0.5</minimum>
</output>"""
% (
get_group_name(channel + 1, light_mapping[button][latch]),
get_key_name(light_mapping[button][latch]),
midi[button][j][latch],
)
)
xml.append(
""" </outputs>
</controller>
</MixxxControllerPreset>"""
)
fh.writelines("\n".join(xml))
fh.close()