cache bypassed pedalboards - currently wip

This commit is contained in:
Daniel Sommer 2022-03-24 16:30:00 +01:00
parent 2ee5bedf79
commit 72edb1a159
5 changed files with 81 additions and 30 deletions

View file

@ -92,8 +92,8 @@ _:b10
<BigMuffPi/:bypass> <BigMuffPi/:bypass>
ingen:value 1 ; ingen:value 1 ;
midi:binding [ midi:binding [
midi:channel 0 ; midi:channel 1 ;
midi:controllerNumber 0 ; midi:controllerNumber 2 ;
a midi:Controller ; a midi:Controller ;
] ; ] ;
a lv2:ControlPort , a lv2:ControlPort ,

View file

@ -45,6 +45,7 @@ async function setActive(active) {
} }
async function setPedalStatus(pedal) { async function setPedalStatus(pedal) {
try {
if (!enabled || pedal === undefined || pedal.controls === undefined) { if (!enabled || pedal === undefined || pedal.controls === undefined) {
return; return;
} }
@ -53,7 +54,7 @@ async function setPedalStatus(pedal) {
if (bypass.name !== CONTROL_BYPASS) { if (bypass.name !== CONTROL_BYPASS) {
continue; continue;
} }
return httpPOST( await httpPOST(
global.config.blinky.host, global.config.blinky.host,
global.config.blinky.port, global.config.blinky.port,
'set', 'set',
@ -64,6 +65,9 @@ async function setPedalStatus(pedal) {
} }
); );
} }
} catch (err) {
logger.error('[BLINKY] ' + err);
}
} }
async function setStatus(pedals) { async function setStatus(pedals) {

View file

@ -61,7 +61,7 @@ function validLifetime(timestamp) {
} }
function getValue(key) { function getValue(key) {
var value = cache.get(key); let value = cache.get(key);
if (value === undefined) { if (value === undefined) {
return undefined; return undefined;
} }
@ -156,6 +156,38 @@ function setInfo(value) {
setValue(constants.CACHE_INFO, value); setValue(constants.CACHE_INFO, value);
} }
function setBypassedPedal(pedalId) {
if (isPedalBypassed(pedalId)) {
return;
}
let bypassedPedals = cache.get(constants.CACHE_PEDALS_BYPASSED);
if (bypassedPedals === undefined) {
bypassedPedals = [];
}
bypassedPedals.push(pedalId);
cache.set(constants.CACHE_PEDALS_BYPASSED, bypassedPedals);
}
function isPedalBypassed(pedalId) {
let bypassedPedals = cache.get(constants.CACHE_PEDALS_BYPASSED);
if (bypassedPedals === undefined) {
return;
}
return bypassedPedals.includes(pedalId);
}
function removeBypassedPedal(pedalId) {
if (!isPedalBypassed(pedalId)) {
return;
}
let bypassedPedals = cache.get(constants.CACHE_PEDALS_BYPASSED);
bypassedPedals.splice(bypassedPedals.indexOf(pedalId), 1);
}
function clearBypassedPedals() {
cache.delete(constants.CACHE_PEDALS_BYPASSED);
}
module.exports = { module.exports = {
isActive, isActive,
getLifetime, getLifetime,
@ -178,5 +210,9 @@ module.exports = {
setCurrentPedals, setCurrentPedals,
getInfo, getInfo,
clearInfo, clearInfo,
setInfo setInfo,
setBypassedPedal,
isPedalBypassed,
removeBypassedPedal,
clearBypassedPedals
} }

View file

@ -40,6 +40,7 @@ exports.CACHE_PEDALBOARDS = "pedalboards";
exports.CACHE_PEDALBOARD_DEFAULT = "pedalboard_default"; exports.CACHE_PEDALBOARD_DEFAULT = "pedalboard_default";
exports.CACHE_PEDALBOARD_CURRENT = "pedalboard_current"; exports.CACHE_PEDALBOARD_CURRENT = "pedalboard_current";
exports.CACHE_PEDALS = "pedals"; exports.CACHE_PEDALS = "pedals";
exports.CACHE_PEDALS_BYPASSED = "pedals_bypassed"
exports.PEDALBOARD_DEFAULT = '/var/modep/pedalboards/default.pedalboard'; exports.PEDALBOARD_DEFAULT = '/var/modep/pedalboards/default.pedalboard';

View file

@ -241,8 +241,8 @@ async function parseCurrentPedalboard(currentPedalboard) {
throw new Error('could not determine current pedalboard config file'); throw new Error('could not determine current pedalboard config file');
} }
// FAKE DATA // FAKE DATA
// let file = path.resolve(path.dirname(__dirname) + '/dev/' + currentPedalboard.uri.substring(currentPedalboard.uri.lastIndexOf('/') + 1)); let file = path.resolve(path.dirname(__dirname) + '/dev/' + currentPedalboard.uri.substring(currentPedalboard.uri.lastIndexOf('/') + 1));
let file = path.resolve(currentPedalboard.uri.replace('file://', '')); // let file = path.resolve(currentPedalboard.uri.replace('file://', ''));
pedals = await new Promise((resolve, reject) => { pedals = await new Promise((resolve, reject) => {
fs.readFile(file, function (err, data) { fs.readFile(file, function (err, data) {
if (err) { if (err) {
@ -426,16 +426,26 @@ async function toggleBypass(pedalId) {
} }
return; return;
} }
// TODO: Cache aktualisieren mit An/Aus-Wert const pedal = await getCurrentPedalById(pedalId);
let pedal = await getCurrentPedalById(pedalId); const bypass = getBypassControlFromPedal(pedal);
let bypass = getBypassControlFromPedal(pedal); const bypassState = cache.isPedalBypassed(pedal.id);
if (bypass.value === undefined || bypass.value === 0) { let value = 0;
bypass.value = 0; if (bypassState === true) {
} else { value = 127;
bypass.value = 127; } else if (bypassState === false) {
value = 0;
} else if (bypassState === undefined) {
if (bypass.value !== undefined && bypass.value !== 0) {
value = 127;
}
} }
try { try {
await setControl(bypass, bypass.value); await setControl(bypass, value);
if (value === 0) {
cache.setBypassedPedal(pedal.id);
} else {
cache.removeBypassedPedal(pedal.id);
}
blinky.setPedalStatus(pedal); blinky.setPedalStatus(pedal);
} catch (err) { } catch (err) {
throw new Error('could not toggle bypass for pedal ' + pedal.name + ' with id \'' + pedal.id + '\' > ' + err); throw new Error('could not toggle bypass for pedal ' + pedal.name + ' with id \'' + pedal.id + '\' > ' + err);