1 package com.jamesbryangraves.bob.music; 2 3 import java.util.ArrayList; 4 import java.util.Collection; 5 6 import com.jamesbryangraves.bob.util.Translator; 7 8 public class ChordProgression extends DiatonicMusicEventGenerator { 9 10 private int[] pitches; 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 int key = Translator.translate(musicContext.getKey()); 16 Scale scale = musicContext.getScale(); 17 for(long i = 0; i < ticks;) { 18 long value = getNoteValue(ticks - i); 19 if(pitches != null) { 20 for(int j = 0; j < pitches.length; j++) { 21 pitches[j] = getNextPitch(pitches[j], key, scale); 22 events.add(new MusicEvent(pitches[j], value, tick + i)); 23 } 24 } else { 25 pitches = new int[4]; 26 for(int j = 0; j < pitches.length; j++) { 27 pitches[j] = getScalePitch(key, scale); 28 events.add(new MusicEvent(pitches[j], value, tick + i)); 29 } 30 } 31 i += value; 32 } 33 return events; 34 } 35 }