HOMEWORK ASSIGNMENT #6
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: MyFavoriteMelody.java, CanonMaker.java, TestCanonMaker.java, …, 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)
Set up your PC to work with JFugue. To do so, do the following:
· javac -classpath %CLASSPATH%;jfugue.jar MyMusicApp.java
· java -classpath %CLASSPATH%;jfugue.jar MyMusicApp
To test your updated configuration, compile and execute the sample program MyMusicApp.java .
Create a Java program, MyFavoriteMelody.java, 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).
Create class CanonMaker. This class has, at least, the following methods:
public Pattern retrograde(Pattern phrase), which reverses the phrase.
public Pattern diminute(Pattern phrase), which halves the duration of all notes in the phrase.
public Pattern augment(Pattern phrase), which doubles the duration of all notes in the phrase.
public Pattern shift(Pattern phrase), which shifts the phrase one whole note to the right. (Hint: this equivalent to adding a whole note rest, "Rw ", at the beginning of phrase.)
Your methods should be fully documented (purpose, pre/postconditions, parameter information flow (in, out, in/out), etc.)
You will need to import org.jfugue.*; and also import org.jfugue.demo.*;
To test your class, create a driver called, TestCanonMaker.java, 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):
Demonstrate your PatternFactory through a TestXPatternFactory.java, 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 TestCanonMaker.java
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...
For instance, you could write a composer of canons using LSysMusic.java and CanonMaker.java. 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.