-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scales.java
executable file
·167 lines (135 loc) · 4.63 KB
/
Scales.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import java.util.*;
public class Scales {
private boolean DEBUG;
List myScales = new ArrayList(); //of type aScale
Scales(boolean debug) {
this();
this.DEBUG = debug;
}
Scales(){
this.DEBUG = false;
try{
myScales.add( new AScale("A", "Major") );
myScales.add( new AScale("Bb", "Major") );
myScales.add( new AScale("B", "Major") );
myScales.add( new AScale("C", "Major") );
myScales.add( new AScale("C#", "Major") );
myScales.add( new AScale("D", "Major") );
myScales.add( new AScale("Eb", "Major") );
myScales.add( new AScale("E", "Major") );
myScales.add( new AScale("F", "Major") );
myScales.add( new AScale("F#", "Major") );
myScales.add( new AScale("G", "Major") );
myScales.add( new AScale("Ab", "Major") );
myScales.add( new AScale("A", "Minor") );
myScales.add( new AScale("Bb", "Minor") );
myScales.add( new AScale("B", "Minor") );
myScales.add( new AScale("C", "Minor") );
myScales.add( new AScale("C#", "Minor") );
myScales.add( new AScale("D", "Minor") );
myScales.add( new AScale("Eb", "Minor") );
myScales.add( new AScale("E", "Minor") );
myScales.add( new AScale("F", "Minor") );
myScales.add( new AScale("F#", "Minor") );
myScales.add( new AScale("G", "Minor") );
myScales.add( new AScale("Ab", "Minor") );
}
catch(Exception e){
System.out.println("wrong scale type" + e.toString());
}
}
public void addNote(int addMe){
if (DEBUG) {
System.out.println("adding:" + addMe);
}
for(int i=0; i<myScales.size(); i++){
((AScale)myScales.get(i)).updateCount(addMe);
}
}
public void addSubNote(int addMe){
for(int i=0; i<myScales.size(); i++){
((AScale)myScales.get(i)).updateCount(addMe);
}
}
public AScale getHighestCount(){
double temp = 0, highest = 0;
int pos=0;
List posList = new ArrayList();
for(int i=0; i<myScales.size(); i++){
temp = ((AScale)myScales.get(i)).getScore();
if (temp>highest){
highest = temp;
pos = i;
}
}
//Get all the scales with a tie for highest
for(int i=0; i<myScales.size(); i++){
if(((AScale)myScales.get(i)).getScore() == highest)
posList.add(new Integer(i));
}
if (DEBUG) {
System.out.print("Highest scores: " + highest + " - "); //debugging
//this whole for loop is debugging
for(int i=0; i<myScales.size(); i++){
if(((AScale)myScales.get(i)).getScore() == highest){
System.out.print(((AScale)myScales.get(i)).getScaleKey() + " " +((AScale)myScales.get(i)).getScaleType() + " ");
}
}
}
//select a scale randomly from the highest ties
pos = ((Integer)posList.get( ((int)(posList.size()*Math.random())) )).intValue();
return (AScale)myScales.get(pos);
}
public AScale getSecondHighestCount(){
double temp = 0, highest = 0, secondHighest = 0;
int secondPos=0, highPos = 0;
List posList = new ArrayList();
//get highest first
for(int i=0; i<myScales.size(); i++){
temp = ((AScale)myScales.get(i)).getScore();
if (temp>highest){
highest = temp;
}
}
//then get second highest
for(int i=0; i<myScales.size(); i++){
temp = ((AScale)myScales.get(i)).getScore();
if (temp>secondHighest && temp<highest){
secondHighest = temp;
}
}
if (DEBUG) {
// Get all the scales with a tie for highest
System.out.print("Highest scores: " + highest + " - "); //debugging
//this whole for loop is debugging
for(int i=0; i<myScales.size(); i++){
if(((AScale)myScales.get(i)).getScore() == highest){
System.out.print(((AScale)myScales.get(i)).getScaleKey() + " " +((AScale)myScales.get(i)).getScaleType() + " ");
}
}
System.out.println("\n"); //debugging
}
//Get all the scales with a tie for Second highest
if (DEBUG) {
System.out.print("Second highest scores: " + secondHighest + " - "); //debugging
}
for(int i=0; i<myScales.size(); i++){
if(((AScale)myScales.get(i)).getScore() == secondHighest){
posList.add(new Integer(i));
if (DEBUG) {
System.out.print(((AScale)myScales.get(i)).getScaleKey() + " " +((AScale)myScales.get(i)).getScaleType() + " ");
}
}
}
if (DEBUG) {
System.out.println("\n"); //debugging
}
//select a scale randomly from the highest ties
secondPos = ((Integer)posList.get( ((int)(posList.size()*Math.random())) )).intValue();
return (AScale)myScales.get(secondPos);
}
}
/*
public class MajorScale Extends Scale{
MajorScale
}*/