set color for specific pedalboards and/or systemd services
This commit is contained in:
parent
a55c7a9929
commit
a5c6801a4b
7 changed files with 128 additions and 63 deletions
|
@ -27,6 +27,11 @@
|
||||||
"host": "192.168.1.31",
|
"host": "192.168.1.31",
|
||||||
"port": 3000,
|
"port": 3000,
|
||||||
"colors": {
|
"colors": {
|
||||||
|
"pedalboards": {
|
||||||
|
"Default": "#0F0F0F",
|
||||||
|
"FUZZ": "0F0F00"
|
||||||
|
},
|
||||||
|
"pedals": {
|
||||||
"BigMuffPi": {
|
"BigMuffPi": {
|
||||||
"enabled": "#008800",
|
"enabled": "#008800",
|
||||||
"bypassed": "002200"
|
"bypassed": "002200"
|
||||||
|
@ -40,6 +45,9 @@
|
||||||
"bypassed": "#220022"
|
"bypassed": "#220022"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Bypass": "#333333"
|
"systemd": {
|
||||||
|
"jack-capture": "#660066"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ function setEndpoint(url, get, post) {
|
||||||
endpoint.POST = post;
|
endpoint.POST = post;
|
||||||
}
|
}
|
||||||
endpoints.set(url, endpoint);
|
endpoints.set(url, endpoint);
|
||||||
logger.debug('set up endpoint \'' + url + '\' > ' + JSON.stringify(endpoint));
|
logger.debug('set up endpoint \'' + url + '\' > GET: ' + (endpoint.GET !== undefined) + ', POST ' + (endpoint.POST !== undefined));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEndpoints() {
|
function getEndpoints() {
|
||||||
|
|
152
libs/blinky.js
152
libs/blinky.js
|
@ -1,9 +1,17 @@
|
||||||
const logger = require('./logger.js');
|
const logger = require('./logger.js');
|
||||||
const { CONTROL_BYPASS } = require('./constants.js');
|
const { CONTROL_BYPASS, SYSTEMD_STATE_ACTIVE } = require('./constants.js');
|
||||||
const { httpPOST } = require('./util.js');
|
const { httpPOST, httpGET } = require('./util.js');
|
||||||
|
|
||||||
|
const BLINKSTICK_SQUARE = 'square';
|
||||||
|
const BLINKSTICK_STRIP = 'strip';
|
||||||
|
|
||||||
|
const COLOR_RANDOM = 'random';
|
||||||
|
const COLOR_DEFAULT = '#333333';
|
||||||
|
|
||||||
let enabled;
|
let enabled;
|
||||||
let isBypassActive;
|
let fnIsBypassActive;
|
||||||
|
|
||||||
|
let animationsInProgress = {};
|
||||||
|
|
||||||
async function initialize() {
|
async function initialize() {
|
||||||
enabled = global.config.blinky !== undefined &&
|
enabled = global.config.blinky !== undefined &&
|
||||||
|
@ -12,36 +20,60 @@ async function initialize() {
|
||||||
global.config.blinky.port !== undefined;
|
global.config.blinky.port !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setActive(active) {
|
async function getColor() {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info('handling blinky event \'setActive\' (argument: \'' + active + '\')...');
|
|
||||||
try {
|
try {
|
||||||
if (active) {
|
return await httpGET(
|
||||||
await httpPOST(
|
|
||||||
global.config.blinky.host,
|
global.config.blinky.host,
|
||||||
global.config.blinky.port,
|
global.config.blinky.port,
|
||||||
'/set',
|
'color'
|
||||||
{ blinkstick: 'square', color: '#0f0f0f' }
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let mode = '/poweroff';
|
|
||||||
await httpPOST(
|
|
||||||
global.config.blinky.host,
|
|
||||||
global.config.blinky.port,
|
|
||||||
mode,
|
|
||||||
{ blinkstick: 'square' }
|
|
||||||
);
|
|
||||||
await httpPOST(
|
|
||||||
global.config.blinky.host,
|
|
||||||
global.config.blinky.port,
|
|
||||||
mode,
|
|
||||||
{ blinkstick: 'strip' }
|
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('[BLINKY] ' + err);
|
logger.error('[blinky] ' + err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function poweroff(...blinksticks) {
|
||||||
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (blinksticks === undefined || blinksticks.length === 0) {
|
||||||
|
blinksticks = [BLINKSTICK_SQUARE, BLINKSTICK_STRIP];
|
||||||
|
}
|
||||||
|
for (let index = 0; index < blinksticks.length; index++) {
|
||||||
|
try {
|
||||||
|
await httpPOST(
|
||||||
|
global.config.blinky.host,
|
||||||
|
global.config.blinky.port,
|
||||||
|
'poweroff',
|
||||||
|
{ blinkstick: blinksticks[index] }
|
||||||
|
);
|
||||||
|
logger.debug('[blinky] powered off blinkstick \'' + blinksticks[index]);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('[blinky] ' + err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setPedalboardStatus(pedalboard) {
|
||||||
|
try {
|
||||||
|
if (!enabled || pedalboard === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await httpPOST(
|
||||||
|
global.config.blinky.host,
|
||||||
|
global.config.blinky.port,
|
||||||
|
'set',
|
||||||
|
{
|
||||||
|
blinkstick: BLINKSTICK_SQUARE,
|
||||||
|
color: getPedalboardColor(pedalboard.title)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
logger.debug('[blinky] set status for pedalboard \'' + pedalboard.title + '\'');
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('[blinky] ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +82,8 @@ async function setPedalStatus(pedal) {
|
||||||
if (!enabled || pedal === undefined || pedal.controls === undefined) {
|
if (!enabled || pedal === undefined || pedal.controls === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isBypassActive === undefined) {
|
if (fnIsBypassActive === undefined) {
|
||||||
isBypassActive = require('./modep.js').isBypassActive;
|
fnIsBypassActive = require('./modep.js').isBypassActive;
|
||||||
}
|
}
|
||||||
for (let index = 0; index < pedal.controls.length; index++) {
|
for (let index = 0; index < pedal.controls.length; index++) {
|
||||||
const bypass = pedal.controls[index];
|
const bypass = pedal.controls[index];
|
||||||
|
@ -63,23 +95,25 @@ async function setPedalStatus(pedal) {
|
||||||
global.config.blinky.port,
|
global.config.blinky.port,
|
||||||
'set',
|
'set',
|
||||||
{
|
{
|
||||||
blinkstick: 'strip',
|
blinkstick: BLINKSTICK_STRIP,
|
||||||
index: pedal.id,
|
index: pedal.id,
|
||||||
color: getPedalColor(pedal.name, isBypassActive(bypass))
|
color: getPedalColor(pedal.name, fnIsBypassActive(bypass))
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
logger.debug('[blinky] set status for pedal \'' + pedal.name + '\'');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('[BLINKY] ' + err);
|
logger.error('[blinky] ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setStatus(pedals) {
|
async function setStatus(pedalboard, pedals) {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await httpPOST(global.config.blinky.host, global.config.blinky.port, '/poweroff', { blinkstick: 'strip' });
|
setPedalboardStatus(pedalboard);
|
||||||
|
await poweroff([BLINKSTICK_STRIP]);
|
||||||
if (pedals === undefined || pedals.length === 0) {
|
if (pedals === undefined || pedals.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -98,38 +132,58 @@ async function setStatus(pedals) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('[BLINKY] ' + err);
|
logger.error('[blinky] ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setBypass(bypassActive) {
|
async function setSystemdStatus(name, state) {
|
||||||
if (!enabled) {
|
if (name === undefined || state === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
let mode = 'set';
|
||||||
if (!bypassActive) {
|
let options = {
|
||||||
return await setActive(true);
|
blinkstick: BLINKSTICK_STRIP,
|
||||||
|
color: animationsInProgress[name] || COLOR_DEFAULT
|
||||||
|
};
|
||||||
|
if (state === SYSTEMD_STATE_ACTIVE) {
|
||||||
|
const result = await getColor([BLINKSTICK_SQUARE]);
|
||||||
|
for (let index = 0; index < result.length; index++) {
|
||||||
|
if (result[index].blinkstick !== options.blinkstick) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
await httpPOST(global.config.blinky.host, global.config.blinky.port, 'pulse', { blinkstick: 'square', color: '#660000' });
|
animationsInProgress[name] = result[index].leds[0]?.color || COLOR_RANDOM;
|
||||||
} catch (err) {
|
mode = 'pulse';
|
||||||
logger.error('[BLINKY] ' + err);
|
options.color = getSystemdColor(name);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return await httpPOST(
|
||||||
|
global.config.blinky.host,
|
||||||
|
global.config.blinky.port,
|
||||||
|
mode,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPedalboardColor(name) {
|
||||||
|
return global.config?.blinky?.colors?.pedalboards[name] || COLOR_RANDOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPedalColor(name, bypassed) {
|
function getPedalColor(name, bypassed) {
|
||||||
let color;
|
|
||||||
if (bypassed) {
|
if (bypassed) {
|
||||||
color = global.config.blinky?.colors[name]?.bypassed || global.config.blinky?.colors['Bypass'] || '#333333';
|
return global.config?.blinky?.colors?.pedals[name]?.bypassed || COLOR_DEFAULT;
|
||||||
} else {
|
|
||||||
color = global.config.blinky?.colors[name]?.enabled || 'random';
|
|
||||||
}
|
}
|
||||||
return color;
|
return global.config?.blinky?.colors?.pedals[name]?.enabled || COLOR_RANDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSystemdColor(name) {
|
||||||
|
return global.config?.blinky?.colors?.systemd[name] || COLOR_RANDOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
initialize,
|
initialize,
|
||||||
setActive,
|
poweroff,
|
||||||
setBypass,
|
|
||||||
setStatus,
|
setStatus,
|
||||||
setPedalStatus
|
setPedalStatus,
|
||||||
|
setSystemdStatus
|
||||||
}
|
}
|
|
@ -146,7 +146,7 @@ async function parseCurrentPedalboard(currentPedalboard) {
|
||||||
const defaultPedalboard = await getDefaultPedalboard();
|
const defaultPedalboard = await getDefaultPedalboard();
|
||||||
if (defaultPedalboard.id === currentPedalboard.id) {
|
if (defaultPedalboard.id === currentPedalboard.id) {
|
||||||
cache.setCurrentPedals(pedals);
|
cache.setCurrentPedals(pedals);
|
||||||
blinky.setStatus(pedals);
|
blinky.setStatus(currentPedalboard, pedals);
|
||||||
return pedals;
|
return pedals;
|
||||||
}
|
}
|
||||||
let startTime = new Date();
|
let startTime = new Date();
|
||||||
|
@ -155,8 +155,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://', ''));
|
||||||
const data = await new Promise((resolve, reject) => {
|
const data = await new Promise((resolve, reject) => {
|
||||||
fs.readFile(file, (err, data) => {
|
fs.readFile(file, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -210,7 +210,7 @@ async function parseCurrentPedalboard(currentPedalboard) {
|
||||||
}
|
}
|
||||||
logger.debug('parsing current pedalboard file \'' + file + '\' took ' + util.timeDiff(startTime) + 'ms')
|
logger.debug('parsing current pedalboard file \'' + file + '\' took ' + util.timeDiff(startTime) + 'ms')
|
||||||
cache.setCurrentPedals(pedals);
|
cache.setCurrentPedals(pedals);
|
||||||
blinky.setStatus(pedals);
|
blinky.setStatus(currentPedalboard, pedals);
|
||||||
return pedals;
|
return pedals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +241,7 @@ async function setControl(control, value) {
|
||||||
}
|
}
|
||||||
control.midi.value = await osc.send(control.midi.controller, control.midi.channel, value);
|
control.midi.value = await osc.send(control.midi.controller, control.midi.channel, value);
|
||||||
cache.updateControl(control);
|
cache.updateControl(control);
|
||||||
|
logger.info('set value for control \'' + control.name + '\' to \'' + value + '\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setPedalboardById(pedalboardId) {
|
async function setPedalboardById(pedalboardId) {
|
||||||
|
@ -263,6 +264,7 @@ async function setPedalboard(pedalboard) {
|
||||||
await reset();
|
await reset();
|
||||||
await util.httpPOST(global.config.modep.host, global.config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle);
|
await util.httpPOST(global.config.modep.host, global.config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle);
|
||||||
cache.setCurrentPedalboard(pedalboard);
|
cache.setCurrentPedalboard(pedalboard);
|
||||||
|
logger.info('set current pedalboard to \'' + pedalboard.title + '\'');
|
||||||
return await parseCurrentPedalboard(pedalboard);
|
return await parseCurrentPedalboard(pedalboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +318,6 @@ async function toggleBypass(pedalId) {
|
||||||
pedalboardIdBypassOrigin = undefined;
|
pedalboardIdBypassOrigin = undefined;
|
||||||
}
|
}
|
||||||
await setPedalboardById(pedalboardId);
|
await setPedalboardById(pedalboardId);
|
||||||
blinky.setBypass(pedalboardId === defaultPedalboard.id);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
|
@ -334,6 +335,7 @@ async function toggleBypass(pedalId) {
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
logger.info('toggled bypass for pedal \'' + pedal.name + '\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const logger = require('./logger.js');
|
const logger = require('./logger.js');
|
||||||
const api = require('./api.js');
|
const api = require('./api.js');
|
||||||
const blinky = require('./blinky.js');
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
const ID = require('./constants.js').VARIABLE_ID;
|
const ID = require('./constants.js').VARIABLE_ID;
|
||||||
|
@ -13,7 +12,6 @@ async function start() {
|
||||||
}
|
}
|
||||||
server.listen(global.config.server.port, global.config.server.listen).on('listening', () => {
|
server.listen(global.config.server.port, global.config.server.listen).on('listening', () => {
|
||||||
logger.debug('server listening on ' + global.config.server.listen + ':' + global.config.server.port + '...');
|
logger.debug('server listening on ' + global.config.server.listen + ':' + global.config.server.port + '...');
|
||||||
blinky.setActive(true);
|
|
||||||
handleRequests();
|
handleRequests();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const logger = require('./logger.js');
|
const logger = require('./logger.js');
|
||||||
const commands = require('./commands.js');
|
const commands = require('./commands.js');
|
||||||
const constants = require('./constants.js');
|
const constants = require('./constants.js');
|
||||||
|
const blinky = require('./blinky.js');
|
||||||
|
|
||||||
async function getServiceState(name) {
|
async function getServiceState(name) {
|
||||||
if (name === undefined) {
|
if (name === undefined) {
|
||||||
|
@ -42,7 +43,9 @@ async function setServiceState(name, args) {
|
||||||
state = constants.SYSTEMD_STATE_ACTIVE;
|
state = constants.SYSTEMD_STATE_ACTIVE;
|
||||||
}
|
}
|
||||||
logger.debug('setting state of service \'' + name + '\' to \'' + state + '\'...');
|
logger.debug('setting state of service \'' + name + '\' to \'' + state + '\'...');
|
||||||
return { service: name, state: state, result: await commands.execute('systemctl', [command, name], true)};
|
const result = await commands.execute('systemctl', [command, name], true);
|
||||||
|
blinky.setSystemdStatus(name, state);
|
||||||
|
return { service: name, state: state, result: result};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
2
pbc.js
2
pbc.js
|
@ -40,7 +40,7 @@ function handleExit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exit(err, code) {
|
async function exit(err, code) {
|
||||||
await blinky.setActive(false);
|
await blinky.poweroff();
|
||||||
if (code === undefined) {
|
if (code === undefined) {
|
||||||
code = 0;
|
code = 0;
|
||||||
if (err !== undefined) {
|
if (err !== undefined) {
|
||||||
|
|
Loading…
Reference in a new issue