> Music Algorithms > Generating > Journey | |||||||||
Journey: Interlocking theme variationsIn this tutorial we create a composition by making a polyphonic texture from themes derived from the same melodic material. The piece is in two small classes and provides a good example of programming as well as musical structuring processes. Here is an example of the output from the Journey class.
Below is the source code for both the Journey.java
file and the NPart.java file (both are required to run the program). Click here to view Journey.java source Click here to view NPart.java source Lets have a closer look at the Journey class first:
The first few lines import the required jMusic packages and classes. After a comment to describe the piece, the
class is declared. First, a Score object is created at the class level. The first method is main()
in which all we do is create a new instance of the Journey class. The new keyword is important in these lines of code. It is used
to create an instance of the Score
class,
Above is the constructor method for the Journey class. This method provides an overview of our compositional
process. The loop at the top has one line only. This
line uses the new keyword again to create instances of the NPart
class (we'll see more of it below).
This newPart() method saves us some typing because we want to do things
to each part we create. "What does it do?" I hear you ask. The part is added to the score and then passed back to the calling method, and in this case on to the NPart class for further stuffing-around-with. The final curly bracket closes the class. Well, that's the Journey class dealt with. Now let's look at the NPart class in detail:
The import statements provide access to the classes we need for this program. A whole bunch of variables are declared for
use in this class. The part provides a local holder for the Part passed to this class by Journey. pitches and rhythms
hold the data to make up the notes. partLength is the duration of the music in this part in beats (crotchets). fadeInLength and fadeOutLength specify how long it takes to ramp up and down the loudness of notes at the beginning and ending of the part. Compositionally this has the effect of crossfading the parts which makes the piece more interesting. nPartStartTime contains the time (in beats) when the music of this part should begin. panPosition holds the information about where in the stereo spectrum notes from this part should emerge.
There are two methods in this class, the
first (above) is the constructor. Note that it has the same name as
the class. First, the part passed from the Journey class is assigned to the local variable part. Next, an instrument (sound) for this part is calculated at random between between 0 an 59. Then a start time for this class is calculated at random somewhere within the first 200 semiquaver steps of the piece. Each part in this piece has just one Phrase and the last line calls the makePhrase() method to make it and adds it to the part, all in one fowl swoop.
This method generates a phrase based on notes attributes (pitch and rhythm) specified earlier as class variables. First, it makes an empty phrase and sets the start time. Second, it uses the Phrase.addNoteList() method to generate notes based on the pitches and rhythm values provided as arrays earlier. Thirdly, it sets the pan position for each
note in the phrase. The pan position is calculated at random. At this stage the notes in the phrase are
set. But we want each phrase to be somewhat different so we modify the
phase to add variety. The first modification is shuffle()which randomly mixes up the note order of the phrase. The second modification is cycle()
which loops the phrase until it fills the required number of beats. The third and fourth modifications fade in and out the loudness of the notes over a specified length. Finally we pass back the generated and modified phrase to the calling method (above).
Important lessons from this tutorial: The breaking up of this program into many
small methods saves repetitive typing and makes the code easier to read
and changes easier to implement. You should try changing the variables to see how they effect the music,
and then try some more significant changes, perhaps adding different |
|||||||||