removed debug / development stuff

This commit is contained in:
Daniel Sommer 2022-02-07 16:56:18 +01:00
parent 3705d8cca7
commit e7fb5dc68c
3 changed files with 143 additions and 112 deletions

2
.vscode/launch.json vendored
View file

@ -8,7 +8,7 @@
"skipFiles": [ "skipFiles": [
"<node_internals>/**" "<node_internals>/**"
], ],
"program": "${workspaceFolder}/api.js" "program": "${workspaceFolder}/pbc.js"
} }
] ]
} }

View file

@ -27,15 +27,22 @@ function getBanks() {
return resolve(banks); return resolve(banks);
} }
// FAKE DATA // FAKE DATA
var fake = [{ "title": "The Button", "pedalboards": [{ "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/default.pedalboard/default.ttl", "bundle": "/var/modep/pedalboards/default.pedalboard", "title": "Default", "version": 0 }, { "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/FUZZ.pedalboard/FUZZ.ttl", "bundle": "/var/modep/pedalboards/FUZZ.pedalboard", "title": "FUZZ", "version": 1 }] }]; // var fake = [{ "title": "The Button", "pedalboards": [{ "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/default.pedalboard/default.ttl", "bundle": "/var/modep/pedalboards/default.pedalboard", "title": "Default", "version": 0 }, { "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/FUZZ.pedalboard/FUZZ.ttl", "bundle": "/var/modep/pedalboards/FUZZ.pedalboard", "title": "FUZZ", "version": 1 }] }];
for (var index = 0; index < fake.length; index++) { // for (var index = 0; index < fake.length; index++) {
fake.id = index; // fake.id = index;
} // }
banks = util.sortById(fake); // banks = util.sortById(fake);
return resolve(fake); // return resolve(fake);
util.httpGET(config.modep.host, config.modep.port, '/banks') util.httpGET(config.modep.host, config.modep.port, '/banks')
.then(resolve) .then(function (banks) {
for (var index = 0; index < banks.length; index++) {
var bank = banks[index];
bank.id = index;
}
banks = util.sortById(banks);
return resolve(banks);
})
.catch(reject); .catch(reject);
}); });
} }
@ -46,24 +53,36 @@ function getPedalboards() {
return resolve(pedalboards); return resolve(pedalboards);
} }
// FAKE DATA // FAKE DATA
var fake = [{ "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/FUZZ.pedalboard/FUZZ.ttl", "bundle": "/var/modep/pedalboards/FUZZ.pedalboard", "title": "FUZZ", "version": 1 }, { "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/default.pedalboard/default.ttl", "bundle": "/var/modep/pedalboards/default.pedalboard", "title": "Default", "version": 0 }]; // var fake = [{ "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/FUZZ.pedalboard/FUZZ.ttl", "bundle": "/var/modep/pedalboards/FUZZ.pedalboard", "title": "FUZZ", "version": 1 }, { "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/default.pedalboard/default.ttl", "bundle": "/var/modep/pedalboards/default.pedalboard", "title": "Default", "version": 0 }];
var id = 1; // var id = 1;
for (var index = 0; index < fake.length; index++) { // for (var index = 0; index < fake.length; index++) {
var pedalboard = fake[index]; // var pedalboard = fake[index];
if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) { // if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) {
pedalboard.id = 0; // pedalboard.id = 0;
defaultPedalboard = pedalboard; // defaultPedalboard = pedalboard;
continue; // continue;
} // }
pedalboard.id = id; // pedalboard.id = id;
id++; // id++;
} // }
pedalboards = util.sortById(fake); // pedalboards = util.sortById(fake);
return resolve(fake); // return resolve(fake);
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/list') util.httpGET(config.modep.host, config.modep.port, '/pedalboard/list')
.then(function (pedalboards) { .then(function (data) {
var id = 1;
for (var index = 0; index < data.length; index++) {
var pedalboard = data[index];
if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) {
pedalboard.id = 0;
defaultPedalboard = pedalboard;
continue;
}
pedalboard.id = id;
id++;
}
pedalboards = util.sortById(data);
return resolve(pedalboards);
}) })
.catch(reject); .catch(reject);
}); });
@ -86,23 +105,24 @@ function getCurrentPedalboard() {
return resolve(currentPedalboard); return resolve(currentPedalboard);
} }
// FAKE DATA // FAKE DATA
var fake = '/var/modep/pedalboards/FUZZ.pedalboard'; // var fake = '/var/modep/pedalboards/FUZZ.pedalboard';
getPedalboardByBundle(fake) // getPedalboardByBundle(fake)
.then(function (pedalboard) { // .then(function (pedalboard) {
currentPedalboard = pedalboard; // currentPedalboard = pedalboard;
return resolve(pedalboard); // return resolve(pedalboard);
}) // })
.catch(reject); // .catch(reject);
// PRODUCTION // PRODUCTION
// util.httpGET(config.modep.host, config.modep.port, '/pedalboard/current') util.httpGET(config.modep.host, config.modep.port, '/pedalboard/current')
// .then(getPedalboardByBundle) .then(getPedalboardByBundle)
// .then(resolve) .then(resolve)
// .catch(reject); .catch(reject);
}); });
} }
function getPedalboardById(pedalboardId) { function
getPedalboardById(pedalboardId) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
getPedalboards() getPedalboards()
.then(function (pedalboards) { .then(function (pedalboards) {
@ -122,6 +142,11 @@ function getPedalboardByBundle(pedalboardBundle) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
getPedalboards() getPedalboards()
.then(function (pedalboards) { .then(function (pedalboards) {
if (!pedalboardBundle) {
return getDefaultPedalboard()
.then(resolve)
.catch(reject);
}
for (var index = 0; index < pedalboards.length; index++) { for (var index = 0; index < pedalboards.length; index++) {
if (pedalboards[index].bundle != pedalboardBundle) { if (pedalboards[index].bundle != pedalboardBundle) {
continue; continue;
@ -153,7 +178,7 @@ function getPedalControlById(pedalId, controlId) {
function getCurrentPedalById(id) { function getCurrentPedalById(id) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
getCurrentPedals() getCurrentPedals()
.then(function () { .then(function (currentPedals) {
for (var index = 0; index < currentPedals.length; index++) { for (var index = 0; index < currentPedals.length; index++) {
if (currentPedals[index].id != id) { if (currentPedals[index].id != id) {
continue; continue;
@ -178,79 +203,75 @@ function getCurrentPedals() {
}); });
} }
function parseCurrentPedalboard(pedalboardBundle) { function parseCurrentPedalboard(currentPedalboard) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var startTime = new Date(); getDefaultPedalboard()
logger.debug('parsing current pedalboard...'); .then(function (defaultPedalboard) {
if (!currentPedalboard || !currentPedalboard.uri) { if (defaultPedalboard.id == currentPedalboard.id) {
for (var index = 0; index < pedalboards.length; index++) { return resolve([]);
var pedalboard = pedalboards[index];
if (!pedalboard.bundle || pedalboardBundle != pedalboard.bundle) {
continue;
} }
currentPedalboard = pedalboard; var startTime = new Date();
break; logger.debug('parsing current pedalboard...');
}; if (!currentPedalboard.uri) {
} reject('error: could not determine current pedalboard config file');
if (!currentPedalboard.uri) {
reject('error: could not determine current pedalboard config file');
}
// FAKE DATA
var file = path.resolve('./dev/FUZZ.ttl');
// var file = path.resolve(currentPedalboard.uri.replace('file://', ''));
fs.readFile(file, function (err, data) {
if (err) {
return reject('error: could not parse current pedalboard file \'' + file + '\' >>> ' + err);
}
currentPedals = [];
var json = ttl2jsonld(data.toString())['@graph'];
var id = 0;
for (var index = 0; index < json.length; index++) {
var tmp = json[index];
if (!tmp['lv2:prototype']) {
continue;
} }
var name = tmp['@id']; // FAKE DATA
currentPedals.push({ id: id, name: name, controls: [] }); var file = path.resolve('./dev/FUZZ.ttl');
id++; // var file = path.resolve(currentPedalboard.uri.replace('file://', ''));
} fs.readFile(file, function (err, data) {
for (var index = 0; index < json.length; index++) { if (err) {
var tmp = json[index]; return reject('error: could not parse current pedalboard file \'' + file + '\' >>> ' + err);
var name = tmp['@id'];
var value = tmp['ingen:value'];
if (value == undefined) {
continue;
}
var pedal = undefined;
for (var pedalIndex = 0; pedalIndex < currentPedals.length; pedalIndex++) {
if (!name.startsWith(currentPedals[pedalIndex].name)) {
continue;
} }
pedal = currentPedals[pedalIndex]; currentPedals = [];
break; var json = ttl2jsonld(data.toString())['@graph'];
} var id = 0;
if (!pedal) { for (var index = 0; index < json.length; index++) {
continue; var tmp = json[index];
} if (!tmp['lv2:prototype']) {
id = pedal.controls.length; continue;
name = name.replace(pedal.name + '/', ''); }
if (name == ':bypass') { var name = tmp['@id'];
value = value; currentPedals.push({ id: id, name: name, controls: [] });
} else { id++;
value = value['@value']; }
} for (var index = 0; index < json.length; index++) {
var control = { id: id, name: name, value: value }; var tmp = json[index];
pedal.controls.push(control); var name = tmp['@id'];
id++; var value = tmp['ingen:value'];
var midi = tmp['midi:binding']; if (value == undefined) {
if (!midi) { continue;
continue; }
} var pedal = undefined;
control.midi = { channel: midi['midi:channel'], controller: midi['midi:controllerNumber'] } for (var pedalIndex = 0; pedalIndex < currentPedals.length; pedalIndex++) {
} if (!name.startsWith(currentPedals[pedalIndex].name)) {
logger.debug('parsing current pedalboard file \'' + file + '\' took ' + util.timeDiff(startTime) + 'ms') continue;
resolve(currentPedals); }
}); pedal = currentPedals[pedalIndex];
break;
}
if (!pedal) {
continue;
}
id = pedal.controls.length;
name = name.replace(pedal.name + '/', '');
if (name == ':bypass') {
value = value;
} else {
value = value['@value'];
}
var control = { id: id, name: name, value: value };
pedal.controls.push(control);
id++;
var midi = tmp['midi:binding'];
if (!midi) {
continue;
}
control.midi = { channel: midi['midi:channel'], controller: midi['midi:controllerNumber'] }
}
logger.debug('parsing current pedalboard file \'' + file + '\' took ' + util.timeDiff(startTime) + 'ms')
resolve(currentPedals);
});
}).catch(reject);
}); });
} }
@ -306,12 +327,19 @@ function setPedalboard(pedalboard) {
if (pedalboard.id == currentPedalboard.id) { if (pedalboard.id == currentPedalboard.id) {
return resolve('pedalboard \'' + pedalboard.id + '\' is already active'); return resolve('pedalboard \'' + pedalboard.id + '\' is already active');
} }
logger.debug("DERP")
reset() reset()
.then(function () { .then(logger.debug("RESETTED"))
util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle) .catch(logger.error);
})
.then(getCurrentPedalboard)
.catch(reject); // reset()
// .then(function () {
// util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle)
// })
// .then(getCurrentPedalboard)
// .catch(reject);
}); });
} }

View file

@ -47,7 +47,10 @@ function httpRequest(host, port, path, method, args) {
}); });
response.on('end', function () { response.on('end', function () {
logger.debug('http \'' + method + '\' request \'' + host + ':' + port + path + '\' returned data \'' + responseData + '\''); logger.debug('http \'' + method + '\' request \'' + host + ':' + port + path + '\' returned data \'' + responseData + '\'');
return resolve(responseData); if (!responseData) {
return resolve();
}
return resolve(JSON.parse(responseData));
}); });
}); });
request.on('error', function (err) { request.on('error', function (err) {