midi: move python assets in src, add launcher context menu action for midi device listing
This commit is contained in:
parent
1d298b574e
commit
3eb73eca74
10 changed files with 125 additions and 77 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -5,6 +5,7 @@ app/assets/*.css*
|
|||
app/assets/*.png
|
||||
app/client/*.js*
|
||||
app/launcher/*.js*
|
||||
app/server/*.js*
|
||||
app/server/*
|
||||
app/package.json
|
||||
package-lock.json
|
||||
*.pyc
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## next
|
||||
|
||||
- launcher
|
||||
- added context menu action to display midi device list without starting the server
|
||||
|
||||
## 0.42.0
|
||||
|
||||
- widgets
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ var cpr = require('cpr'),
|
|||
['../resources/images/logo-nobadge.png', '../app/assets/favicon.png'],
|
||||
['../resources/images/logo.png', '../app/assets/logo.png'],
|
||||
['../LICENSE', '../app/LICENSE'],
|
||||
['../src/python/head.py', '../app/server/python/head.py'],
|
||||
['../src/python/list.py', '../app/server/python/list.py'],
|
||||
['../src/python/midi.py', '../app/server/python/midi.py'],
|
||||
]
|
||||
|
||||
for (var i in files) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ var {remote, ipcRenderer, shell} = eval('require(\'electron\')'),
|
|||
{dialog, Menu, MenuItem, app} = remote.require('electron'),
|
||||
menu = new Menu(),
|
||||
settings = remote.getGlobal('settings'),
|
||||
midilist = remote.getGlobal('midilist'),
|
||||
packageInfos = remote.require('./package.json'),
|
||||
packageVersion = packageInfos.version,
|
||||
packageUrl = packageInfos.repository.url,
|
||||
|
|
@ -210,16 +211,16 @@ $(document).ready(()=>{
|
|||
|
||||
// Fake console
|
||||
var terminal = $('<div class="terminal"></div>').appendTo(form).hide(),
|
||||
autoscoll = true
|
||||
autoscroll = true
|
||||
|
||||
ipcRenderer.on('stdout', function(e, msg){
|
||||
terminal.append(`<div class="log">${ansiHTML(msg)}</div>`)
|
||||
if (autoscoll) scrollBottom()
|
||||
if (autoscroll) scrollBottom()
|
||||
})
|
||||
|
||||
ipcRenderer.on('stderr', function(e, msg){
|
||||
terminal.append(`<div class="error">${ansiHTML(msg)}</div>`)
|
||||
if (autoscoll) scrollBottom()
|
||||
if (autoscroll) scrollBottom()
|
||||
})
|
||||
|
||||
|
||||
|
|
@ -227,6 +228,15 @@ $(document).ready(()=>{
|
|||
|
||||
menu.append(new MenuItem({role: 'copy'}))
|
||||
menu.append(new MenuItem({role: 'paste'}))
|
||||
menu.append(new MenuItem({type: 'submenu' , label: 'Midi', submenu: [
|
||||
new MenuItem({
|
||||
label: 'List Devices',
|
||||
click: ()=>{
|
||||
terminal.show()
|
||||
midilist()
|
||||
}
|
||||
}),
|
||||
]}))
|
||||
menu.append(new MenuItem({type: 'submenu' , label: 'Console', submenu: [
|
||||
new MenuItem({
|
||||
label: 'Clear',
|
||||
|
|
@ -239,7 +249,7 @@ $(document).ready(()=>{
|
|||
type: 'checkbox',
|
||||
checked: true,
|
||||
click: function(e){
|
||||
autoscoll = e.checked
|
||||
autoscroll = e.checked
|
||||
}
|
||||
})
|
||||
]}))
|
||||
|
|
|
|||
26
src/python/head.py
Normal file
26
src/python/head.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from sys import argv, stdin, stdout, version_info, version, exit
|
||||
from binascii import hexlify, unhexlify
|
||||
import traceback
|
||||
import json as JSON
|
||||
import re
|
||||
|
||||
def ipcSend(name, data):
|
||||
print(JSON.dumps([name, data]))
|
||||
stdout.flush()
|
||||
|
||||
try:
|
||||
import rtmidi
|
||||
API = rtmidi.RtMidiIn.UNIX_JACK if 'jack' in argv else rtmidi.RtMidiIn.UNSPECIFIED
|
||||
JACK = API == rtmidi.RtMidiIn.UNIX_JACK
|
||||
in_dev = rtmidi.RtMidiIn(API, 'MIDI->OSC probe')
|
||||
out_dev = rtmidi.RtMidiOut(API, 'OSC->MIDI probe')
|
||||
except:
|
||||
ipcSend('error', 'pyrtmidi not found (or wrong version)\nRunning with python version %s' % version)
|
||||
exit()
|
||||
|
||||
if version_info.major == 3:
|
||||
raw_input = input
|
||||
|
||||
debug = False
|
||||
if 'debug' in argv:
|
||||
debug = True
|
||||
24
src/python/list.py
Normal file
24
src/python/list.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from head import *
|
||||
|
||||
def list():
|
||||
|
||||
message = []
|
||||
|
||||
message.append('===========')
|
||||
message.append('MIDI Inputs')
|
||||
|
||||
for i in range(in_dev.getPortCount()):
|
||||
message.append('%i: %s' % (i, in_dev.getPortName(i)))
|
||||
|
||||
message.append('===========')
|
||||
message.append('MIDI Outputs')
|
||||
|
||||
for i in range(out_dev.getPortCount()):
|
||||
message.append('%i: %s' % (i, out_dev.getPortName(i)))
|
||||
|
||||
ipcSend('log', '\n'.join(message))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
list()
|
||||
|
|
@ -1,47 +1,5 @@
|
|||
from sys import argv, stdin, stdout, version_info, version
|
||||
from binascii import hexlify, unhexlify
|
||||
import traceback
|
||||
import json as JSON
|
||||
import re
|
||||
|
||||
def ipcSend(name, data):
|
||||
print(JSON.dumps([name, data]))
|
||||
stdout.flush()
|
||||
|
||||
try:
|
||||
import rtmidi
|
||||
API = rtmidi.RtMidiIn.UNIX_JACK if 'jack' in argv else rtmidi.RtMidiIn.UNSPECIFIED
|
||||
JACK = API == rtmidi.RtMidiIn.UNIX_JACK
|
||||
in_dev = rtmidi.RtMidiIn(API, 'MIDI->OSC probe')
|
||||
out_dev = rtmidi.RtMidiOut(API, 'OSC->MIDI probe')
|
||||
except:
|
||||
ipcSend('error', 'pyrtmidi not found (or wrong version)\nRunning with python version %s' % version)
|
||||
|
||||
|
||||
if version_info.major == 3:
|
||||
raw_input = input
|
||||
|
||||
debug = False
|
||||
if 'debug' in argv:
|
||||
debug = True
|
||||
|
||||
def list():
|
||||
|
||||
message = []
|
||||
|
||||
message.append('===========')
|
||||
message.append('MIDI Inputs')
|
||||
|
||||
for i in range(in_dev.getPortCount()):
|
||||
message.append('%i: %s' % (i, in_dev.getPortName(i)))
|
||||
|
||||
message.append('===========')
|
||||
message.append('MIDI Outputs')
|
||||
|
||||
for i in range(out_dev.getPortCount()):
|
||||
message.append('%i: %s' % (i, out_dev.getPortName(i)))
|
||||
|
||||
ipcSend('log', '\n'.join(message))
|
||||
from head import *
|
||||
from list import *
|
||||
|
||||
if 'list' in argv:
|
||||
list()
|
||||
|
|
@ -98,6 +98,7 @@ if (settings.cli) {
|
|||
|
||||
app.on('ready',function(){
|
||||
global.settings = settings
|
||||
global.midilist = require('./midi').list
|
||||
launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(100 + 8*3 + 29 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length), node:true, color:'#253040'})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
var {PythonShell} = require('python-shell'),
|
||||
settings = require('./settings')
|
||||
|
||||
class Midi {
|
||||
var pythonOptions = {
|
||||
scriptPath:__dirname,
|
||||
mode:'text',
|
||||
}
|
||||
|
||||
class MidiConverter {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.py = new PythonShell('midi.py', {
|
||||
scriptPath:__dirname,
|
||||
mode:'text',
|
||||
this.py = new PythonShell('python/midi.py', Object.assign({
|
||||
args: [
|
||||
settings.read('debug') ? 'debug' : '',
|
||||
...settings.read('midi')
|
||||
]
|
||||
})
|
||||
}, pythonOptions))
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -34,31 +37,46 @@ class Midi {
|
|||
}
|
||||
|
||||
init(receiveOsc) {
|
||||
this.py.on('message', function(message) {
|
||||
// console.log(message)
|
||||
var name, data
|
||||
try {
|
||||
[name, data] = JSON.parse(message)
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
}
|
||||
if (name == 'log') {
|
||||
if (data.indexOf('ERROR') === 0) {
|
||||
console.error(data)
|
||||
} else {
|
||||
console.log(data)
|
||||
}
|
||||
} else if (name == 'osc') {
|
||||
receiveOsc(data)
|
||||
} else if (name == 'error') {
|
||||
console.error('ERROR: MIDI: ' + data)
|
||||
this.stop()
|
||||
}
|
||||
|
||||
this.py.on('message', (message)=>{
|
||||
MidiConverter.parseIpc(message, this)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
static parseIpc(message, instance) {
|
||||
|
||||
// console.log(message)
|
||||
var name, data
|
||||
try {
|
||||
[name, data] = JSON.parse(message)
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
}
|
||||
if (name == 'log') {
|
||||
if (data.indexOf('ERROR') === 0) {
|
||||
console.error(data)
|
||||
} else {
|
||||
console.log(data)
|
||||
}
|
||||
} else if (name == 'osc') {
|
||||
receiveOsc(data)
|
||||
} else if (name == 'error') {
|
||||
console.error('ERROR: MIDI: ' + data)
|
||||
if (instance) instance.stop()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static list() {
|
||||
|
||||
PythonShell.run('python/list.py', pythonOptions, function (err, results) {
|
||||
if (err) console.error(err)
|
||||
MidiConverter.parseIpc(results)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var midi = new Midi()
|
||||
|
||||
module.exports = midi
|
||||
module.exports = MidiConverter
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ var ipc = require('../server').ipc,
|
|||
EventEmitter = require('events').EventEmitter
|
||||
|
||||
|
||||
if (midi) midi = new midi()
|
||||
|
||||
class OscServer {
|
||||
|
||||
constructor(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue