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: 
      
        - Create a phrase filled with random notes 
          to apply the accents to. 
 
        - Apply the accents with the accents() method 
        
 
        - The accents() method: 
          
            - get the phrase's StartTime 
              and create a variable to store the offset; 
 
            - get the next note in the phrase's noteList; 
            
 
            - check to see if it falls on an accented 
              beat, and if it does, add the accent; 
 
            - 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;   | 
           
        
       
      
      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++) {  	    Phrase phr = new Phrase((double)(int)(Math.random()*8.0)); 	    int pitch = (int)(Math.random()*50)+50; 	    for(int i = 0; i<100; i ++) {  		Note n2 = new Note(pitch,(int) 		    (Math.random()*2+1)*0.5,(int)(Math.random()*30+50)); 		phr.addNote(n2); 	    } 	      	    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. 
       
       |