audio MIDI Music Algorithms Interfaces Programming Acoustics Context
> Music Algorithms > Modifying > Implying a sense of Meter    
 
   

Implying a sense of Meter

This program passes a phrase and adds accents on the downbeats according to the hard-coded time signature.
It works regardless of the phrase's start time relative to the beginning of the score.

The process is achieved by running through the following loop:

  1. Create a phrase filled with random notes to apply the accents to.
  2. Apply the accents with the accents() method
  3. The accents() method:
    1. get the phrase's StartTime and create a variable to store the offset;
    2. get the next note in the phrase's noteList;
    3. check to see if it falls on an accented beat, and if it does, add the accent;
    4. add the note's rhythmDuration to the offset variable and move onto the next note;

This is what the result of this tutorial file sounds like:

Click here to view source

Let's have a closer look.
import jm.JMC;
import jm.music.data.*;
import jm.midi.*;
import jm.util.*;
import java.util.Vector;
 
/**=========================================================
* The accents method puts strong dynamics at the
* beginning of every bar assuming the meter is
* 7/8, 7/8, 7/8, 3/8
* Other metres can be made by modifying the == statements
* in the accents() method
* @author Andrew R. Brown and Marian Collier
*========================================================= */

 
public final class Meter implements JMC{

public static void main(String[] args) {
new Meter();
}

Setup all the usual jMusic stuff. Instantiate the Meter class within the main() method. Notice that the hard-coded meter is 7/8, 7/8, 7/8, 3/8.

    public Meter() {
Part p = new Part();
for(int j=0;j<10;j++) { //make lots of phrases
Phrase phr = new Phrase((double)(int)(Math.random()*8.0));
int pitch = (int)(Math.random()*50)+50;
for(int i = 0; i<100; i ++) { //make lots of notes
Note n2 = new Note(pitch,(int)
(Math.random()*2+1)*0.5,(int)(Math.random()*30+50));
phr.addNote(n2);
}
//do accents
accents(phr);
p.addPhrase(phr);
}

Score s= new Score();
s.addPart(p);

Write.midi(s, "Meter.mid");
}

The Meter() constructor method: Sets up a loop which makes a phrase, fills it with 100 notes (all notes in the one phrase have the same randomly selected pitch, but have different rhythmic and dynamic values), and apply the accents() method to the phrase. Once this is done, write the phrase to the part, and, when all the phrases have been created and processed, create the Score and MIDI file.

    public static void accents(Phrase phrase) {
double beatCounter = phrase.getStartTime();
Vector v = phrase.getNoteList();
for(int i=0;i<v.size();i++) {
Note n = (Note)v.elementAt(i);
if (beatCounter%12 == 0.0 || beatCounter%12 == 3.5 ||
beatCounter%12 == 7.0 || beatCounter%12 == 10.5)
n.setDynamic(127);
beatCounter += n.getRhythmValue();
}
}
}

The accents() method accepts a phrase, and alters the Dynamic of particular notes within it to accent certain beats depending on the hard-coded meter.
In this case, the meter (7/8, 7/8, 7/8, 3/8) is equal to 24/8 or 12/4. Hence, the beatCounter is divided by 12 and the remainder (modulus) decides if each note should be accented. This can be altered by changing the conditions of the if() statement. For example, if the meter was 3/4, the if() statement would read:

if (beatCounter%3 == 0.0) n.setDynamic(127);
 

This would accent every third beat. Potentially, a second if command could be setup to create weaker accents on other beats.

This class shows the whole process of adding accents. There is a

Mod.accents()method 
which encapsultes all this code and can be used to add accents to a jMusic piece. Check out the details in the documentation.

 

 

jMusic Australia Council Queensland University of Technology Sitemap Contact Home Home http://www.qut.com http://explodingart.com/jmusic http://www.ozco.gov.au

Digital Instrument making Home