midi: implementing midi addon with python-pyo (wip)
This commit is contained in:
parent
2ee89db9cf
commit
8fbcdce320
5 changed files with 241 additions and 7 deletions
48
app/main/midi.js
Normal file
48
app/main/midi.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
var PythonShell = require('python-shell'),
|
||||
path = require('path'),
|
||||
settings = require('./settings')
|
||||
|
||||
|
||||
var py = new PythonShell(path.resolve('/main/midi.py'),{mode:'text', args: settings.read('midi')})
|
||||
|
||||
|
||||
|
||||
// py.send('zefezf')
|
||||
//
|
||||
//
|
||||
// py.on('error', function (message) {
|
||||
// // received a message sent from the Python script (a simple "print" statement)
|
||||
// console.log('error:' +message);
|
||||
// });
|
||||
|
||||
oscToMidi = (data)=>{
|
||||
var args = []
|
||||
for (i in data.args) {
|
||||
args.push(data.args[i].value)
|
||||
}
|
||||
py.send(JSON.stringify([data.port, data.address, ...args]))
|
||||
}
|
||||
|
||||
init = (receiveOsc)=>{
|
||||
py.on('message', function (message) {
|
||||
// console.log(message)
|
||||
|
||||
try {
|
||||
message = JSON.parse(message)
|
||||
// console.log(JSON.parse(message))
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
}
|
||||
if (message.log) {
|
||||
console.log(message.log)
|
||||
} else if (message.osc) {
|
||||
receiveOsc(message.osc)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
send: oscToMidi,
|
||||
init: init
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue