-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomModule.js
78 lines (63 loc) · 2.82 KB
/
customModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const path = nativeRequire('path')
const SibeliusConnect = require('SibeliusConnect.js')
const DoricoRemote = require('DoricoRemote.js')
module.exports = {
init: function() {
global.SibeliusConnect = new SibeliusConnect({ plugins: ['cmdutils'] })
// global.SibeliusConnect.connect()
global.DoricoRemote = new DoricoRemote()
// global.DoricoRemote.connect()
},
oscOutFilter: function(data) {
const { address, args, host, port, clientId } = data;
try {
if (args.length === 1 && args[0].value === 0) {
// passthru "off"/0 messages
return data
}
if (address === '/sibelius' || path.dirname(address) === '/sibelius') {
let newArgs = args
if (args.length === 1 && args[0].value.indexOf(';') > -1) {
newArgs = args[0].value.split(';').map(v => { return { type: 's', value: v.replace(/^\n|\n$/g, '').trim() } })
}
newArgs.forEach(arg => {
let addr = address
arg = arg.value
if (arg.startsWith('command:') || arg.startsWith('plugin:')) {
addr = arg.substring(0,arg.indexOf(':'))
arg = arg.substring(arg.indexOf(':') + 1)
}
let msg = arg.startsWith('{') ? JSON.parse(arg) : {}
if (path.basename(addr) === 'command') {
msg.message = 'invokeCommands'
msg.commands = arg.split(',').map(v => v.trim())
}
else if (path.basename(addr) === 'plugin') {
msg.message = 'invokePlugin'
if (!msg.name || msg.name === '') {
const [pluginName, method, ...methodArgs] = arg.split(',')
msg.name = pluginName
if (method) {
msg.method = method
}
if (methodArgs && methodArgs.length > 0) {
msg.args = JSON.parse(`[${methodArgs.join(',').replace(/\\/g, "\\\\")}]`)
}
}
}
global.SibeliusConnect.send(msg)
})
return;
}
else if (address === '/dorico') {
args.forEach(arg => {
global.DoricoRemote.send(JSON.parse(arg.value))
})
}
}
catch (e) {
receive('/NOTIFY', '^circle-exclamation', `${address} ${args.map(a => a.value).join(' ')}\n\n ${e.toString()}`)
}
return { address, args, host, port };
},
};