CSCI 220
Assigned Date: Monday, April 19, 2004
Due Date: Tuesday, April 27, 2004
Due Time: 11:55pm

Due Date for Bonus Work: TBA (you'll have a few extra days for these)


Updated: April 23, 2004 09:16 PM

Program file names to be submitted:,,, …, Readme.txt .

Skills Developed: Object-oriented design, inheritance, having fun!

Documentation and submission:  See instructions in the first homework assignment.

Assignment:  You will write a set of programs that generate music.  To do so you will employ a set of classes from the JFugue API for Music Programming.



There is a strong connection between mathematics and art/music.  This connection dates back to pre-Socratic times. Pythagoras, Plato, and Aristotle worked on quantitative expressions of proportion and beauty, such as the golden ratio. Pythagoreans, for instance, quantified harmonious musical intervals in terms of proportions (ratios) of the numbers 1, 2, 3, 4 and 5. This scale became the basis for the well-tempered scales eventually refined by J.S. Bach and others. 

Leibniz wrote, "Music charms us, although its beauty consists only in the agreement of numbers and in the counting, which we do not perceive but which the soul nevertheless continues to carry out." (Loemker 1976, p. 641). Boethius stated, "[Music] consonance is a unified concordance of sounds dissimilar in themselves." It pleases the listener because "the body is subject to the same laws that govern music, and these same proportions are to be found in the cosmos itself. Microcosm and macrocosm are tied by the same knot, simultaneously mathematical and aesthetic." (Eco 1986, p.31)

Johann Sebastian Bach (1685-1750) explored the connection between mathematics and music by creating a variety of compositions that are especially pleasing to those with a mathematical inclination. His fugues and cannons are particularly mathematical in nature. Bach also played clever games with music. For example, a sheet of music with his "Crab Cannon" on it can literally be turned upside down and remain unchanged. Escher had a special affinity for Bach, which he wrote about on more than one occasion. "In my periods of weakness and spiritual emptiness and lethargy, I reach out to Bach's music to revive and fire my desire for creativity." (Profiles in math & art)


Part 0:

Set up your PC to work with JFugue.  To do so, do the following:

  1. Save jfugue.jar in your working directory.
  2. Update the way you compile and execute Java programs.  There are two ways to do this (pick one):
    1. Update the JCreator configuration by adding jfugue.jar to the list of known archives (Configure --> Options --> JDK Profiles --> Edit --> Add --> Add Archive --> <path to your working directory>\jfugue.jar).
    2. Or, alternatively, compile and execute from the MSDOS console as follows:

·         javac -classpath %CLASSPATH%;jfugue.jar

·         java -classpath %CLASSPATH%;jfugue.jar MyMusicApp

  1. Any program that uses JFugue should contain the statement import org.jfugue.*; before the class definition(s).

To test your updated configuration, compile and execute the sample program .


Part 1:

Familiarize yourself with the JFugue documentation, and in particular with how music phrases are represented, i.e., the Music String and Patterns. 

Create a Java program,, to play one of your favorite melodies.  

Here is a sample program that plays the children's song "Frere Jacques".  It demonstrates how to construct songs with several concurrent voices.

Also, here is a Java program you can use to convert a MIDI file to text, if you need it (look for MIDI File Disassembler/Assembler).


Part 2:

Create class CanonMaker.  This class has, at least, the following methods:



  1. Your methods should be fully documented (purpose, pre/postconditions, parameter information flow (in, out, in/out), etc.)

  2. You will need to import org.jfugue.*; and also import org.jfugue.demo.*; 

  3. You may use PatternTransformers that come with JFugue (i.e., DurationPatternTransformer, IntervalPatternTransformer, ReversePatternTransformer). Here is a sample program that demonstrates their use.

  4. To test your class, create a driver called,, which uses CanonMaker to "compose" a canon from the following music string:

Pattern musicalOfferingRoyalTheme = new Pattern(
   "C5h Eb5h G5h Ab5h B4h Rq G5q G5q F#5h F5q F5q E5h Ebq " +   // first five measures
   "Ebq D5q Db5q C5q B4q G4q C5q F5q Eb5h D5h C5h Eb5h G5i F5i G5i C6i G5i Eb5i D5i Eb5i " +  // five more measures
   "F5i G5i A5i B5i C6i Eb5i F5i G5i Ab5i D5i Eb5i F5i G5i F5i Eb5i D5i E5i F5i G5i Ab5i Bb5i Ab5i G5i F5i G5i Ab5i Bb5i C6i Db6i Bb5i Ab5i G5i " +    // four more measures
   "A5i B5i C6i D6i Eb6i C6i Bb5i Ab5i B5i C6i D6i Eb6i F6i D6i G5i D6i C6i D6i Eb6i F6i Eb6i D6i C6i B5i C6q G5q Eb5q C5q "    // last four measures

This theme was given as a challenge to Johann Sebastian Bach by King Frederick the Great in 1746.   Bach developed several canons from this theme.  Your CanonMaker class has enough power to help you "compose" at least one of them (i.e., Canon No. 1).  Experiment with other possibilities.

Part 3 (bonus):

Create a new PatternFactory.  Possibilities include, or, or ... .  For sample code, see JFugue source (examples and demos subdirectories).

Demonstrate your PatternFactory through a, where X is the music genre your chose.  

Provide details in your Readme.txt file.


Part 4 (extra bonus):

Expand your CanonMaker class by adding more methods, as per the Anatomy of a Canon.

Demonstrate some of these operations in your

Encode a few canon leaders and write programs that generate them using CanonMaker.  

Provide details in your Readme.txt file.


Part 5 (super duper bonus):

This is an open exploration activity...

Experiment with the LSystems code in JFugue source ( in the examples subdirectory).   For background on LSystems see Laurens Lapré's page and LMUSe).

For instance, you could write a composer of canons using and  There are may other intriguing possibilities. 



   1. You should modularize and document your code thoroughly. 

   2. If you don't design carefully, parts 3, 4, and 5 could be a great time drain!

   3. Within submitted file 'Readme.txt' state which assignment parts you completed and describe the behavior of your programs.

   4. Each source file you submit should include an opening comment section (i.e., author, course, date, assignment, etc.) and a certificate of authenticity.

   5. The bonus parts do not need to be done in sequence.  You may pick and choose which bonus activity you wish to work on, if any.