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": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/api.js"
"program": "${workspaceFolder}/pbc.js"
}
]
}

View file

@ -27,15 +27,22 @@ function getBanks() {
return resolve(banks);
}
// 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 }] }];
for (var index = 0; index < fake.length; index++) {
fake.id = index;
}
banks = util.sortById(fake);
return resolve(fake);
// 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++) {
// fake.id = index;
// }
// banks = util.sortById(fake);
// return resolve(fake);
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);
});
}
@ -46,10 +53,26 @@ function getPedalboards() {
return resolve(pedalboards);
}
// 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;
for (var index = 0; index < fake.length; index++) {
var pedalboard = fake[index];
for (var index = 0; index < data.length; index++) {
var pedalboard = data[index];
if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) {
pedalboard.id = 0;
defaultPedalboard = pedalboard;
@ -58,12 +81,8 @@ function getPedalboards() {
pedalboard.id = id;
id++;
}
pedalboards = util.sortById(fake);
return resolve(fake);
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/list')
.then(function (pedalboards) {
pedalboards = util.sortById(data);
return resolve(pedalboards);
})
.catch(reject);
});
@ -86,23 +105,24 @@ function getCurrentPedalboard() {
return resolve(currentPedalboard);
}
// FAKE DATA
var fake = '/var/modep/pedalboards/FUZZ.pedalboard';
getPedalboardByBundle(fake)
.then(function (pedalboard) {
currentPedalboard = pedalboard;
return resolve(pedalboard);
})
.catch(reject);
// var fake = '/var/modep/pedalboards/FUZZ.pedalboard';
// getPedalboardByBundle(fake)
// .then(function (pedalboard) {
// currentPedalboard = pedalboard;
// return resolve(pedalboard);
// })
// .catch(reject);
// PRODUCTION
// util.httpGET(config.modep.host, config.modep.port, '/pedalboard/current')
// .then(getPedalboardByBundle)
// .then(resolve)
// .catch(reject);
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/current')
.then(getPedalboardByBundle)
.then(resolve)
.catch(reject);
});
}
function getPedalboardById(pedalboardId) {
function
getPedalboardById(pedalboardId) {
return new Promise(function (resolve, reject) {
getPedalboards()
.then(function (pedalboards) {
@ -122,6 +142,11 @@ function getPedalboardByBundle(pedalboardBundle) {
return new Promise(function (resolve, reject) {
getPedalboards()
.then(function (pedalboards) {
if (!pedalboardBundle) {
return getDefaultPedalboard()
.then(resolve)
.catch(reject);
}
for (var index = 0; index < pedalboards.length; index++) {
if (pedalboards[index].bundle != pedalboardBundle) {
continue;
@ -153,7 +178,7 @@ function getPedalControlById(pedalId, controlId) {
function getCurrentPedalById(id) {
return new Promise(function (resolve, reject) {
getCurrentPedals()
.then(function () {
.then(function (currentPedals) {
for (var index = 0; index < currentPedals.length; index++) {
if (currentPedals[index].id != id) {
continue;
@ -178,20 +203,15 @@ function getCurrentPedals() {
});
}
function parseCurrentPedalboard(pedalboardBundle) {
function parseCurrentPedalboard(currentPedalboard) {
return new Promise(function (resolve, reject) {
getDefaultPedalboard()
.then(function (defaultPedalboard) {
if (defaultPedalboard.id == currentPedalboard.id) {
return resolve([]);
}
var startTime = new Date();
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) {
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')
resolve(currentPedals);
});
}).catch(reject);
});
}
@ -306,12 +327,19 @@ function setPedalboard(pedalboard) {
if (pedalboard.id == currentPedalboard.id) {
return resolve('pedalboard \'' + pedalboard.id + '\' is already active');
}
logger.debug("DERP")
reset()
.then(function () {
util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle)
})
.then(getCurrentPedalboard)
.catch(reject);
.then(logger.debug("RESETTED"))
.catch(logger.error);
// 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 () {
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) {