View Javadoc

1   package com.jamesbryangraves.bob.music;
2   
3   import java.util.List;
4   
5   
6   public class Scale {
7   	
8   	private List<ScaleState> scaleStates;
9   	private List<Integer> scaleSteps;
10  	private int scaleSize;
11  	
12  	public int getNextNote(int note, int root) {
13  		int scaleStep = (note % scaleSize) < (root % scaleSize) ?
14  				((note % scaleSize) + 12) - (root % scaleSize) :
15  					(note % scaleSize) - (root % scaleSize);
16  		int i = 0;
17  		while(i < scaleSteps.size() - 1 && 
18  				scaleSteps.get(i).intValue() != scaleStep)
19  				i++;
20  		return scaleStates.get(i).getUp() + note;
21  	}
22  	
23  	public int getScaleSize() {
24  		return scaleSize;
25  	}
26  
27  	public void setScaleSize(int scaleSize) {
28  		this.scaleSize = scaleSize;
29  	}
30  
31  	public int getPreviousNote(int note, int root) {
32  		int scaleStep = (note % scaleSize) < (root % scaleSize) ?
33  				((note % scaleSize) + 12) - (root % scaleSize) :
34  					(note % scaleSize) - (root % scaleSize);	
35  		int i = 0;
36  		while(i < scaleSteps.size() - 1 &&
37  				scaleSteps.get(i).intValue() != scaleStep)
38  				i++;			
39  		return scaleStates.get(i).getDown() + note;
40  	}
41  			
42  	public boolean contains(int note, int root) {
43  		
44  		int scaleStep = (note % 12) < (root % 12) ?
45  				((note % 12) + 12) - (root % 12) :
46  					(note % 12) - (root % 12);
47  		for(int i = 0; i < scaleSteps.size(); i++)
48  			if(scaleSteps.get(i).intValue() == scaleStep)
49  				return true;
50  		return false;
51  	}
52  
53  	public List<ScaleState> getScaleStates() {
54  		return scaleStates;
55  	}
56  
57  	public void setScaleStates(List<ScaleState> scaleStates) {
58  		this.scaleStates = scaleStates;
59  	}
60  
61  	public List<Integer> getScaleSteps() {
62  		return scaleSteps;
63  	}
64  
65  	public void setScaleSteps(List<Integer> scaleSteps) {
66  		this.scaleSteps = scaleSteps;
67  	}
68  	
69  }