diff --git a/src/python/head.py b/src/python/head.py index 6077beeb..cb59c2ec 100644 --- a/src/python/head.py +++ b/src/python/head.py @@ -13,7 +13,7 @@ try: from rtmidi.midiconstants import * API = rtmidi.API_UNIX_JACK if 'jack' in argv else rtmidi.API_UNSPECIFIED - if API is rtmidi.API_UNIX_JACK and rtmidi.API_UNIX_JACK not in rtmidi.get_compiled_api(): + if API == rtmidi.API_UNIX_JACK and rtmidi.API_UNIX_JACK not in rtmidi.get_compiled_api(): API = rtmidi.API_UNSPECIFIED ipc_send('log', '(ERROR, MIDI) python-rtmidi was not compiled with jack midi support, falling back to default API') diff --git a/src/python/midi.py b/src/python/midi.py index 7b4dc320..e8d4f464 100644 --- a/src/python/midi.py +++ b/src/python/midi.py @@ -5,6 +5,10 @@ from utils import * if 'list' in argv: list() +if 'list-only' in argv: + list() + exit() + # option: act as if displayed program is between 1-128 instead of 0-127 PROGRAM_CHANGE_OFFSET = 'pc_offset' in argv @@ -13,7 +17,11 @@ outputs = {} for arg in argv: - if type(arg) == str and ':' in arg: + if 'python/midi.py' in arg: + + pass # in case we're using pre-compiled binaries + + elif type(arg) == str and ':' in arg: name, ports = arg.split(':') @@ -81,7 +89,7 @@ def create_callback(name): osc['address'] = MIDI_TO_OSC[mtype] - if mtype is SYSTEM_EXCLUSIVE: + if mtype == SYSTEM_EXCLUSIVE: # Parse the provided data into a hex MIDI data string of the form 'f0 7e 7f 06 01 f7'. v = ' '.join([hex(x).replace('0x', '').zfill(2) for x in message]) osc['args'].append({'type': 'string', 'value': v}) @@ -96,10 +104,10 @@ def create_callback(name): if mtype == NOTE_OFF: message[2] = 0 - elif mtype is PITCH_BEND: + elif mtype == PITCH_BEND: message = message[:1] + [message[1] + message[2] * 128] # convert 0-127 pair -> 0-16384 -> - elif mtype is PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET: + elif mtype == PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET: message[-1] = message[-1] + 1 for data in message[1:]: @@ -135,10 +143,10 @@ def midi_message(status, channel, data1=None, data2=None): msg = [(status & 0xF0) | (channel - 1 & 0xF)] - if data1 is not None: + if data1 != None: msg.append(data1 & 0x7F) - if data2 is not None: + if data2 != None: msg.append(data2 & 0x7F) return msg @@ -160,7 +168,7 @@ def send_midi(name, event, *args): mtype = OSC_TO_MIDI[event] - if mtype is SYSTEM_EXCLUSIVE: + if mtype == SYSTEM_EXCLUSIVE: # unhexlify('f0 7e 7f 06 01 f7') creates a sysex message # from hex MIDI data string 'f0 7e 7f 06 01 f7'. @@ -187,19 +195,19 @@ def send_midi(name, event, *args): args = [int(round(x)) for x in args] m = [mtype, args[0]] - if mtype is NOTE_ON: - if args[2] is 0: + if mtype == NOTE_ON: + if args[2] == 0: mtype = NOTE_OFF - elif mtype is PITCH_BEND: + elif mtype == PITCH_BEND: args = args[:1] + [args[1] & 0x7f, (args[1] >> 7) & 0x7f] # convert 0-16384 -> 0-127 pair - elif mtype is PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET: + elif mtype == PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET: args[-1] = args[-1] - 1 m = midi_message(mtype, *args) - if m is None: + if m == None: ipc_send('log','(ERROR, MIDI) could not convert osc to midi (%s %s)' % (event, " ".join([str(x) for x in args]))) diff --git a/src/python/requirements.txt b/src/python/requirements.txt new file mode 100644 index 00000000..3aa7f400 --- /dev/null +++ b/src/python/requirements.txt @@ -0,0 +1 @@ +python-rtmidi == 1.4.2 diff --git a/src/python/utils.py b/src/python/utils.py index 95622973..bdf01f80 100644 --- a/src/python/utils.py +++ b/src/python/utils.py @@ -22,7 +22,7 @@ def midi_str(message): mtype = message[0] & 0xF0 s = 'UNKNOWN' - if mtype is SYSTEM_EXCLUSIVE: + if mtype == SYSTEM_EXCLUSIVE: s = 'SYSTEM_EXCLUSIVE: sysex=%s' % ' '.join([hex(x).replace('0x', '').zfill(2) for x in message]) @@ -33,15 +33,15 @@ def midi_str(message): try: - if mtype is NOTE_ON: + if mtype == NOTE_ON: s = 'NOTE_ON: channel=%i, note=%i, velocity=%i' % (channel, message[1], message[2]) - elif mtype is NOTE_OFF: + elif mtype == NOTE_OFF: s = 'NOTE_OFF: channel=%i, note=%i' % (channel, message[1]) - elif mtype is CONTROL_CHANGE: + elif mtype == CONTROL_CHANGE: s = 'CONTROL_CHANGE: channel=%i, cc=%i, value=%i'% (channel, message[1], message[2]) - elif mtype is PROGRAM_CHANGE: + elif mtype == PROGRAM_CHANGE: s = 'PROGRAM_CHANGE: channel=%i, program=%i' % (channel, message[1]) - elif mtype is PITCH_BEND: + elif mtype == PITCH_BEND: s = 'PITCH_BEND: channel=%i, pitch=%i' % (channel, message[1] + message[2] * 128 if len(message) == 3 else message[1]) except IndexError: diff --git a/src/server/midi.js b/src/server/midi.js index 354e3280..0608c303 100644 --- a/src/server/midi.js +++ b/src/server/midi.js @@ -84,7 +84,7 @@ class MidiConverter { var pythonPath = settings.read('midi') ? settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0] : undefined - PythonShell.run('python/list.py', Object.assign({pythonPath}, pythonOptions), function(e, results) { + PythonShell.run('python/midi.py', Object.assign({pythonPath: pythonPath, args: ['list-only']}, pythonOptions), function(e, results) { if (e) { if (e.code === 'ENOENT') { console.error(`(ERROR, MIDI) Could not find python binary: ${e.message.replace(/spawn (.*) ENOENT/, '$1')}`)