From 22dbaafc6144640c9965074a4f166a94c61c9659 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 28 Feb 2017 17:15:41 +0100 Subject: [PATCH] midi: handle errors from node, print and kill process --- app/main/midi.js | 12 +++++++++--- app/main/midi.py | 12 ++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/main/midi.js b/app/main/midi.js index d3d3f0dd..6dd64a35 100644 --- a/app/main/midi.js +++ b/app/main/midi.js @@ -18,6 +18,10 @@ oscToMidi = (data)=>{ py.send(JSON.stringify([data.port, data.address, ...args])) } +stop = ()=>{ + py.childProcess.kill() +} + init = (receiveOsc)=>{ py.on('message', function (message) { // console.log(message) @@ -31,13 +35,15 @@ init = (receiveOsc)=>{ console.log(data) } else if (name == 'osc') { receiveOsc(data) + } else if (name == 'error') { + console.log('ERROR: Midi: ' + data) + stop() + process.exit() } }) } -stop = ()=>{ - py.childProcess.kill() -} + module.exports = { send: oscToMidi, diff --git a/app/main/midi.py b/app/main/midi.py index 8af2e7c4..525ab199 100644 --- a/app/main/midi.py +++ b/app/main/midi.py @@ -47,7 +47,7 @@ if len(virtuals) > 0: import mididings from threading import Thread except: - raise ImportError('virtual midi port requires python-mididings (linux only)') + ipcSend('error', 'virtual midi port requires python-mididings (linux only)') mididings.config(client_name='Open Stage Control', in_ports=mididingsInPorts, out_ports=mididingsOutPorts) @@ -62,15 +62,15 @@ if len(virtuals) > 0: try: import pyo except: - raise ImportError('python-pyo module not found') + ipcSend('error','python-pyo module not found') version = int(pyo.PYO_VERSION.replace('.','')) if version < 83: - raise ImportError('python-pyo >= 8.3.0 module is required (%s found)' % pyo.PYO_VERSION) + ipcSend('error','python-pyo >= 8.3.0 module is required (%s found)' % pyo.PYO_VERSION) if not pyo.withPortmidi(): - raise ImportError('python-pyo must be built with portmidi support') + ipcSend('error','python-pyo must be built with portmidi support') # get midi devices @@ -153,10 +153,10 @@ class MidiRouter(object): o = int(ports.split(',')[1]) if i not in _midiInputs[1] and i != -1: - raise ValueError('Invalid midi input %i' % i) + ipcSend('error','Invalid midi input %i' % i) if o not in _midiOutputs[1] and o != -1: - raise ValueError('Invalid midi output %i' % o) + ipcSend('error','Invalid midi output %i' % o) if i != -1: self.midiDevicesIn[i] = name