Sunday, March 29, 2015

Controlling VMeter on Linux with Java

I bought a VMeter USB MIDI controller on a whim about a year ago (it was on sale).  Since then, it has patiently sat on my desk waiting for me to find a use for it.

I'm not a musician so I didn't buy it for its musical features.  I bought it as an input device and display for my computer.  Since my primary computer runs Linux, I can't run most of the sample programs provided by the VMeter folks.
A few weeks ago I finally sat down to try my hand at getting the VMeter to do something interesting.  Being a Java programmer, the language choice was obvious.  Unfortunately, I didn't find any Java sample code but it didn't prove too hard to adapt the C sample code.
For my first attempt, I wrote a program that changes which LEDs are lit on the VMeter based on a pattern passed in on the command line.  It even allows multiple patterns to be specified on the command line and a delay after displaying each one to make an animated light show.
The second program reads from /proc/stat and /proc/meminfo on Linux and displays the current CPU usage percent and the percent of memory currently used on the VMeter LEDs.  CPU is displayed like a bargraph and memory is displayed as a single LED which is XOR'd with the CPU bar graph.  To make it even more useful I added the ability to set the master volume on my computer (courtesy of the "amixer" command) by touching the VMeter.
I have uploaded both programs to my GitHub repository.

No comments:

Post a Comment