Random Rhythms

Much attention in these tutorials has been placed on the note pitch, however this demo explores aleatoric (randomly influenced music/art) note durations.

To hear the result play this midi file.

 Click here to view or download source

Humans are quite susceptible to changes in timing, and the apparent disorganisation of this random series of rhythms confirms this.

To read a comprehensive background of randomness and automatic processes in music composition with computer check out chapter 10 "Automata" in Joel Chadabe's book "Electric Sound: The past and promise of electronic music." Prentice Hall, 1997.

Lets have a closer look.

import jm.JMC;
import jm.music.data.*;
import jm.util.*;

Lines 1-4 import useful packages that we need to use in the program. The first import statement gets a standard Java class. The rest of the statements import the jMusic classes (to take another look at the package documentation or work out what gets imported from where look at the packages).

public final class RandomRhythm implements JMC{
public static void main(String[] args){
Score score = new Score("JMDemo - Random Rhythm");
Part inst = new Part("Snare", 0, 9);
Phrase phr = new Phrase(0.0);

In this section score, part, and phrase objects are declared.


        for(short i=0;i<24;i++){
Note note = new Note(38, Math.random()*4);
phr.addNote(note);
}

24 notes are added to the phrase. Each note is of the same pitch (snare drum for General MIDI instruments on channel 10) and MIDI channel. They are each given a random duration between 0.0 and 4.0 (nothing and a whole note).


        inst.addPhrase(phr);
score.addPart(inst);

The phrase is added to a part, which in turn is allocated to the score. A score object is required for passing to the MIDI file conversion class.


       Write.midi(score, "randomRhythm.mid");

As with other jMusic demo files, this code creates a MIDI file from the score. Once created the randomRhythm.mid file can be played by any MIDI file player and will sound correctly using a General MIDI sound source, such as most PC sound cards, or Quicktime. The final line provides feedback during execution that the MIDI file has been successfully written.