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,10 +53,26 @@ 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;
// for (var index = 0; index < fake.length; index++) {
// var pedalboard = fake[index];
// if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) {
// pedalboard.id = 0;
// defaultPedalboard = pedalboard;
// continue;
// }
// pedalboard.id = id;
// id++;
// }
// pedalboards = util.sortById(fake);
// return resolve(fake);
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/list')
.then(function (data) {
var id = 1; var id = 1;
for (var index = 0; index < fake.length; index++) { for (var index = 0; index < data.length; index++) {
var pedalboard = fake[index]; var pedalboard = data[index];
if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) { if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) {
pedalboard.id = 0; pedalboard.id = 0;
defaultPedalboard = pedalboard; defaultPedalboard = pedalboard;
@ -58,12 +81,8 @@ function getPedalboards() {
pedalboard.id = id; pedalboard.id = id;
id++; id++;
} }
pedalboards = util.sortById(fake); pedalboards = util.sortById(data);
return resolve(fake); return resolve(pedalboards);
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/list')
.then(function (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,20 +203,15 @@ function getCurrentPedals() {
}); });
} }
function parseCurrentPedalboard(pedalboardBundle) { function parseCurrentPedalboard(currentPedalboard) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
getDefaultPedalboard()
.then(function (defaultPedalboard) {
if (defaultPedalboard.id == currentPedalboard.id) {
return resolve([]);
}
var startTime = new Date(); var startTime = new Date();
logger.debug('parsing current pedalboard...'); logger.debug('parsing current pedalboard...');
if (!currentPedalboard || !currentPedalboard.uri) {
for (var index = 0; index < pedalboards.length; index++) {
var pedalboard = pedalboards[index];
if (!pedalboard.bundle || pedalboardBundle != pedalboard.bundle) {
continue;
}
currentPedalboard = pedalboard;
break;
};
}
if (!currentPedalboard.uri) { if (!currentPedalboard.uri) {
reject('error: could not determine current pedalboard config file'); reject('error: could not determine current pedalboard config file');
} }
@ -251,6 +271,7 @@ function parseCurrentPedalboard(pedalboardBundle) {
logger.debug('parsing current pedalboard file \'' + file + '\' took ' + util.timeDiff(startTime) + 'ms') logger.debug('parsing current pedalboard file \'' + file + '\' took ' + util.timeDiff(startTime) + 'ms')
resolve(currentPedals); 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) {