Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.