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.
- Set up
your PC to work with jMusic. To do
so, follow the jMusic
installation instructions.
- Open
BlueJ, go to Preferences --> Libraries --> Add,
and add jmusic.jar to the list of libraries
known to BlueJ.
- Test
your installation by compiling and executing the sample program Bing.java
.
- Create
a Java program, MyFavoriteMelody.java,
to save one of your favorite melodies, as a MIDI file. See MyFavoriteMelody.java,
for an example.
- Create
class CanonPhrase.
This class should extend jMusic's class Phrase
and should have, at least, the following methods:
- constructor
that accepts a Phrase.
- public void retrograde(), which
reverses the phrase.
- public void diminute(), which
halves the duration of all notes in the phrase.
- public void augment(), which
doubles the duration of all notes in the phrase.
- public void shift(double startTime),
which shifts the phrase the specified number of beats.
public CanonPhrase copy(), which returns a deep copy of this canon phrase.
- Hint: See class Mod.
- And
now, the fun part: Create class Canon. It should have, at least, the following methods:
- constructor
that accepts a CanonPhrase,
also known as the canon "leader" phrase.
- 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).
- Bonus: Using code design similar to RoyalTheme.java,
create one or more classes which encapsulate different canons:
- Class CrabCanon,
which extends Score. It should
have only a default constructor and toString().
- 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):
- MyFavoriteMelody.java
and generated MIDI file, MyFavoriteMelody.mid
- CanonPhrase.java,
Canon.java and generated
MIDI file, Canon.mid
- (Optional) CrabCanon.java
and generated MIDI file, CrabCanon.mid
(use similar style for other bonus material).
Notes:
- Familiarize
yourself with the following jMusic documentation (bold-font are
recommended, regular-font are only for reference):
- tutorials
(Dots
and Dashes -- note that there are several pages, Round/Canon,
Mozart
Dice Game)
- constants
(Duration,
Instruments,
Scales,
Volumes)
- APIs
(Note,
Rest,
Score,
Part,
Phrase,
Mod,
Write,
Play,
View,
Read).
- 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).
- 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.
- Here are some Free Scores, if you know how to
read sheet music (see note values, rhythm values).
- Here
is a virus-free program you could use to convert a MIDI file to text,
if necessary (search for "MIDI File Disassembler/Assembler").