Here is a Python script which merges two Akai XPM keygroup programs. Tested with Force 3.1.3, with merged keygroup programs auto-sampled on MPC One 2.10. There is no error checking. It simply takes all <Program> / <Instruments> / <Instrument> structures from program 2, adds them to the <Program> / <Instruments> structure loaded from program 1, and saves the whole updated structure to a new file. Only <Instrument> thingies and program name are taken from program 2. Program name and number of instruments are updated accordingly. The script does not at all understand what the XML represents, or if the result will "work" in any way, whatever "working" means to anyone.
Code: Select all""" file: merge_akai_keygroup_programs.py
Merge two Akai XPM keygroup programs. No input checking.
Usage:
python merge_akai_keygroup_programs.py <program1.xpm> <program2.xpm> <combined_program.xpm>
"""
import sys
import xml.etree.ElementTree as et
# parse input data
tree1 = et.parse(sys.argv[1])
tree2 = et.parse(sys.argv[2])
program1 = tree1.find('Program')
program2 = tree2.find('Program')
program1_instruments = program1.find('Instruments')
program2_instruments = program2.find('Instruments')
# number of instruments i.e. keygroups in program 1
program1_orig_num_instruments = len(program1_instruments.findall('Instrument'))
# add instruments (keygroups) from program 2 to program 1
for el in program2_instruments.findall('Instrument'):
el.attrib['number'] = str(int(el.attrib['number']) + program1_orig_num_instruments)
program1_instruments.append(el)
# update number of instruments
program1.find('KeygroupNumKeygroups').text = \
str(len(program1_instruments.findall('Instrument')))
# update program name
program1.find('ProgramName').text = \
program1.find('ProgramName').text + ' + ' + program2.find('ProgramName').text
# write combined program to a new file
with open(sys.argv[3], 'wb') as f:
tree1.write(f)