View Javadoc

1   package com.jamesbryangraves.bob.music;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   
6   import com.jamesbryangraves.bob.util.BobUtils;
7   
8   public class Percussion extends MusicEventGenerator {
9   	
10  	private static int[] drumSet = {44, 35, 38, 49};
11  		
12  	public Collection<MusicEvent> generateEvents(MusicContext musicContext, long tick) throws Exception {
13  		ArrayList<MusicEvent> events = new ArrayList<MusicEvent>();
14  		long ticks = musicContext.getTicksPerBar();
15  		for(long i = 0; i < ticks;) {
16  			long value = ticks - i == 1 ? 1 : BobUtils.getRandomInt(2) + 1; //getNoteValue(ticks - i);
17  			int chordSize = BobUtils.getRandomInt(3) + 1;
18  			for(int j = 0; j < chordSize; j++) {
19  				if(BobUtils.getRandomInt(
20  							musicContext.getMeterNumerator() * 
21  							musicContext.getMeterNumerator()) == 1) {
22  					events.add(new MusicEvent(
23  							BobUtils.getRandomInt(127), 
24  							value, tick + i));
25  				} else if(j == 2) {
26  					events.add(new MusicEvent(drumSet[j], value, tick + i));
27  					break;
28  				} else {
29  					events.add(new MusicEvent(drumSet[j], value, tick + i));
30  				}
31  			}		
32  			i += value;
33  		}
34  		return events;
35  	}
36  }