File: make_xone.py

package info (click to toggle)
mixxx 1.11.0~dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 96,840 kB
  • ctags: 37,182
  • sloc: cpp: 210,326; xml: 167,911; ansic: 24,880; sh: 12,876; python: 9,407; makefile: 566; php: 57
file content (463 lines) | stat: -rwxr-xr-x 16,323 bytes parent folder | download
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
#!/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                : owilliams@mixxx.org
#############################################################################


import sys
import getopt

def help():
    print "usage: make_xone [args] outputfilename"
    print "optional args: "
    print "          --4decks     to generate a layout for 4 deck-enabled versions of mixxx"
    print "          --mastersync to generate alternative layout for master_sync testing"

if len(sys.argv) < 2:
    help()
    sys.exit(1)
    
MASTER_SYNC_LAYOUT = False
MAX_DECKS = 2
fname = ""

try:
    opts, args = getopt.getopt(sys.argv[1:], "",["mastersync","4decks"])
    for o, a in opts:
        if o == "--mastersync":
            # This is an alternative layout for my work on master sync
            MASTER_SYNC_LAYOUT = True
        elif o == "--4decks":
            MAX_DECKS = 4
    if len(args) > 0:
        fname = args[0]
except Exception, e:
    print str(e)
    help()
    sys.exit(1)

if fname == "":
    help()
    sys.exit(1)

try:
    fh = open(fname, "w")
except Exception, 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:
            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! ###########
##################################################

cc_mapping = {#'spinknob':['StantonSCS1m.encoderJog1','<Script-Binding/>'], (script stuff is custom, below)
              '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 MASTER_SYNC_LAYOUT:
    button_mapping = {'spinknob':['beatsync','<button/>'], 
           'knoblight1':['pfl','<button/>'], 'knoblight2':['quantize','<normal/>'], 'knoblight3':['filterLowKill','<normal/>'], 
           'button1':{'red':['sync_master','<button/>'], 'orange':['beatloop_4','<button/>'],  'green':['hotcue_1_activate','<button/>']}, 
           'button2':{'red':['sync_slave','<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','<normal/>'],        '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 MASTER_SYNC_LAYOUT:
    light_mapping = {#'spinknob':'jog', 
           'knoblight1':'pfl', 'knoblight2':'quantize', 'knoblight3':'filterLowKill', 
           'button1':{'red':'sync_master', 'orange':'beatloop_4',   'green':'hotcue_1_enabled'}, 
           'button2':{'red':'sync_slave',  '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
master_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 MASTER_SYNC_LAYOUT:
    master_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>sync_master</key>
                <status>0x9F</status>
                <midino>0x0D</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&amp;Heath Xone K2</name>
        <author>Owen Williams</author>
        <description>Set Xone:K2 latching mode to "Switching Matrix" -- mode 2.<br/> (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 in range(0,MAX_DECKS):
    xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>XoneK2.encoderJog%i</key>
                <status>0xBF</status>
                <midino>%s</midino>
                <options>
                    <Script-Binding/>
                </options>
            </control>""" % (i+1, i+1, midi_cc['spinknob'][i]))


########################################
########################################
########################################           
# ok back to boilerplate...

#cc controls (no latching needed)
for channel in range(0,MAX_DECKS):
    for cc in cc_mapping:
        xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0xBF</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, cc_mapping[cc][0], midi_cc[cc][channel], cc_mapping[cc][1]))

#Spin Knob buttons (no latching needed)
for channel in range(0,MAX_DECKS):
    xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x9F</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, button_mapping['spinknob'][0], midi['spinknob'][channel]['red'], button_mapping['spinknob'][1]))
    xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x8F</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, button_mapping['spinknob'][0], midi['spinknob'][channel]['red'], button_mapping['spinknob'][1]))            
            
xml.append("<!-- Upper Buttons -->")    
#knoblight buttons (no latching)
for channel in range(0,MAX_DECKS):
    for knob in ['knoblight%i' % i for i in range(1,4)]:
        xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x9F</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, button_mapping[knob][0], midi[knob][channel]['red'], button_mapping[knob][1]))
        xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x8F</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, button_mapping[knob][0], midi[knob][channel]['red'], button_mapping[knob][1]))
    
xml.append("<!-- Lower Button Grid -->") 
    
#buttons
for channel in range(0,MAX_DECKS):
    for latch in ['red','orange','green']:
        for button in ['button%i' % i for i in range(1,5)]:
        
            xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x9F</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, button_mapping[button][latch][0], midi[button][channel][latch], button_mapping[button][latch][1]))
            xml.append("""            <control>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x8F</status>
                <midino>%s</midino>
                <options>
                    %s
                </options>
            </control>""" % (channel+1, button_mapping[button][latch][0], midi[button][channel][latch], button_mapping[button][latch][1]))
    
xml.append("<!-- Special Case Knobs / buttons -->")    
# a couple custom entries:
xml.append(master_knobs)

    
############ done with controls    
    
xml.append("""        </controls>
        <outputs>""")
    
#ok now the lights
if 'spinknob' in light_mapping:
    for channel in range(0,MAX_DECKS):
        xml.append("""            <output>
                    <group>[Channel%i]</group>
                    <key>%s</key>
                    <status>0x9F</status>
                    <midino>%s</midino>
                    <minimum>0.5</minimum>
                </output>""" % (channel+1, mapping['spinknob'], midi['spinknob'][channel]['red']))
                
     
xml.append("<!-- Knob lights -->")       
#knoblight buttons (no latching)
for channel in range(0,MAX_DECKS):
    for knob in ['knoblight%i' % i for i in range(1,4)]:
        xml.append("""            <output>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x9F</status>
                <midino>%s</midino>
                <minimum>0.5</minimum>
            </output>""" % (channel+1, light_mapping[knob], midi[knob][channel]['red']))
    
xml.append("<!-- Button lights -->")
#buttons (latched)
for channel in range(0,MAX_DECKS):    
    for latch in ['red','orange','green']:    
        for button in ['button%i' % i for i in range(1,5)]:
            xml.append("""            <output>
                <group>[Channel%i]</group>
                <key>%s</key>
                <status>0x9F</status>
                <midino>%s</midino>
                <minimum>0.5</minimum>
            </output>""" % (channel+1, light_mapping[button][latch], midi[button][channel][latch]))    
    
xml.append("""        </outputs>
    </controller>
</MixxxControllerPreset>""")

fh.writelines("\n".join(xml))
fh.close()