Music that doesn't get repetitive or adapts to the situation in a game is a trick few have mastered, either in the commercial domain or in Free software games.
Whereas music is traditionally composed/produced then simply looped during games, there is another possibility - generating the music on-demand to match the current scenario. These are two Java libraries for doing this.
Sound Helix algorithmic random music composer
(Source: java-gaming.org thread)
SoundHelix is a Java framework for composing algorithmic music.
The examples on the webpage are really good:
http://www.soundhelix.com/audio-examples
Simple example applet:
http://www.soundhelix.com/applet/SoundHelix-applet.jnlp
The music created is totally random within the limits provided.
Music generation can be quite fast (millisecond range) or really slow (seconds range), depending on how complex the constraints are for the generated songs. Virtually all time for song generation is spent in finding a random song activity matrix that fulfills the given constraints. Once a valid matrix has been found, rendering the song is very fast.
Reactive Music Language
(Source: java-gaming.org thread)
The reactive music language editor and
The Music Generator is the layer below the Reactive Music Language (sort of). If you want to study the Music Generator in isolation, this is the place for you.
A video that demonstrates a module:
http://www.youtube.com/watch?v=wUxdZjHdcIw
Another video that demonstrates two modules and the editor
http://www.youtube.com/watch?v=XQ9h_uxegjQ
The second demo is at 6:08 and the editor demo is at 8:00 if you want to skip forward Smiley
The Music Generator produces one musical measure or bar at a time given a large set of possible property values. It also keeps track of a harmonic rythm.
The Reactive Music Language (RML) supports scripting, action execution (parallel, conditional etc.), external parameter mapping, states with reactions.
The examples with multiple channels are the most interesting ones to listen to, the others are more tutorial-like and demonstrate one particular functionality.
I think that the most interesting application for this API is to put RML modules inside games that produce music depending on what happens.