Created
May 28, 2020 21:35
-
-
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
This file contains hidden or 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
// 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