Skip to content

Instantly share code, notes, and snippets.

@neagle
Created May 28, 2020 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neagle/e5b07f6eefb071e8b09b86b5b3be25d7 to your computer and use it in GitHub Desktop.
Save neagle/e5b07f6eefb071e8b09b86b5b3be25d7 to your computer and use it in GitHub Desktop.
This is just a quick example of how to use the raw ASCII output from CAVA in an application
// A minimal set of NodeJS code for parsing incoming ASCII data from CAVA and turning it into useful data.
// This code would need to have cava's output piped to it:
// Ex: $ cava -p ~/.config/cava/raw | node cava_ascii_output_parser.js
process.stdin.setEncoding('utf8');
let str = '';
process.stdin.on('readable', () => {
let chunk;
// Use a loop to make sure we read all available data.
while ((chunk = process.stdin.read()) !== null) {
str += chunk;
// CAVA's convention for marking the ends of frames is the @ symbol
const frameEnd = str.indexOf('@');
if (frameEnd > 0) {
displayFrame(str.substring(0, frameEnd));
str = str.substring(frameEnd + 1);
}
}
});
function displayFrame(f) {
frame.pop();
// Bars are separated by semi-colons
frame.push(f.split(';'));
// Do something with the frames
// This line references code not present in the gist
visualizers.forEach(draw);
}
process.stdin.on('end', () => {
console.log('end');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment