Skip to content

Commit

Permalink
chore: convert upgrade scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jun 9, 2021
1 parent 02d1922 commit 02f1133
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 133 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var tcp = require('../../tcp');
var instance_skel = require('../../instance_skel');
var scpNames = require('./scpNames.json');
var upgrade = require('./upgrade');
var upgradeScripts = require('./upgrade');

const SCP_PARAMS = ['Ok', 'Command', 'Index', 'Address', 'X', 'Y', 'Min', 'Max', 'Default', 'Unit', 'Type', 'UI', 'RW', 'Scale'];
const SCP_VALS = ['Status', 'Command', 'Address', 'X', 'Y', 'Val', 'TxtVal'];
Expand All @@ -18,10 +18,6 @@ class instance extends instance_skel {
constructor(system, id, config) {
super(system, id, config);

Object.assign(this, {
...upgrade,
});

this.scpCommands = [];
this.nameCommands = []; // Commands which have a name field
this.colorCommands = []; // Commands which have a color field
Expand All @@ -31,9 +27,11 @@ class instance extends instance_skel {
this.macroCount = 0;
this.dataStore = {};

this.addUpgradeScripts();
}

static GetUpgradeScripts() {
return upgradeScripts
}

// Startup
init() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yamaha-scp",
"version": "1.4.1",
"version": "1.4.2",
"api_version": "1.0.0",
"description": "Control module for Yamaha Pro Audio equipment via SCP",
"main": "index.js",
Expand Down
237 changes: 111 additions & 126 deletions upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,144 +2,129 @@
// Do the upgrades of actions, release actions and feedback
*/

module.exports = {

addUpgradeScripts() {

console.log('Running upgrade script.');

// Upgrade 1.0.x > 1.1.0
this.addUpgradeScript((config, actions, releaseActions, feedbacks) => {
var changed = false;
console.log('Running 1.1.1 -> 1.1.2 Upgrade.')

let checkUpgrade = function(action, changed) {
let newAction = '';

switch (action.action) {
case 'InChOn':
// cmd = 'set MIXER:Current/InCh/Fader/On '+ opt.Ch + ' 0 1';
newAction = 186;
action.options.X = actions.options.Ch;
action.options.Val = 1;
break;
case 'InChOff':
// cmd = 'set MIXER:Current/InCh/Fader/On '+ opt.Ch + ' 0 0';
newAction = 186;
action.options.X = actions.options.Ch;
action.options.Val = 0;
break;
case 'InChLevel':
// cmd = 'set MIXER:Current/InCh/Fader/Level ' + opt.Ch + ' 0 ' + opt.ChAct;
newAction = 184;
action.options.X = action.options.Ch;
action.options.Val = action.options.ChAct;
break;
case 'AuxOn', 'MixOn':
// cmd = 'set MIXER:Current/Mix/Fader/On '+ opt.Ch + ' 0 1';
newAction = 187;
action.options.X = action.options.Ch;
action.options.Val = 1;
break;
case 'AuxOff', 'MixOff':
// cmd = 'set MIXER:Current/Mix/Fader/On '+ opt.Ch + ' 0 0';
newAction = 187;
action.options.X = action.options.Ch;
action.options.Val = 0;
break;
case 'AuxLevel', 'MixLevel':
// cmd = 'set MIXER:Current/Mix/Fader/Level ' + opt.Ch + ' 0 ' + opt.ChAct;
newAction = 185;
action.options.X = action.options.Ch;
action.options.Val = action.options.ChAct;
break;
case 'MtrxOn':
// cmd = 'set MIXER:Current/Mtrx/Fader/On '+ opt.Ch + ' 0 1';
newAction = 7;
action.options.X = action.options.Ch;
action.options.Val = 1;
break;
case 'MtrxOff':
// cmd = 'set MIXER:Current/Mtrx/Fader/On '+ opt.Ch + ' 0 0';
newAction = 7;
action.options.X = action.options.Ch;
action.options.Val = 0;
break;
case 'MtrxLevel':
// cmd = 'set MIXER:Current/Mtrx/Fader/Level ' + opt.Ch + ' 0 ' + opt.ChAct;
newAction = 2;
action.options.X = action.options.Ch;
action.options.Val = action.options.ChAct;
break;
case 'TFRecall':
// cmd = 'ssrecall_ex scene_'+ opt.Bank + ' ' + opt.Scene;
newAction = 1000;
action.options.X = action.options.Scene;
action.options.Y = action.options.Bank;
break;
case 'CLQLRecall':
// cmd = 'ssrecall_ex MIXER:Lib/Scene ' + opt.Scene;
newAction = 1000;
action.options.X = action.options.Scene;
break;
}

if(newAction != '') {
console.log(`Action ${action.action} => scp_${newAction}`);
action.action = 'scp_' + newAction;
action.label = this.id + ':' + action.action;
changed = true;
}

return changed;
}

for (let k in actions) {
changed = checkUpgrade(actions[k], changed);
module.exports = [
// Upgrade 1.0.x > 1.1.0
function (context, config, actions, feedbacks) {
var changed = false;
console.log('Running 1.1.1 -> 1.1.2 Upgrade.')

let checkUpgrade = function(action, changed) {
let newAction = '';

switch (action.action) {
case 'InChOn':
// cmd = 'set MIXER:Current/InCh/Fader/On '+ opt.Ch + ' 0 1';
newAction = 186;
action.options.X = actions.options.Ch;
action.options.Val = 1;
break;
case 'InChOff':
// cmd = 'set MIXER:Current/InCh/Fader/On '+ opt.Ch + ' 0 0';
newAction = 186;
action.options.X = actions.options.Ch;
action.options.Val = 0;
break;
case 'InChLevel':
// cmd = 'set MIXER:Current/InCh/Fader/Level ' + opt.Ch + ' 0 ' + opt.ChAct;
newAction = 184;
action.options.X = action.options.Ch;
action.options.Val = action.options.ChAct;
break;
case 'AuxOn', 'MixOn':
// cmd = 'set MIXER:Current/Mix/Fader/On '+ opt.Ch + ' 0 1';
newAction = 187;
action.options.X = action.options.Ch;
action.options.Val = 1;
break;
case 'AuxOff', 'MixOff':
// cmd = 'set MIXER:Current/Mix/Fader/On '+ opt.Ch + ' 0 0';
newAction = 187;
action.options.X = action.options.Ch;
action.options.Val = 0;
break;
case 'AuxLevel', 'MixLevel':
// cmd = 'set MIXER:Current/Mix/Fader/Level ' + opt.Ch + ' 0 ' + opt.ChAct;
newAction = 185;
action.options.X = action.options.Ch;
action.options.Val = action.options.ChAct;
break;
case 'MtrxOn':
// cmd = 'set MIXER:Current/Mtrx/Fader/On '+ opt.Ch + ' 0 1';
newAction = 7;
action.options.X = action.options.Ch;
action.options.Val = 1;
break;
case 'MtrxOff':
// cmd = 'set MIXER:Current/Mtrx/Fader/On '+ opt.Ch + ' 0 0';
newAction = 7;
action.options.X = action.options.Ch;
action.options.Val = 0;
break;
case 'MtrxLevel':
// cmd = 'set MIXER:Current/Mtrx/Fader/Level ' + opt.Ch + ' 0 ' + opt.ChAct;
newAction = 2;
action.options.X = action.options.Ch;
action.options.Val = action.options.ChAct;
break;
case 'TFRecall':
// cmd = 'ssrecall_ex scene_'+ opt.Bank + ' ' + opt.Scene;
newAction = 1000;
action.options.X = action.options.Scene;
action.options.Y = action.options.Bank;
break;
case 'CLQLRecall':
// cmd = 'ssrecall_ex MIXER:Lib/Scene ' + opt.Scene;
newAction = 1000;
action.options.X = action.options.Scene;
break;
}

for (let k in releaseActions) {
changed = checkUpgrade(releaseActions[k], changed);
if(newAction != '') {
console.log(`Action ${action.action} => scp_${newAction}`);
action.action = 'scp_' + newAction;
changed = true;
}

return changed;
});
}

// Upgrade 1.1.2 > 1.1.3
this.addUpgradeScript((config, actions, releaseActions, feedbacks) => {
console.log('Running 1.1.2 -> 1.1.3 Upgrade.')
var changed = false;
for (let k in actions) {
changed = checkUpgrade(actions[k], changed);
}

let checkUpgrade = function(action, changed) {
let newAction = '';
return changed;
},

if(action.action.substring(0, 4) != 'scp_') {
newAction = action.action;
}
// Upgrade 1.1.2 > 1.1.3
function (context, config, actions, feedbacks) {
console.log('Running 1.1.2 -> 1.1.3 Upgrade.')
var changed = false;

if(newAction != '') {
console.log(`Action ${action.action} => scp_${newAction}`);
action.action = 'scp_' + newAction;
action.label = this.id + ':' + action.action;
changed = true;
}
let checkUpgrade = function(action, changed) {
let newAction = '';

return changed;
}
if(action.action.substring(0, 4) != 'scp_') {
newAction = action.action;
}

for (let k in actions) {
changed = checkUpgrade(actions[k], changed);
if(newAction != '') {
console.log(`Action ${action.action} => scp_${newAction}`);
action.action = 'scp_' + newAction;
changed = true;
}

for (let k in releaseActions) {
changed = checkUpgrade(releaseActions[k], changed);
}
return changed;
}

for (let k in feedbacks) {
changed = checkUpgrade(feedbacks[k], changed);
}
for (let k in actions) {
changed = checkUpgrade(actions[k], changed);
}

return changed;
})
}
}

for (let k in feedbacks) {
changed = checkUpgrade(feedbacks[k], changed);
}

return changed;
},
]

0 comments on commit 02f1133

Please sign in to comment.