> Music Algorithms > Generating > Tea for two, or three, or.....Row Your Boat | |||||||||||
Tea for two, or three, or.....Row Your BoatThis tutorial looks at how we can write more than a single concurrent
(meaning simultaneous) voice There are two ways in which to write polyphonic music in jMusic, and
these two paradigms are applied in much the same manner as in the real
world. An orchestral score works similarly to this by containing both monophonic (trumpets, flutes, clarinets etc.) and polyphonic parts like the harp, piano, marimba, and occasionally the string family. To hear the result play the MIDI file below.
The first technique we will investigate is writing for a single part containing multiple lines/voices. Here is the source code.
The first four lines indicate which Java packages (groups of classes)
are required for this class. Because we want to work with the jMusic additions to Java, the import
statements are all parts of the jm package. The final line above declares the class RowYourBoat. It is possible for this line to simply read public class RowYourBoat { but the other words add meaning. Starting at the end, implements JMC allows the class to reference the JMC constants directly. The final statement indicates to the compiler that there will be instances of this class and which allows certain optimisation.
We need a score, so one score object is created. In order to have a number of instruments play the round three Part objects are declared, and set to different MIDI channels. An initial Phrase is declared with a start time of 0.0 and a flute (MIDI program change) timbre selected.
It would be very painful if, for a longish tune like this one, every time we wanted to make a Note object we had to type Note note = new Note(C4, CROTCHET); Luckily for us, jMusic has several nice ways of helping us with this. A way to enter musical information into jMusic is by using arrays. As demonstrated above we can write pitch and rhythm values for each note we want to create into arrays. The number of elements in each array must match up so that the first note we create is a C4 (the first element of the pitchArray) and C (the first element of the rhythmArray), the second a C4 and C, the third a C4 and CT (crotchet triplet) etc... Once we have written the arrays we can send them straight to a phrase as shown above using the addNoteList() method of the phrase class.
Now, we all know that to create a round that we need to start the melody again and again with a delay between each entry. In this example we want a three part round so we are going to need three phrases. We already have the first phrase so we just need two more. We'll call them phrase2 and phrase3 - very imaginative :) Now we could create two empty phrases and add notes to them as we did for the first phrase but there is a nicer way to achieve this, we can just copy the first phrase. We do this by calling the first phrase's copy() method. Phrase phrase2 = phrase1.copy(); This method returns a copy of the phrase object which we assign to the new Phrase named phrase2. We can make a new phrase by copying an old phrase. We also need to set start times for the new phrases because we don't want them to all start at the same time. We do this by calling the setStartTime() method of phrases 2 and 3.
So that we can hear our parts a little more clearly we are going to transpose them. With a call to the transpose() method from the static Mod class to do this. The second part is transposed down one octave (-12 means down twelve semitones). The third phrase is transposed up an octave. We can repeat each phrases so that the round goes for a little bit longer. Mod.repeat(phrase1, 1); indicates that the modification 'repeat' should be applied to phrase1 with a repetition once only. Any positive number could be put in here insted of 1. Each phrase needs to be repeated.
The rest of the example might be familiar from previous tutorials. The
part called 'flute' uses its addPhrase() method to put phrase1 into the
flute part. The addPhrase() method is one of the methods of the Part class.
Notice that we can add as many parts as we like to a score with the addPart() method. If we wanted to we could add more than one phrase to a Part also. We could have one hundred voices playing the round if wanted, although this reminds me of a nightmare I had once about 100 oboes playing in the same place at the same time .....
This line exports the jMusic score as a standard MIDI file. Before going on, try entering your own round and play with the transpositions and repeat lengths. Well, we've come a long way in a short time and we shall give you a break
now and let you go out and enjoy some sunshine. In the mean time, play around with the examples, try to write some of your own, and try to find some information on the web and in books about computer and algorithmic music composition. |
|||||||||||