cache bypassed pedalboards - currently wip
This commit is contained in:
parent
2ee5bedf79
commit
72edb1a159
5 changed files with 81 additions and 30 deletions
|
@ -92,8 +92,8 @@ _:b10
|
|||
<BigMuffPi/:bypass>
|
||||
ingen:value 1 ;
|
||||
midi:binding [
|
||||
midi:channel 0 ;
|
||||
midi:controllerNumber 0 ;
|
||||
midi:channel 1 ;
|
||||
midi:controllerNumber 2 ;
|
||||
a midi:Controller ;
|
||||
] ;
|
||||
a lv2:ControlPort ,
|
||||
|
|
|
@ -45,6 +45,7 @@ async function setActive(active) {
|
|||
}
|
||||
|
||||
async function setPedalStatus(pedal) {
|
||||
try {
|
||||
if (!enabled || pedal === undefined || pedal.controls === undefined) {
|
||||
return;
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ async function setPedalStatus(pedal) {
|
|||
if (bypass.name !== CONTROL_BYPASS) {
|
||||
continue;
|
||||
}
|
||||
return httpPOST(
|
||||
await httpPOST(
|
||||
global.config.blinky.host,
|
||||
global.config.blinky.port,
|
||||
'set',
|
||||
|
@ -64,6 +65,9 @@ async function setPedalStatus(pedal) {
|
|||
}
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('[BLINKY] ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
async function setStatus(pedals) {
|
||||
|
|
|
@ -61,7 +61,7 @@ function validLifetime(timestamp) {
|
|||
}
|
||||
|
||||
function getValue(key) {
|
||||
var value = cache.get(key);
|
||||
let value = cache.get(key);
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -156,6 +156,38 @@ function setInfo(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 = {
|
||||
isActive,
|
||||
getLifetime,
|
||||
|
@ -178,5 +210,9 @@ module.exports = {
|
|||
setCurrentPedals,
|
||||
getInfo,
|
||||
clearInfo,
|
||||
setInfo
|
||||
setInfo,
|
||||
setBypassedPedal,
|
||||
isPedalBypassed,
|
||||
removeBypassedPedal,
|
||||
clearBypassedPedals
|
||||
}
|
|
@ -40,6 +40,7 @@ exports.CACHE_PEDALBOARDS = "pedalboards";
|
|||
exports.CACHE_PEDALBOARD_DEFAULT = "pedalboard_default";
|
||||
exports.CACHE_PEDALBOARD_CURRENT = "pedalboard_current";
|
||||
exports.CACHE_PEDALS = "pedals";
|
||||
exports.CACHE_PEDALS_BYPASSED = "pedals_bypassed"
|
||||
|
||||
exports.PEDALBOARD_DEFAULT = '/var/modep/pedalboards/default.pedalboard';
|
||||
|
||||
|
|
|
@ -241,8 +241,8 @@ async function parseCurrentPedalboard(currentPedalboard) {
|
|||
throw new Error('could not determine current pedalboard config file');
|
||||
}
|
||||
// FAKE DATA
|
||||
// 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(path.dirname(__dirname) + '/dev/' + currentPedalboard.uri.substring(currentPedalboard.uri.lastIndexOf('/') + 1));
|
||||
// let file = path.resolve(currentPedalboard.uri.replace('file://', ''));
|
||||
pedals = await new Promise((resolve, reject) => {
|
||||
fs.readFile(file, function (err, data) {
|
||||
if (err) {
|
||||
|
@ -426,16 +426,26 @@ async function toggleBypass(pedalId) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
// TODO: Cache aktualisieren mit An/Aus-Wert
|
||||
let pedal = await getCurrentPedalById(pedalId);
|
||||
let bypass = getBypassControlFromPedal(pedal);
|
||||
if (bypass.value === undefined || bypass.value === 0) {
|
||||
bypass.value = 0;
|
||||
} else {
|
||||
bypass.value = 127;
|
||||
const pedal = await getCurrentPedalById(pedalId);
|
||||
const bypass = getBypassControlFromPedal(pedal);
|
||||
const bypassState = cache.isPedalBypassed(pedal.id);
|
||||
let value = 0;
|
||||
if (bypassState === true) {
|
||||
value = 127;
|
||||
} else if (bypassState === false) {
|
||||
value = 0;
|
||||
} else if (bypassState === undefined) {
|
||||
if (bypass.value !== undefined && bypass.value !== 0) {
|
||||
value = 127;
|
||||
}
|
||||
}
|
||||
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);
|
||||
} catch (err) {
|
||||
throw new Error('could not toggle bypass for pedal ' + pedal.name + ' with id \'' + pedal.id + '\' > ' + err);
|
||||
|
|
Loading…
Reference in a new issue