I’ve combined your example code with your other articulationFilter example code. I have added another type
property to the articulation object e.g. (type:short
) and am filling button arrays based on the type of articulation, then using /EDIT to show the buttons in their corresponding containers (panel_short, panel long etc). This concept is working well, but I am unsure how I could do this dynamically (i.e. not hard code the button array names, container names etc. If there are only 2 types of articulations for the track, create the container names based on the two types (short, long. Hard mallets, soft mallets. With mute, without mute etc It should get this information from the articulation object). I think I should also make the switch case section much shorter. There is a lot of repeated code. Perhaps a function. As I’m not a coder at all, but am enjoying learning this software, if you have any thoughts on how I could achieve this, or if I am doing anything here that is really terrible practice, that would be great. Appreciate your time. Hope this also helps others. Here is my code:
(function(){
// mapping between the daw's track identifiers and the articulation's labels
var tracks = {
1 : { maker : "VSL", group : "WW", inst : "clarinet", arts : ['stacc' , 'sus' , 'trill']}, //etc
2 : { maker : "VSL", group : "strings", inst : "violin", arts : ['stacc' , 'trill whole' , 'trem', 'port']}
// etc
}
colors = {
short:'yellow',
long: 'pink',
deco: 'purple',
}
// articulations details that will be used to create buttons
var articulations = {
'stacc': {
color: colors.short,
type: 'short',
// etc
},
'sus': {
color: colors.long,
type: 'long',
// etc
},
'trill': {
color: colors.deco,
type: 'deco',
},
//etc
}
function articulationFilter(address, args){
// only filter messages that match our needs
if (address !== '/control') return
var trackname = 0, //just for testing
buttons_short = [], //how can I do these dynamically?
buttons_long = [],
buttons_deco = [],
counter = 1,
selectedTrack = tracks[trackname]
for (var articulation in articulations) {
if (selectedTrack !== undefined && selectedTrack.arts.includes(articulation)) {
var type = articulations[articulation].type
switch (type){
case 'short':
buttons_short.push({ //how to do this dynamically?
type: 'push',
id: 'button_' + counter,
label: articulation,
address: '/control',
preArgs: '[1, ' + counter + ']',
color: articulations[articulation].color,
target: 'midi:buttonsOut',
norelease: true,
css: `:host{
margin:2px;
color: ${articulations[articulation].color}
}`,
// etc
})
counter++
break
case 'long':
buttons_long.push({
type: 'push',
id: 'button_' + counter,
label: articulation,
address: '/control',
preArgs: '[1, ' + counter + ']',
color: articulations[articulation].color,
target: 'midi:buttonsOut',
norelease: true,
css: `:host{
margin:2px;
color: ${articulations[articulation].color}
}`,
// etc
})
counter++
break;
case 'deco':
buttons_deco.push({
type: 'push',
id: 'button_' + counter,
label: articulation,
address: '/control',
preArgs: '[1, ' + counter + ']',
color: articulations[articulation].color,
target: 'midi:buttonsOut',
norelease: true,
css: `:host{
margin:2px;
color: ${articulations[articulation].color}
}`,
// etc
})
counter++
break;
}
}
}
// replace the container's children with our list of buttons
receive('/EDIT', 'panel_short', {widgets: buttons_short}) //how to do this dynamically?
receive('/EDIT', 'panel_long', {widgets: buttons_long})
receive('/EDIT', 'panel_deco', {widgets: buttons_deco})
} //end articulation filter
return {
oscInFilter:function(data){
var {address, args, host, port} = data
// insert our custom filter in the loop
articulationFilter(address, args)
return {address, args, host, port}
}
}
})()