midi: implement backend restart feature
This commit is contained in:
parent
31f4119442
commit
e4eae76bdf
7 changed files with 84 additions and 18 deletions
|
|
@ -32,6 +32,8 @@
|
|||
|
||||
- midi
|
||||
- add `no_auto_note_off` option
|
||||
- add `Restart backend` action to the launcher's menu
|
||||
- add `restartMidiBackend()` function to custom module context
|
||||
|
||||
- breaking change
|
||||
- dropped support for iOS 10.3
|
||||
|
|
|
|||
|
|
@ -167,6 +167,10 @@ for (var ip in tcpServer.clients) {
|
|||
```
|
||||
|
||||
|
||||
#### `restartMidiBackend()`
|
||||
|
||||
This function can be used to restart the midi backend (if already running) without restarting the server
|
||||
|
||||
#### Other javascript globals
|
||||
|
||||
- `console`
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@
|
|||
- New window: open a new client window (hidden when stopped)
|
||||
- Load: load server configuration from file
|
||||
- Save / Save as: save server configuration to file
|
||||
- List MIDI devices: list available MIDI devices in the console
|
||||
- MIDI
|
||||
- List devices: list available MIDI devices in the console
|
||||
- Restart backend: restart midi backend without restarting the server
|
||||
- Console:
|
||||
- Clear: clear console
|
||||
- Autoscroll: enable/disable console autoscroll
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {DOM, PXSCALE} from '../client/globals.mjs'
|
|||
|
||||
var {Menu, MenuItem} = remote.require('electron'),
|
||||
menu = new Menu(),
|
||||
{midilist, openDocs} = remote.getGlobal('launcherSharedGlobals'),
|
||||
{midiList, midiRestart, openDocs} = remote.getGlobal('launcherSharedGlobals'),
|
||||
serverStarting = false,
|
||||
serverStart = ()=>{
|
||||
if (serverStarting) return
|
||||
|
|
@ -77,13 +77,25 @@ menu.append(new MenuItem({
|
|||
menu.append(new MenuItem({
|
||||
type: 'separator'
|
||||
}))
|
||||
menu.append(new MenuItem({
|
||||
label: 'List MIDI Devices',
|
||||
click: ()=>{
|
||||
midilist()
|
||||
},
|
||||
accelerator: 'ctrl + m'
|
||||
}))
|
||||
|
||||
menu.append(new MenuItem({type: 'submenu' , label: 'MIDI', submenu: [
|
||||
new MenuItem({
|
||||
label: 'List devices',
|
||||
click: ()=>{
|
||||
midiList()
|
||||
},
|
||||
accelerator: 'ctrl + m'
|
||||
}),
|
||||
new MenuItem({
|
||||
label: 'Restart backend',
|
||||
id: 'midiRestart',
|
||||
click: ()=>{
|
||||
midiRestart()
|
||||
},
|
||||
enabled: false
|
||||
}),
|
||||
|
||||
]}))
|
||||
menu.append(new MenuItem({type: 'submenu' , label: 'Console', submenu: [
|
||||
new MenuItem({
|
||||
label: 'Clear',
|
||||
|
|
@ -211,6 +223,8 @@ class Toolbar {
|
|||
stop.visible = !!serverStarting
|
||||
qrcode.visible = !!serverStarting
|
||||
newWindow.visible = !!serverStarting
|
||||
menu.getMenuItemById('midiRestart').enabled = !!serverStarting
|
||||
|
||||
menu.popup({window: remote.getCurrentWindow(), x: parseInt(PXSCALE), y: parseInt(40 * PXSCALE)})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,12 @@ function startLauncher() {
|
|||
global.launcherSharedGlobals = {
|
||||
settings: settings,
|
||||
openDocs: openDocs,
|
||||
midilist: midi.list
|
||||
midiList: midi.list,
|
||||
midiRestart: ()=>{
|
||||
if (serverProcess) {
|
||||
serverProcess.send('midiRestart')
|
||||
}
|
||||
}
|
||||
}
|
||||
var address = 'file://' + path.resolve(__dirname + '/../../launcher/' + 'index.html')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import {PythonShell} from 'python-shell'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import {EventEmitter} from 'events'
|
||||
import * as settings from './settings.mjs'
|
||||
|
||||
|
||||
var scriptPath = __dirname.includes('server/node') ?
|
||||
var scriptPath = __dirname.includes('server/node') ?
|
||||
path.resolve(__dirname, '../python') : // src folder structure
|
||||
path.resolve(__dirname, './python') // app folder structure with rollup chunking
|
||||
|
||||
|
|
@ -32,12 +33,33 @@ if (midiBinaries[process.arch] && midiBinaries[process.arch][process.platform])
|
|||
}
|
||||
}
|
||||
|
||||
class MidiConverter {
|
||||
class MidiConverter extends EventEmitter{
|
||||
|
||||
constructor() {
|
||||
|
||||
super()
|
||||
|
||||
if (expectMidiBinariesError) MidiConverter.midiBinariesError()
|
||||
|
||||
this.running = false
|
||||
this.restarting = false
|
||||
this.py = {}
|
||||
|
||||
this.start()
|
||||
|
||||
|
||||
process.on('message', (m) => {
|
||||
if (m == 'midiRestart') {
|
||||
this.restart()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
if (this.running) return
|
||||
|
||||
this.py = new PythonShell('midi.py', Object.assign({
|
||||
args: [
|
||||
'--params',
|
||||
|
|
@ -55,12 +77,32 @@ class MidiConverter {
|
|||
}
|
||||
})
|
||||
|
||||
this.running = true
|
||||
this.py.childProcess.on('exit', (code)=>{
|
||||
if (code === null) console.error('(ERROR, MIDI) Midi bridge process crashed')
|
||||
if (code === null && !this.restarting) console.error('(ERROR, MIDI) Midi bridge process crashed')
|
||||
this.running = false
|
||||
this.emit('stopped')
|
||||
})
|
||||
|
||||
this.running = true
|
||||
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
if (this.running) this.py.childProcess.kill()
|
||||
|
||||
}
|
||||
|
||||
restart() {
|
||||
|
||||
if (this.running) {
|
||||
this.restarting = true
|
||||
this.once('stopped', ()=>{
|
||||
this.start()
|
||||
this.restarting = false
|
||||
})
|
||||
this.stop()
|
||||
}
|
||||
}
|
||||
|
||||
send(data) {
|
||||
|
|
@ -76,11 +118,7 @@ class MidiConverter {
|
|||
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
this.py.childProcess.kill()
|
||||
|
||||
}
|
||||
|
||||
init(receiveOsc) {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export default class OscServer {
|
|||
this.customModuleEventEmitter = new EventEmitter()
|
||||
this.customModule = settings.read('custom-module') ? new CustomModule(settings.read('custom-module'), {
|
||||
app: this.customModuleEventEmitter,
|
||||
restartMidiBackend: ()=>{if (this.midiServer) this.midiServer.restart()},
|
||||
tcpServer: this.oscTCPServer,
|
||||
sendOsc: this.sendOsc.bind(this),
|
||||
receiveOsc: this.receiveOsc.bind(this),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue