2022-02-07 15:41:27 +01:00
|
|
|
const util = require('./util.js');
|
|
|
|
const constants = require('./constants.js');
|
|
|
|
const logger = require('./logger.js');
|
2022-02-08 14:07:59 +01:00
|
|
|
const cache = require('./cache.js');
|
2022-02-11 01:20:53 +01:00
|
|
|
const commands = require('./commands.js');
|
2022-03-08 00:51:58 +01:00
|
|
|
const blinky = require('./blinky.js');
|
2022-03-11 16:52:37 +01:00
|
|
|
const osc = require('./osc.js');
|
2022-02-07 15:41:27 +01:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const ttl2jsonld = require('@frogcat/ttl2jsonld').parse;
|
|
|
|
|
2022-03-08 00:51:58 +01:00
|
|
|
let pedalboardIdBypassOrigin;
|
|
|
|
|
2022-02-07 15:41:27 +01:00
|
|
|
function reset() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-24 12:50:16 +01:00
|
|
|
util.httpGET(global.config.modep.host, global.config.modep.port, '/reset')
|
2022-02-07 15:41:27 +01:00
|
|
|
.then(resolve)
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBanks() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let banks = cache.getBanks();
|
2022-02-07 23:50:16 +01:00
|
|
|
if (banks != undefined) {
|
2022-02-07 15:41:27 +01:00
|
|
|
return resolve(banks);
|
|
|
|
}
|
2022-03-24 12:50:16 +01:00
|
|
|
util.httpGET(global.config.modep.host, global.config.modep.port, '/banks')
|
2022-02-07 16:56:18 +01:00
|
|
|
.then(function (banks) {
|
2022-03-08 00:51:58 +01:00
|
|
|
for (let index = 0; index < banks.length; index++) {
|
|
|
|
let bank = banks[index];
|
2022-02-07 16:56:18 +01:00
|
|
|
bank.id = index;
|
|
|
|
}
|
|
|
|
banks = util.sortById(banks);
|
2022-02-08 14:07:59 +01:00
|
|
|
cache.setBanks(banks);
|
2022-02-07 16:56:18 +01:00
|
|
|
return resolve(banks);
|
|
|
|
})
|
2022-02-07 15:41:27 +01:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-07 23:50:16 +01:00
|
|
|
function getBankById(bankId) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
getBanks()
|
|
|
|
.then(function (banks) {
|
2022-03-08 00:51:58 +01:00
|
|
|
for (let index = 0; index < banks.length; index++) {
|
2022-02-07 23:50:16 +01:00
|
|
|
if (banks[index].id != bankId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return resolve(banks[index]);
|
|
|
|
}
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('could not find bank by id \'' + bankId + '\'');
|
2022-02-07 23:50:16 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-07 15:41:27 +01:00
|
|
|
function getPedalboards() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let pedalboards = cache.getPedalboards();
|
2022-02-07 23:50:16 +01:00
|
|
|
if (pedalboards != undefined) {
|
2022-02-07 15:41:27 +01:00
|
|
|
return resolve(pedalboards);
|
|
|
|
}
|
2022-03-24 12:50:16 +01:00
|
|
|
util.httpGET(global.config.modep.host, global.config.modep.port, '/pedalboard/list')
|
2022-02-08 14:07:59 +01:00
|
|
|
.then(function (pedalboards) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let id = 1;
|
|
|
|
for (let index = 0; index < pedalboards.length; index++) {
|
|
|
|
let pedalboard = pedalboards[index];
|
2022-02-07 16:56:18 +01:00
|
|
|
if (pedalboard.bundle == constants.PEDALBOARD_DEFAULT) {
|
|
|
|
pedalboard.id = 0;
|
|
|
|
defaultPedalboard = pedalboard;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pedalboard.id = id;
|
|
|
|
id++;
|
|
|
|
}
|
2022-02-08 14:07:59 +01:00
|
|
|
pedalboards = util.sortById(pedalboards);
|
|
|
|
cache.setPedalboards(pedalboards);
|
2022-02-07 16:56:18 +01:00
|
|
|
return resolve(pedalboards);
|
2022-02-07 15:41:27 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDefaultPedalboard() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let defaultPedalboard = cache.getDefaultPedalboard();
|
2022-02-07 23:50:16 +01:00
|
|
|
if (defaultPedalboard != undefined) {
|
2022-02-07 15:41:27 +01:00
|
|
|
return resolve(defaultPedalboard);
|
|
|
|
}
|
|
|
|
getPedalboardByBundle(constants.PEDALBOARD_DEFAULT)
|
2022-02-08 14:07:59 +01:00
|
|
|
.then(function (defaultPedalboard) {
|
|
|
|
cache.setDefaultPedalboard(defaultPedalboard);
|
|
|
|
return resolve(defaultPedalboard);
|
|
|
|
})
|
2022-02-07 15:41:27 +01:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentPedalboard() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let currentPedalboard = cache.getCurrentPedalboard();
|
2022-02-07 23:50:16 +01:00
|
|
|
if (currentPedalboard != undefined && currentPedalboard.id != undefined) {
|
2022-02-07 15:41:27 +01:00
|
|
|
return resolve(currentPedalboard);
|
|
|
|
}
|
2022-03-24 12:50:16 +01:00
|
|
|
util.httpGET(global.config.modep.host, global.config.modep.port, '/pedalboard/current')
|
2022-02-07 16:56:18 +01:00
|
|
|
.then(getPedalboardByBundle)
|
2022-02-08 14:07:59 +01:00
|
|
|
.then(function (currentPedalboard) {
|
|
|
|
cache.setCurrentPedalboard(currentPedalboard);
|
2022-02-07 23:50:16 +01:00
|
|
|
return resolve(currentPedalboard)
|
|
|
|
})
|
2022-02-07 16:56:18 +01:00
|
|
|
.catch(reject);
|
2022-02-07 15:41:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-07 23:50:16 +01:00
|
|
|
function getPedalboardById(pedalboardId) {
|
2022-02-07 15:41:27 +01:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
getPedalboards()
|
|
|
|
.then(function (pedalboards) {
|
2022-03-08 00:51:58 +01:00
|
|
|
for (let index = 0; index < pedalboards.length; index++) {
|
2022-02-07 15:41:27 +01:00
|
|
|
if (pedalboards[index].id != pedalboardId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return resolve(pedalboards[index]);
|
|
|
|
}
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('could not find pedalboard by id \'' + pedalboardId + '\'');
|
2022-02-07 15:41:27 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPedalboardByBundle(pedalboardBundle) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-02-07 23:50:16 +01:00
|
|
|
if (pedalboardBundle == undefined) {
|
|
|
|
getDefaultPedalboard()
|
|
|
|
.then(resolve)
|
|
|
|
.catch(reject);
|
|
|
|
return;
|
|
|
|
}
|
2022-02-07 15:41:27 +01:00
|
|
|
getPedalboards()
|
|
|
|
.then(function (pedalboards) {
|
2022-03-08 00:51:58 +01:00
|
|
|
for (let index = 0; index < pedalboards.length; index++) {
|
2022-02-07 15:41:27 +01:00
|
|
|
if (pedalboards[index].bundle != pedalboardBundle) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return resolve(pedalboards[index]);
|
|
|
|
}
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('could not find pedalboard by bundle \'' + pedalboardBundle + '\'');
|
2022-02-07 15:41:27 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPedalControlById(pedalId, controlId) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
getCurrentPedalById(pedalId)
|
|
|
|
.then(function (pedal) {
|
2022-03-08 00:51:58 +01:00
|
|
|
for (let index = 0; index < pedal.controls.length; index++) {
|
2022-02-07 15:41:27 +01:00
|
|
|
if (pedal.controls[index].id != controlId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return resolve(pedal.controls[index]);
|
|
|
|
}
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('could not find control for pedal \'' + pedalId + '\' by id \'' + controlId + '\'');
|
2022-02-07 15:41:27 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentPedalById(id) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
getCurrentPedals()
|
2022-02-07 16:56:18 +01:00
|
|
|
.then(function (currentPedals) {
|
2022-03-08 00:51:58 +01:00
|
|
|
for (let index = 0; index < currentPedals.length; index++) {
|
2022-02-07 15:41:27 +01:00
|
|
|
if (currentPedals[index].id != id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return resolve(currentPedals[index]);
|
|
|
|
}
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('could not find current pedal by id \'' + id + '\'');
|
2022-02-07 15:41:27 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentPedals() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let currentPedals = cache.getCurrentPedals();
|
2022-02-07 15:41:27 +01:00
|
|
|
if (currentPedals) {
|
|
|
|
return resolve(currentPedals);
|
|
|
|
}
|
|
|
|
getCurrentPedalboard()
|
|
|
|
.then(parseCurrentPedalboard)
|
2022-03-08 00:51:58 +01:00
|
|
|
.then(resolve)
|
2022-02-07 15:41:27 +01:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-08 00:51:58 +01:00
|
|
|
async function parseCurrentPedalboard(currentPedalboard) {
|
|
|
|
let pedals = [];
|
|
|
|
const defaultPedalboard = await getDefaultPedalboard();
|
2022-03-25 12:30:17 +01:00
|
|
|
if (defaultPedalboard.id === currentPedalboard.id) {
|
|
|
|
cache.setCurrentPedals(pedals);
|
|
|
|
blinky.setStatus(pedals);
|
|
|
|
return pedals;
|
|
|
|
}
|
|
|
|
|
|
|
|
let startTime = new Date();
|
|
|
|
logger.debug('parsing current pedalboard \'' + currentPedalboard.title + '\'...');
|
|
|
|
if (currentPedalboard.uri === undefined) {
|
|
|
|
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://', ''));
|
|
|
|
pedals = await new Promise((resolve, reject) => {
|
|
|
|
fs.readFile(file, (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
return reject('could not parse current pedalboard file \'' + file + '\' >>> ' + err);
|
|
|
|
}
|
|
|
|
let json = ttl2jsonld(data.toString())['@graph'];
|
|
|
|
let id = 0;
|
|
|
|
let currentPedals = [];
|
|
|
|
for (let index = 0; index < json.length; index++) {
|
|
|
|
let tmp = json[index];
|
|
|
|
if (tmp['lv2:prototype'] === undefined) {
|
|
|
|
continue;
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
2022-03-25 12:30:17 +01:00
|
|
|
let name = tmp['@id'];
|
|
|
|
currentPedals.push({ id: id, name: name, controls: [] });
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
for (let index = 0; index < json.length; index++) {
|
|
|
|
let tmp = json[index];
|
|
|
|
let name = tmp['@id'];
|
|
|
|
let value = tmp['ingen:value'];
|
|
|
|
if (value === undefined) {
|
|
|
|
continue;
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
2022-03-25 12:30:17 +01:00
|
|
|
let pedal = undefined;
|
|
|
|
for (let pedalIndex = 0; pedalIndex < currentPedals.length; pedalIndex++) {
|
|
|
|
if (!name.startsWith(currentPedals[pedalIndex].name)) {
|
2022-03-08 00:51:58 +01:00
|
|
|
continue;
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
2022-03-25 12:30:17 +01:00
|
|
|
pedal = currentPedals[pedalIndex];
|
|
|
|
break;
|
2022-03-08 00:51:58 +01:00
|
|
|
}
|
2022-03-25 12:30:17 +01:00
|
|
|
if (pedal === undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
id = pedal.controls.length;
|
|
|
|
name = name.replace(pedal.name + '/', '');
|
|
|
|
if (name !== constants.CONTROL_BYPASS) {
|
|
|
|
value = value['@value'];
|
|
|
|
}
|
|
|
|
let control = { id, name, value };
|
|
|
|
pedal.controls.push(control);
|
|
|
|
id++;
|
|
|
|
let midi = tmp['midi:binding'];
|
|
|
|
if (midi === undefined) {
|
|
|
|
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);
|
2022-03-08 00:51:58 +01:00
|
|
|
});
|
2022-03-25 12:30:17 +01:00
|
|
|
});
|
2022-03-08 00:51:58 +01:00
|
|
|
cache.setCurrentPedals(pedals);
|
|
|
|
blinky.setStatus(pedals);
|
|
|
|
return pedals;
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
|
|
|
|
2022-03-08 00:51:58 +01:00
|
|
|
function setControlByRequest(pedalId, requestParams) {
|
2022-02-07 15:41:27 +01:00
|
|
|
return new Promise(function (resolve, reject) {
|
2022-03-08 00:51:58 +01:00
|
|
|
let controlId = requestParams.get('id');
|
2022-03-25 01:10:50 +01:00
|
|
|
if (controlId === undefined) {
|
2022-03-08 00:51:58 +01:00
|
|
|
reject('could not handle POST - missing parameter \'id\'', 400);
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
2022-03-08 00:51:58 +01:00
|
|
|
let value = parseInt(requestParams.get('value'));
|
2022-03-25 01:10:50 +01:00
|
|
|
if (value === undefined) {
|
2022-03-08 00:51:58 +01:00
|
|
|
reject('could not handle POST - missing parameter \'value\'', 400);
|
2022-03-25 12:30:17 +01:00
|
|
|
} else if (isNaN(value)) {
|
2022-03-08 00:51:58 +01:00
|
|
|
reject('parameter \'value\' is not a number', 400);
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
2022-02-08 13:46:02 +01:00
|
|
|
getPedalControlById(pedalId, controlId)
|
|
|
|
.then(function (control) {
|
2022-03-25 12:30:17 +01:00
|
|
|
resolve(setControl(control, value));
|
2022-02-08 13:46:02 +01:00
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-25 12:30:17 +01:00
|
|
|
async function setControl(control, value) {
|
2022-03-08 00:51:58 +01:00
|
|
|
if (control === undefined || control.midi === undefined) {
|
|
|
|
throw new Error('control \'' + control.name + '\' with id \'' + control.id + '\' has no midi bindings');
|
2022-03-25 01:10:50 +01:00
|
|
|
}
|
|
|
|
control.midi.value = await osc.send(control.midi.controller, control.midi.channel, value);
|
2022-03-25 12:30:17 +01:00
|
|
|
cache.updateControl(control);
|
2022-03-08 00:51:58 +01:00
|
|
|
}
|
|
|
|
|
2022-02-07 15:41:27 +01:00
|
|
|
function setPedalboardById(pedalboardId) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2022-02-08 11:11:49 +01:00
|
|
|
if (pedalboardId == undefined) {
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('no pedalboard id given');
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
|
|
|
getPedalboardById(pedalboardId)
|
|
|
|
.then(setPedalboard)
|
|
|
|
.then(resolve)
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPedalboard(pedalboard) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
if (!pedalboard || !pedalboard.bundle) {
|
2022-03-08 00:51:58 +01:00
|
|
|
return reject('no bundle set for pedalboard');
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|
2022-02-07 23:50:16 +01:00
|
|
|
getCurrentPedalboard()
|
|
|
|
.then(function (currentPedalboard) {
|
2022-03-08 00:51:58 +01:00
|
|
|
if (pedalboard.id === currentPedalboard.id) {
|
|
|
|
return Promise.reject('pedalboard with id \'' + currentPedalboard.id + '\' is already active');
|
2022-02-07 23:50:16 +01:00
|
|
|
}
|
|
|
|
})
|
2022-02-08 11:11:49 +01:00
|
|
|
.then(function () {
|
|
|
|
return reset()
|
|
|
|
})
|
|
|
|
.then(function () {
|
2022-03-24 12:50:16 +01:00
|
|
|
return util.httpPOST(global.config.modep.host, global.config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle)
|
2022-02-08 11:11:49 +01:00
|
|
|
})
|
2022-02-07 23:50:16 +01:00
|
|
|
.then(function () {
|
2022-03-08 00:51:58 +01:00
|
|
|
cache.setCurrentPedalboard(pedalboard);
|
|
|
|
return parseCurrentPedalboard(pedalboard);
|
2022-02-07 23:50:16 +01:00
|
|
|
})
|
|
|
|
.then(resolve)
|
|
|
|
.catch(reject);
|
2022-02-07 15:41:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-08 00:51:58 +01:00
|
|
|
function hasControlMidiBindings(control) {
|
2022-03-25 01:10:50 +01:00
|
|
|
return control?.midi !== undefined;
|
2022-03-08 00:51:58 +01:00
|
|
|
}
|
|
|
|
|
2022-03-25 01:10:50 +01:00
|
|
|
function isBypassActive(control) {
|
|
|
|
return (control.midi?.value === undefined && control.value >= 1) || control.midi?.value === 0;
|
2022-03-08 00:51:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function isPedalBypassed(pedal) {
|
2022-03-25 01:10:50 +01:00
|
|
|
return isBypassActive(getBypassControlFromPedal(pedal));
|
2022-03-08 00:51:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBypassControlFromPedal(pedal) {
|
|
|
|
if (pedal === undefined) {
|
|
|
|
throw new Error('could not get bypass for an undefined pedal');
|
|
|
|
}
|
|
|
|
if (pedal.controls === undefined || pedal.controls.length === 0) {
|
|
|
|
throw new Error('could not get bypass for pedal \'' + pedal.name + '\' with id \'' + pedal.id + '\', pedal has no controls');
|
|
|
|
}
|
|
|
|
let bypass;
|
|
|
|
for (let index = 0; index < pedal.controls.length; index++) {
|
|
|
|
const control = pedal.controls[index];
|
|
|
|
if (control.name === constants.CONTROL_BYPASS) {
|
|
|
|
bypass = pedal.controls[index];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bypass === undefined) {
|
|
|
|
throw new Error('could not find bypass control for pedal \'' + pedal.name + '\' with id \'' + pedal.id + '\'');
|
|
|
|
}
|
|
|
|
return bypass;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleBypass(pedalId) {
|
|
|
|
let currentPedalboard = await getCurrentPedalboard();
|
|
|
|
let defaultPedalboard = await getDefaultPedalboard();
|
|
|
|
if (currentPedalboard.id === defaultPedalboard.id && pedalboardIdBypassOrigin === undefined) {
|
|
|
|
throw new Error('could not activate bypass, default pedalboard is currently already active');
|
|
|
|
}
|
|
|
|
if (pedalId === undefined) {
|
|
|
|
try {
|
|
|
|
let pedalboardId;
|
|
|
|
if (pedalboardIdBypassOrigin === undefined) {
|
|
|
|
pedalboardId = defaultPedalboard.id;
|
|
|
|
pedalboardIdBypassOrigin = currentPedalboard.id;
|
|
|
|
} else {
|
|
|
|
pedalboardId = pedalboardIdBypassOrigin;
|
|
|
|
pedalboardIdBypassOrigin = undefined;
|
|
|
|
}
|
|
|
|
await setPedalboardById(pedalboardId);
|
|
|
|
blinky.setBypass(pedalboardId === defaultPedalboard.id);
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-03-24 16:30:00 +01:00
|
|
|
const pedal = await getCurrentPedalById(pedalId);
|
|
|
|
const bypass = getBypassControlFromPedal(pedal);
|
|
|
|
let value = 0;
|
2022-03-25 01:10:50 +01:00
|
|
|
if (isBypassActive(bypass)) {
|
2022-03-24 16:30:00 +01:00
|
|
|
value = 127;
|
2022-03-08 00:51:58 +01:00
|
|
|
}
|
|
|
|
try {
|
2022-03-25 12:30:17 +01:00
|
|
|
await setControl(bypass, value);
|
2022-03-10 00:32:38 +01:00
|
|
|
blinky.setPedalStatus(pedal);
|
2022-03-08 00:51:58 +01:00
|
|
|
} catch (err) {
|
|
|
|
throw new Error('could not toggle bypass for pedal ' + pedal.name + ' with id \'' + pedal.id + '\' > ' + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 15:41:27 +01:00
|
|
|
module.exports = {
|
|
|
|
getBanks,
|
2022-02-07 23:50:16 +01:00
|
|
|
getBankById,
|
2022-02-07 15:41:27 +01:00
|
|
|
getPedalboards,
|
2022-02-07 23:50:16 +01:00
|
|
|
getPedalboardById,
|
2022-02-07 15:41:27 +01:00
|
|
|
getDefaultPedalboard,
|
|
|
|
getCurrentPedalboard,
|
|
|
|
getCurrentPedals,
|
|
|
|
getCurrentPedalById,
|
|
|
|
getPedalControlById,
|
|
|
|
setPedalboard,
|
|
|
|
setPedalboardById,
|
2022-03-08 00:51:58 +01:00
|
|
|
setControlByRequest,
|
|
|
|
toggleBypass,
|
2022-03-25 01:10:50 +01:00
|
|
|
isBypassActive,
|
2022-03-08 00:51:58 +01:00
|
|
|
isPedalBypassed,
|
2022-03-25 01:10:50 +01:00
|
|
|
getBypassControlFromPedal,
|
|
|
|
hasControlMidiBindings
|
2022-02-07 15:41:27 +01:00
|
|
|
}
|