-
Notifications
You must be signed in to change notification settings - Fork 7
/
ardour-plugins-module.js
385 lines (325 loc) · 11.1 KB
/
ardour-plugins-module.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
STRIP_NAMES = {}
PLUGIN_NAMES = {}
PLUGIN = {}
CURRENT_SSID = 0
var host, port, error = false
if (settings.read('send')) {
[host, port] = settings.read('send')[0].split(':')
} else {
console.warn('(WARNING) "send" option not set')
error = true
}
// Shorthand for osc sending to ardour
_send = (address, ...args)=>{
if (!error) send(host, port, address, ...args)
}
// Shorthand for osc sending to client
_receive = (address, ...args)=>{
receive(host, port, address, ...args)
}
// send plugin list to strip
function createPluginsList(ssid, plugins) {
var widgets = []
for (var i in plugins) {
widgets.push({
type: 'panel',
mode: 'horizontal',
label: false,
scroll: false,
padding: 0,
height: 20,
alphaStroke: 0,
innerPadding: false,
widgets: [
{
type: 'button',
mode: 'toggle',
padding: -1,
width: 20,
value: plugins[i].active,
alphaStroke: 0,
alphaFillOff: 0.15,
alphaFillOn: 0.15,
id: `strip_${ssid}_plugin_${plugins[i].id}_active`,
label: '^circle',
css: '--color-text: var(--color-background); --color-text-on: var(--color-widget);',
address: '/strip/plugin/activate',
preArgs: [ssid, plugins[i].id],
typeTags: 'i'
},
{
type: 'button',
mode: 'tap',
padding: -1,
expand: true,
alphaStroke: 0,
alphaFillOff: 0.15,
linkId: '>> plugin_modal',
id: `strip_${ssid}_plugin_${plugins[i].id}`,
label: plugins[i].name,
address: '/strip/plugin/descriptor',
preArgs: ssid,
doubleClick: true,
on: plugins[i].id
}
]
})
}
_receive('/EDIT', 'plugins_' + ssid, {
widgets: widgets,
})
}
// send plugin gui to plugin modal
function createPluginsGui() {
var widgets = [],
toggles = {type:'panel', layout: 'vertical', label: false, alphaStroke: 0, widgets:[], width:200, contain: false, innerPadding: false, padding: 0},
faders = {type:'panel', layout: 'vertical', label: false, alphaStroke: 0, widgets:[], expand:true, contain: false, innerPadding: false, padding: 0}
for (var j in PLUGIN.parameters) {
if (256 & PLUGIN.parameters.flags) continue
let w = paramsToWidget(PLUGIN.parameters[j], PLUGIN.id)
if (!w) continue
var pane = w.type === 'button' ? toggles : faders
pane.widgets.push({
type: 'panel',
height: 35,
layout: 'horizontal',
label: false,
padding: 0,
alphaStroke: 0,
widgets: [
{
type: 'text',
value: PLUGIN.parameters[j].name,
label: false,
expand: w.type === 'button',
width: 100,
alphaStroke: 0,
alphaFillOff: 0,
align: 'left',
colorWidget: '#ccc'
},
w
]
})
if (w.type === 'fader') {
pane.widgets[pane.widgets.length-1].widgets.push({
type: 'input',
label: false,
width: 80,
unit: w.unit,
linkId: w.linkId,
alphaStroke: 0,
bypass: true
})
}
}
if (toggles.widgets.length) widgets.push(toggles)
if (faders.widgets.length) widgets.push(faders)
_receive('/EDIT', 'plugin_modal', {
widgets: widgets,
popupLabel: STRIP_NAMES[CURRENT_SSID] + ' ^chevron-right ' + PLUGIN_NAMES[CURRENT_SSID + '_' + PLUGIN.id]
})
}
// convert ardour plugin parameters to widget definition
function paramsToWidget(params, ppid) {
var type = ! (128 & params.flags) ? 'meter' :
1 & params.flags ? 'dropdown' :
64 & params.flags ? 'button' : 'fader',
unit = !params.unit.length ? '' :
params.unit.replace(/\%\.?[0-9]*[a-z]{1}/,'')
.replace('%%','%').trim()
var widget = {
id: 'plugin_' + ppid + '_param_' + params.id,
label: params.name,
type: type,
address: '/strip/plugin/parameter',
preArgs: [CURRENT_SSID, ppid, params.id],
precision: 2 & params.flags ? 0 : 2,
logScale: 4 & params.flags ? true : false,
unit: unit,
value: params.value,
alphaStroke: 0,
alphaFillOff: 0.1
}
if (type == 'button') {
widget.mode = 'toggle'
widget.off = params.min
widget.on = params.max
widget.width = 35
widget.padding = 1
widget.label = false
} else if (type == 'fader'){
widget.horizontal = true
widget.label = false
widget.expand = true
widget.design = 'compact'
widget.linkId = 'plugin_param_' + CURRENT_SSID + '_' + ppid + '_' + params.id
if (params.pips.length) {
var range = {}
for (var n in params.pips) {
let val = params.pips[n][0],
percent = 100 * (params.pips[n][0] - params.min) / (params.max - params.min) + '%',
label = params.pips[n][1]
range[percent] = {}
range[percent][label] = val
}
widget.range = range
} else {
widget.pips = false
widget.range = {min:params.min, max:params.max}
}
} else if (type == 'meter'){
return // Useless since ardour doesn't send plugin feedback
} else if (type == 'dropdown'){
widget.label = false
widget.expand = true
widget.values = {}
if (params.pips.length) {
for (var n in params.pips) {
widget.values[params.pips[n][1]] = params.pips[n][0]
}
} else {
return
}
} else {
return
}
return widget
}
app.on('sessionOpened', ()=>{
// make client send config to ardour
receive('/SET', 'load_config', 1)
receive('/SET', 'connect', 1)
})
module.exports = {
oscInFilter: function(data) {
var {address, args, host, port} = data
if (address === '/strip/name') {
if (args[1].value === ' ') {
createPluginsList(args[0].value, [])
} else {
_send('/strip/plugin/list', args[0].value)
}
STRIP_NAMES[args[0].value] = args[1].value
}
else if (address == '/strip/plugin/list') {
let plugins = [],
ssid = args[0].value
for (let i=1; i<args.length; i+=3) {
let plugin = {
id: args[i].value,
name: args[i+1].value,
active: args[i+2].value
}
PLUGIN_NAMES[ssid + '_' + plugin.id] = plugin.name
plugins[args[i].value] = plugin
}
createPluginsList(ssid, plugins)
return
}
else if (address == '/strip/plugin/descriptor' && args.length > 1) {
PLUGIN.id = args[1].value
PLUGIN.parameters[args[2].value] = {
id: args[2].value,
name: args[3].value,
flags: args[4].value,
dataType: args[5].value,
min: args[6].value,
max: args[7].value,
unit: args[8].value,
pips: []
}
// skip scale infos
var nPips = args[9].value
for (var p=0; p < nPips * 2; p += 2) {
PLUGIN.parameters[args[2].value].pips.push([args[10 + p].value, args[10 + p + 1].value])
}
// get current value
PLUGIN.parameters[args[2].value].value = args[10 + nPips * 2].value
return
}
else if (address == '/strip/plugin/descriptor_end' && args.length > 1) {
createPluginsGui()
return
}
// else if (address == '/strip/sends') {
// sends = []
//
// if (args.length > 1) {
// for (var i=1; i<args.length; i+=5) {
// sends.push({
// targetId: args[0].value,
// name: args[i+1].value,
// id: args[i+2].value,
// gain: args[i+3].value,
// enabled: args[i+4].value
// })
// }
// }
// createSendsReceivesGui('Send')
// return
// }
//
// else if (address == '/strip/receives') {
// sends = []
//
// if (args.length > 1) {
// for (var i=0; i<args.length; i+=5) {
// sends.push({
// targetId: args[i].value,
// name: args[i+1].value,
// id: args[i+2].value,
// gain: args[i+3].value,
// enabled: args[i+4].value
// })
// }
// }
// createSendsReceivesGui('Receive')
// return
// }
return {address, args, host, port}
},
oscOutFilter: function(data) {
var {address, args, host, port} = data
if (address === '/strip/plugin/list') {
if (!args[1].value) {
// empty plugin panel
plugins = []
createPluginsList()
return
} else {
// query plugin list
CURRENT_SSID = args[0].value
args.pop()
}
}
else if (address === '/strip/plugin/descriptor') {
CURRENT_SSID = args[0].value
PLUGIN = {id: 0, parameters: {}}
}
else if (address === '/plugin_modal' && args[0].value === 0) {
receive('/EDIT', 'plugin_modal', {
label: false,
widgets: []
})
}
else if (address === '/strip/plugin/activate') {
if (!args[2].value) address = '/strip/plugin/deactivate'
args.pop()
}
// else if (address === '/receives_panel' && args[0].value === 1) {
// _send(
// '/strip/receives',
// {type:'i', value:CURRENT_SSID}
// )
// }
//
// else if (address === '/sends_panel' && args[0].value === 1) {
// _send(
// '/strip/sends',
// {type:'i', value:CURRENT_SSID}
// )
// }
return {address, args, host, port}
}
}