Last active
January 31, 2020 10:00
-
-
Save defel/3575854c2e867af45f082cf8d4b27796 to your computer and use it in GitHub Desktop.
Keebwerk Nano Bento Pulseaudio Volumecontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const midi = require('midi'); | |
const debounce = require('debounce'); | |
const {execSync} = require('child_process') | |
// Set up a new input. | |
const input = new midi.Input(); | |
// Count the available input ports. | |
// console.log('COUNT:', input.getPortCount()); | |
// console.log('P1:', input.getPortName(0)); | |
// console.log('P2:', input.getPortName(1)); | |
let lastVal = 0; | |
const dbDraw = debounce(draw, 20); | |
input.on('message', (deltaTime, message) => { | |
const [status, d1, d2] = message; | |
if(d2 === lastVal) { | |
return; | |
} | |
dbDraw(d2) | |
lastVal = d2; | |
}) | |
input.openPort(1); | |
input.ignoreTypes(false, false, false); | |
function draw(input) { | |
val = input / 127 * 100 | |
vol = Math.floor(input / 100 * 65500) | |
console.log('#'.repeat(val), ' ' + vol); | |
// execSync(`amixer sset Master ${val}%`); | |
// console.log(`pacmd set-sink-volume 0 ${vol}`); | |
execSync(`pacmd set-sink-volume 0 ${vol}`); | |
execSync(`pacmd set-sink-volume 15 ${vol}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment