From 9dc11e97ae3554b8bcc40f21e6716fa3e37c414c Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 4 Apr 2019 20:45:10 +0200 Subject: [PATCH] midi: missing asset cp, better sysex error handling --- scripts/copy-assets.js | 3 ++- src/python/midi.py | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/copy-assets.js b/scripts/copy-assets.js index bec30232..c64849e9 100644 --- a/scripts/copy-assets.js +++ b/scripts/copy-assets.js @@ -7,12 +7,13 @@ var cpr = require('cpr'), ['../LICENSE', '../app/LICENSE'], ['../src/python/head.py', '../app/server/python/head.py'], ['../src/python/list.py', '../app/server/python/list.py'], + ['../src/python/utils.py', '../app/server/python/utils.py'], ['../src/python/midi.py', '../app/server/python/midi.py'], ] for (var i in files) { cpr(...files[i].map(f => path.resolve(__dirname + '/' + f)), { - overwrite: true + overwrite: true }) } diff --git a/src/python/midi.py b/src/python/midi.py index 52194209..cc2b6454 100644 --- a/src/python/midi.py +++ b/src/python/midi.py @@ -146,19 +146,21 @@ def send_midi(name, event, *args): # from hex MIDI data string 'f0 7e 7f 06 01 f7'. # We expect all args to be hex strings! args[0] may contain placeholders of # the form 'nn' that are replaced using args[1..N] to create the final message. - midiBytes = args[0].replace(' ', '') - i = 1 - for m in sysexRegex.finditer(midiBytes): - midiBytes = midiBytes[:m.start()] + args[i].replace(' ', '') + midiBytes[m.end():] - i += 1 + try: + midiBytes = args[0].replace(' ', '') + i = 1 + for m in sysexRegex.finditer(midiBytes): + midiBytes = midiBytes[:m.start()] + args[i].replace(' ', '') + midiBytes[m.end():] + i += 1 - msg = unhexlify(midiBytes) + msg = unhexlify(midiBytes) - if (msg and msg.startswith(b'\xF0') and msg.endswith(b'\xF7') and - all((val <= 0x7F for val in msg[1:-1]))): - m = msg - else: - ipc_send('log', 'ERROR: MIDI: Invalid sysex string: %s' % msg) + if (msg and msg.startswith(b'\xF0') and msg.endswith(b'\xF7') and + all((val <= 0x7F for val in msg[1:-1]))): + m = msg + + except: + pass else: @@ -176,7 +178,7 @@ def send_midi(name, event, *args): if m is None: - ipc_send('log','ERROR: MIDI: could not convert osc args to midi message (%s %s)' % (event, " ".join([str(x) for x in args]))) + ipc_send('log','ERROR: MIDI: could not convert osc to midi (%s %s)' % (event, " ".join([str(x) for x in args]))) else: