Listening To Your App
Making music is a hobby of mine, so when I saw the session "Programming Music for Fun and Productivity: JFugue and Log4JFugue" in the JavaOne 2009 program, I signed up.
Unfortunately, I arrived about 10 minutes late and discovered presenter David Koelle already pumping out midi files with JFugue. JFugue is an open-source Java API for programming music. Its interface, while text based, is much easier to understand and program with than is MIDI (musical instrument digital interface).
Koelle showed how easy it was to load quality sound samples into JFugue, and created a pleasing version of Vivaldi's "Spring." He then demonstrated some expressions that JFugue used to make music. This simple example, from
the from "The Complete Guide to JFugue" (http://www.jfugue.org/book.html) plays a C scale.
import org.jfugue.*;
public class MyMusicApp
{
public static void main(String[] args)
{
Player player = new Player();
Pattern pattern = new Pattern("C D E F G A B");
player.play(pattern);
System.exit(0); // If using Java 1.4 or lower
}
}
All this is well and good, but computers have been playing music for a long time now, and I was ready to see -- hear, rather -- what presenter Brian Tarbox had to say about Log4JFugue.
Log4JFugue is built on the open-source project Log4J. With Log4J, you can place log statements in shipped code without paying a large performance price. Logging is controlled through a configuration file, not the application binary itself.
For a complex system, tracking down a failure in log files can be a real challenge. Tarbox helps maintain a program that writes 100,000 lines of code an hour. He told of spreading a log printout across the floor and mapping cause and effect statements for hours to get to the root of a memory link. He decided to bring hearing as well as vision to bear on log files by combining Log4J and JFugue, and Log4JFugue was born.
Tarbox "played" a log file for the audience in which log messages were represented by percussion instruments: successful events were represented by drum sounds, failures were represented by cymbal crashes, and so on. The result sounded like an elaborate mechanism ticking along, and it was easy to tell when the system was getting into trouble by
the sound of the cymbals. Tarbox likened it to the way a good mechanic can tell the condition of a car by the sound of its engine. The timing of repeated rhythmic motifs indicated the frequency of certain function calls, and in this way he got an intuitive sense of how the system was performing.
So far, Log4JFugue has been limited to the sounds of percussion instruments. Although producing pitched instrument sounds could conceivably transmit more information, experiments with them have produced too much cacophony. Tarbox is considering limiting pitched instruments to the pentatonic scale in order to reduce disharmony.
Because the Log4JFugue player is a Spring injection point, you could write a player to play a wav file or take other action for a particular log file entry. A fatal error, for example, could trigger the sound of an explosion.
Overall, the presentation stimulated some new ways of thinking about engaging senses other than the visual in the software development process.
--Rick Palkovic
References
Log4JFugue: http://log4jfugue.org/
JFugue: http://jfugue.org/
Log4J: http://logging.apache.org/log4j/
Related Posting
More Java, More Music <http://blogs.sun.com/javaone2009/entry/more_java_more_music>
