> Music Algorithms > Generating > Chaotic Counterpoint | ||||||||
Chaotic CounterpointThis demo produces a two part chaotic counterpoint. If you have music notation software which will show parts on the same stave in different colours, then try importing the MIDI file from this class and visually see the increasing bifurcation. For an overview of chaotic systems and their musical uses read The Computer Music Tutorial (Roads 1996) from p.886. Also read Computer Music (Dodge & Jerse 1997) from p.371. To hear the result play the MIDI file below.
Let's have a closer look.
Lines 1-4 import useful packages that we need to use in the program. The first import statement gets a standard Java class used for error messages. The rest of the statements import the jMusic classes (take another look at the package documentation to work out what gets imported from where by looking here).
All the work is done in the main method which starts here . This section of the method sets up the attributes to be used. First are the usual suspects of Score, Part, and Phrase. There are two phrases (of course) - one for each line. Then a number of variables which will be used by the fractal algorithm are set up. XOLD is the past x value, and YOLD is the past y value, which are later given starting values. The details of the algorithm will not be discussed here - refer to the references above (or others) for details on the math.
The initial values for the system are set with these two lines. Some initial values will result in oscillating (repeating) output while others result in never-ending change. These values are of the latter sort (they come from the Dodge and Jerse book, Computer Music). As you can see above the maths for chaos theory is really quite straight forward - especially compared to Fractal theory. Just two lines. The x value only is used in the output and is mapped to pitch, each note is a quaver [eighth note] in length. Notice that because the math calculates in floating point numbers the result is cast (converted) to an integer - this is what the '(int)' does. The value is multiplied by 36 then has 48 added to it to bring it into a 'reasonable' range for MIDI notes from the C below middle C up three octaves. After the note is created and added to the phrase the values of x and y are stored as previous values and the loop continues until 48 notes are created.
This code is exactly the same as the previous section except that the starting value for x (a) is 0.001 greater, and notes are added to phrase 2.
The phrases are added to a part which is added to the score. Then the score is converted to a standard MIDI file (SMF) and written to disk with the name 'chaos.mid'. |
||||||||