#!/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 ", end="") print("to generate a layout for 4 deck-enabled versions of mixxx") print(" --mastersync ", end="") print("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 = "" DECK_ORDER = range(0, 2) 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 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", ""], "eq1": ["filterHigh", ""], "eq2": ["filterMid", ""], "eq3": ["filterLow", ""], "slider": ["volume", ""], } button_mapping = { "spinknob": ["beatsync", "