> Music Algorithms > Generating > Letter Melody | |||||||
Letter MelodyThis is an example of rule based composition. This is what the result of this tutorial file can sound like. The sentence typed was 'every good boy deserves fish and chips':
Click here to view the source file.. The Guido Word Music tutorial is based upon this idea but is much more comprehensive. Let's have a closer look:
The classes needed for jMusic are imported for use.
The class is declared and the main method started. The jMusic data types of score, part, and phrase are declared using default values (no arguments) for convenience. Often the String[] array called args is not used, but in this example it is. When the program is run a sentence is typed as an argument. That sentence is used by the program to generate the melody.
This is the heart of the program. The string array (args) is cycled through, word by word. Each word is cycled through character by character. To ensure that all is working there are System.out.println statements outputting the words and letters. Each letter is checked by a series of 'if' statements. this is the basis of rule-based composition. Each 'if' statement represents a rule, and each rule is checked. You can easily add additional rules. In this case lower case characters between a and g result in a new note being added to the phrase. The last rule adds a rest if the comma is found.
Take a break (on jMusic)Congratulations on getting this far. At this stage of the tutorial you know enough to work out this next demo on your own. have a listen, then download the java file and look through it yourself. We've made the MIDI file below loop so you can have the soothing tones of stochastic music sooth you while you examine the code. To hear the result play the MIDI file below.
To keep it playing while you read, open the link below in a new browser window. |
|||||||