> Music Algorithms > Modifying > Forms: Arranging phrases | ||||||||||||
Forms: Arranging phrasesThis class shows how you can experiment with different arrangements of
phrases. To hear the results play the MIDI files below. Binary and Ternary form respectively.
Lets have a closer look at what just happened.
The jm/music/data directory has the jm data structure classes, such as phrase. The jm/midi directory has the classes used to write a MIDI file of the score.
To confirm the part is empty its length is printed to the screen. Further printouts follow which trace the change in size of the part as phrases are added to it. Notice that Score and Part declarations need not take any arguments. This is important for the Part in this example, as it defaults to a start time of -1.0. This makes no sense, but is used as a flag by the Part to add it to the end of the Part. In this way you don't need to calculate the start time yourself - jMusic will simply add the Phrases (with a start time of -1.0) to the Part in sequential order (like notes in a phrase).
The first line in this section is a comment. The next two add new phrases to the part 'p'. They do so by calling the makePhrase1() and makePhrase2() methods which are described in detail below. The part now has two phrases in it. The part is added to the score 's'. The last line prints out the current length of the part 'p' which will be equal to the combined lengths of the two phrases within it.
All jm scores have the ability to write themselves as MIDI files in this way, which is why the line starts with the name of the score ('s' in this case).
An alternative would be to create a new score and part for the second form but this is just as neat, and shows you the empty() methods as well :)
The second form is ternary - phrase 2 followed by phrase 1 followed by phrase 2 again. After being created the length of the part is printed and the score is written to a MIDI file.
The makePhrase1() method simply creates an ascending chromatic scale. Because we reuse the phrase several times it is efficient to have it as a separate method which can be called whenever required. Notice that the method returns a Phrase object, which is why the first line of the method is private static Phrase ... rather than private static void ...(the void key word indicates that no value is returned by the method).
Try modifying the class to produce a third score with a different form structure. |
||||||||||||