def test_parse_invalid_sysex(self): with open('tests/data/test1.syx', 'rb') as r: raw = r.read() raw += 'uh oh' with self.assertRaises(slmkiii.errors.ErrorUnknownData): slmkiii.Template(raw) with self.assertRaises(slmkiii.errors.ErrorUnknownData): slmkiii.Template('wut')
def test_save_export_json(self): tf = tempfile.NamedTemporaryFile(suffix='.syx') template1 = slmkiii.Template('tests/data/expected_1.json') template1.save(tf.name, overwrite=True) template2 = slmkiii.Template(tf.name) with open('tests/data/expected_1.syx', 'rb') as f: sysex2 = f.read() self.assertEqual(template2.export_sysex(), sysex2)
def test_minify_json(self): template1 = slmkiii.Template('tests/data/minimal_2.json') template2 = slmkiii.Template('tests/data/test2.syx') self.assert_equal_templates(template1, template2)
def test_bad_import(self): with self.assertRaises(slmkiii.errors.ErrorTooManyItemsInSection): slmkiii.Template('tests/data/expected_bad_1.json')
def test_invalid_extension(self): tf = tempfile.NamedTemporaryFile(suffix='.fail') with self.assertRaises(slmkiii.errors.ErrorUnknownExtension): slmkiii.Template(tf.name)
def test_default_json(self): template1 = slmkiii.Template('tests/data/minimal_1.json') template2 = slmkiii.Template('tests/data/expected_2.json') self.assertDictEqual(template1.export_json(), template2.export_json()) self.assertEqual(template1.knobs[0].message_type_name, 'CC') self.assertEqual(template1.knobs[0].short_message_type_name, 'CC')
def test_save_json(self): tf = tempfile.NamedTemporaryFile(suffix='.json') template1 = slmkiii.Template('tests/data/test1.syx') template1.save(tf.name, overwrite=True) template2 = slmkiii.Template(tf.name) self.assertDictEqual(template1.export_json(), template2.export_json())
def test_sysex_export_sysex(self): template1 = slmkiii.Template('tests/data/expected_1.json') with open('tests/data/expected_1.syx', 'rb') as f: sysex = f.read() self.assertEqual(sysex, template1.export_sysex())
def test_parse_eight_bit_raw(self): with open('tests/data/test1.syx', 'rb') as r: raw = r.read() template1 = slmkiii.Template(raw) template2 = slmkiii.Template(template1._data) self.assertDictEqual(template1.export_json(), template2.export_json())
def test_parse_sysex_and_json_export(self): template1 = slmkiii.Template('tests/data/expected_1.json') template2 = slmkiii.Template('tests/data/test1.syx') self.assertDictEqual(template1.export_json(), template2.export_json())
def test_parse_seven_bit_raw_and_json_export(self): with open('tests/data/test1.syx', 'rb') as r: raw = r.read() template1 = slmkiii.Template('tests/data/expected_1.json') template2 = slmkiii.Template(raw) self.assertDictEqual(template1.export_json(), template2.export_json())
def test_create_new(self): tf = tempfile.NamedTemporaryFile(suffix='.syx') template1 = slmkiii.Template() template1.save(tf.name, overwrite=True) template2 = slmkiii.Template(tf.name) self.assert_equal_templates(template1, template2)
def test_do_not_replace(self): tf = tempfile.NamedTemporaryFile(suffix='.syx') template = slmkiii.Template('tests/data/minimal_2.json') with self.assertRaises(slmkiii.errors.ErrorFileExists): template.save(tf.name, overwrite=True) template.save(tf.name)
def test_bad_checksum(self): with self.assertRaises(slmkiii.errors.ErrorInvalidChecksum): slmkiii.Template('tests/data/bad_checksum.syx')
def test_bad_json_version(self): with self.assertRaises(slmkiii.errors.ErrorUnknownVersion): slmkiii.Template('tests/data/bad_version.json')
import argparse import slmkiii # value storage is not # # data is scattered around the various parameters parser = argparse.ArgumentParser(description='ALL CCs ARE BECOME BACON') parser.add_argument('input_filename') parser.add_argument('output_filename') args = parser.parse_args() print "Opening {}...".format(args.input_filename) template = slmkiii.Template(args.input_filename) # ALL CCs ARE BECOME BACON for knob in syx.knobs: if knob.message_type_name == 'CC': knob.name = 'Bacon {}'.format(knob.first_param) for button in syx.buttons: if button.message_type_name == 'CC': button.name = 'Bacon {}'.format(button.fourth_param) for fader in syx.faders: if fader.message_type_name == 'CC': fader.name = 'Bacon {}'.format(fader.second_param) for pad_hit in syx.pad_hits: if pad_hit.message_type_name == 'CC': pad_hit.name = 'Bacon {}'.format(pad_hit.fourth_param) template.save(args.output_filename) print "Created {}".format(args.output_filename)