CSCI 221
HOMEWORK ASSIGNMENT #2
Assigned Date: Wednesday, February 9, 2005 (sec 2 +1 day)
Due Date: Thursday, February 17, 2005 (sec 2 +1 day)
Due Time: Noon

 

Updated: Tuesday, February 15, 3:35pm
Friday, February 11, 1:30pm

 

Purpose:

This assignment focuses on using data abstractions, object-oriented design, and having fun!

 

Background: 

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. 

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 canons are particularly mathematical in nature. Bach also played clever games with music. For example, a sheet of music with his "Crab Canon" on it can literally be turned upside down and remain unchanged. M. C. 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)

 

Documentation:

See previous assignment. In addition, all methods should document their preconditions and postconditions using the Javadoc throws keyword.

 

Assignment:

You will write a set of programs that generate music. To do so you will employ a set of classes from jMusic.

 

  1. Set up your PC to work with jMusic. To do so, follow the jMusic installation instructions.
  2. Open BlueJ, go to Preferences --> Libraries --> Add, and add jmusic.jar to the list of libraries known to BlueJ.
  3. Test your installation by compiling and executing the sample program Bing.java .
  4. Create a Java program, MyFavoriteMelody.java, to save one of your favorite melodies, as a MIDI file.  See MyFavoriteMelody.java, for an example.
  5. Create class CanonPhrase.  This class should extend jMusic's class Phrase and should have, at least, the following methods:
    1. constructor that accepts a Phrase.
    2. public void retrograde(), which reverses the phrase.
    3. public void diminute(), which halves the duration of all notes in the phrase.
    4. public void augment(), which doubles the duration of all notes in the phrase.
    5. public void shift(double startTime), which shifts the phrase the specified number of beats.
    6. public CanonPhrase copy(), which returns a deep copy of this canon phrase.
    7. Hint: See class Mod.
  1. And now, the fun part: Create class Canon. It should have, at least, the following methods:
    1. constructor that accepts a CanonPhrase, also known as the canon "leader" phrase.
    2. public Score compose(), which should return a canon composed from the above leader.

i.         For now, just use the transformation(s) that would return Bach's Crab Canon (see Canon 1, Cancrizans, in Canons of the Musical Offering and Math and the Musical Offering), assuming that the class constructor was called with the Royal Theme as its parameter.

ii.       For your convenience, here is the Royal Theme (RoyalTheme.java).

  1. Bonus: Using code design similar to RoyalTheme.java, create one or more classes which encapsulate different canons:
    1. Class CrabCanon, which extends Score. It should have only a default constructor and toString().
    2. One or more (up to three) classes that encapsulate J.S. Bach canons (more beautiful, more points).

Best Solutions:

Submission:

Send a single email, with all files to be graded attached individually (do not zip), to manaris@cs.cofc.edu, by the due date and time. Your email should have the following individual attachments (again, do not archive):

  1. MyFavoriteMelody.java and generated MIDI file, MyFavoriteMelody.mid
  2. CanonPhrase.java, Canon.java and generated MIDI file, Canon.mid
  3. (Optional) CrabCanon.java and generated MIDI file, CrabCanon.mid (use similar style for other bonus material).

 

Notes:

  1. Familiarize yourself with the following jMusic documentation (bold-font are recommended, regular-font are only for reference):
    1. tutorials (Dots and Dashes -- note that there are several pages, Round/Canon, Mozart Dice Game)
    2. constants (Duration, Instruments, Scales, Volumes)
    3. APIs (Note, Rest, Score, Part, Phrase, Mod, Write, Play, View, Read).
    4. Remember: jMusic includes both British and American names for note durations. For example, whole note = semibreve; half note = minim; quarter note = crochet; eighth note = quaver (if this is new to you, see note values, rhythm values).
  1. You should modularize and document your code thoroughly. Your methods should be fully documented, i.e., purpose, pre/postconditions, parameter information flow (in, out, in/out), etc. Each Java file should have a certificate of authenticity, as per first homework.
  2. Here are some Free Scores, if you know how to read sheet music (see note values, rhythm values).
  3. Here is a virus-free program you could use to convert a MIDI file to text, if necessary (search for "MIDI File Disassembler/Assembler").