JFugue: A Java Library for Music Synthesis

Written by on December 20, 2020 in LISP, Music, Programming with 0 Comments

JFugue is an open-source Java library that can be used for algorithmic music composition. Developed by David Koelle, currently it is in its fifth major version. You can get the library from here.

I had downloaded the library some time ago, but could not spend much time since my primary focus has been on Opusmodus. This week I took some time off to get started with the library.

I had two things on my mind when I started working with JFugue:

  • Understand the capabilities of the library
  • Explore the option of using it from Lisp, specifically LispWorks Common Lisp

The author’s e-book is highly recommended in order to get a deeper understanding of the capabilities of the library. I am still going through the book while exploring the different features in a phased manner.

Just like we have the OMN in Opusmodus, JFugue uses “Staccato”, a string-based music representation format that is quite expressive. Just to get started with the library, I wrote a simple Java program shown below:

Simple Java Program

Simple Java Program

A brief description of the above program is in order. First, we create a “Player” object. The next statement uses a “Staccato” representation of a simple musical fragment, giving it to the player to play it. The token “D3h” denotes pitch “D”, 3rd octave, played for “half” a note. “Bb3h” denotes the pitch “B flat”, 3rd octave and played for half a note. “C#3h” likewise, denotes the pitch “C sharp”. “Rq” represents “Rest” for “quarter” note. As you can see, each token contains information about the pitch, it’s octave and the duration. What about the “tempo”? It is by default 120 BPM.

The staccato string in the next statement is slightly different.  Here, the token “T100” explicitly sets the tempo at 100 BPM. The next token “V0” denotes “Voice 0”, to “Track 0”. Following these two, we have pitch specifications as we saw earlier, except that the octave and duration are unspecified. By default, JFugue uses 4th octave and “quarter” note duration. Such assumptions help make the “Staccato” string fairly compact.

The next statement plays a chord progression, that is, sequence of “Chords”. In this case, it plays “C Major”, “F Major”, “G Major”, and “C Major”, in the 3rd octave, each lasting “quarter” note. Instead of explicitly stating a chord progression like this, we can also use the “ChordProgression” class and denote the chords through its indices as is commonly done. The chord progression object can then be passed to the “play” function. The last line shows another interesting possibility. Here we are playing the chord progression as defined earlier, but using “A Flat” as the root instead of “C”.

I wrote and tested the above program using Intellij IDEA. It worked as expected on both my Mac and Windows machines. 

The next part of my experiment was to use the JFugue library from LispWorks Lisp on Windows. This turned out to be pretty straightforward.

Setting Up Java Environment

Setting Up Java Environment


The actual implementation of the example code (as in the Java example above) is here:

Playing the Music

Playing the Music

The only change is that I wrote a simple class abstraction to model the “Player”. The reason is that, in future, I might want to render the music on an external instrument set (such as DAW) instead of the default Windows soundset. Nothing complicated here.

The following shows the test function being run from the “Listener”.

Running the Code

Running the Code

 How does JFugue compare with Opusmodus?

In terms of representing music, JFugue uses a string representation called “Staccato” to depict pitch, rhythm, velocity, tempo, etc. Opusmodus uses OMN for this purpose. Although the syntax differs, the expressive power is almost the same. Opusmodus is vastly superior when it comes to built-in algorithms for music composition. For instance, in Opusmodus, you can easily apply Lindenmayer system for music synthesis. Or convert different types of “noise” (such as White noise, Pink noise, etc.) to pitch. There  are hundreds of built-in functions that let you do fancy composition. It is also easy to hook it up to external Digital Audio Workstations such as Falcon through MIDI or OSC. Most importantly, Opusmodus is not just a library, but a complete environment for music creation. You can even do fancy stuff like plot graphs and render MusicXML. The comparison between the two products might not even be fair! Opusmodus is a commercial product and hence people expect it to provide more. 

One man advantage of JFugue is that it is in Java and hence can run on any platform. Opusmodus is at present limited to Mac OS.

You can download the Java source here and the Lisp source here.

Happy holidays!

Tags: , , , , ,


If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *