-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimingStuff.java
56 lines (48 loc) · 1.83 KB
/
TimingStuff.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
import java.util.ArrayList;
import java.util.Collections;
public class TimingStuff {
public static ArrayList<Note> getThreePositions(ArrayList<Note> measure, Note note) {
//we are getting 3 different positions, all the notes in those positions
Collections.sort(measure);
int index = measure.indexOf(note);
int notePosition = note.getPosition();
ArrayList<Note> atSamePosition = new ArrayList<Note>();
ArrayList<Note> atNextPosition = new ArrayList<Note>();
ArrayList<Note> atPrevPosition = new ArrayList<Note>();
int count = index + 1;
//Get all notes at the same position, forwards
//NOTE: won't be in order, shouldn't matter though since they are all at the same position
while(measure.get(count).getPosition() == notePosition && count < measure.size()){
atSamePosition.add(measure.get(count));
count++;
}
//get all notes at the next position
if(count < measure.size()){
int nextPosition = measure.get(count).getPosition();
while(measure.get(count).getPosition() == nextPosition && count < measure.size()){
atNextPosition.add(measure.get(count));
count++;
}
}
//get all notes at the same position, backwards
count = index - 1;
while(measure.get(count).getPosition() == notePosition && count >= 0){
atSamePosition.add(measure.get(count));
count--;
}
//get all notes at the previous position
if(count > 0){
int prevPosition = measure.get(count).getPosition();
while(measure.get(count).getPosition() == prevPosition && count >= 0){
atPrevPosition.add(measure.get(count));
count--;
}
}
ArrayList<Note> finalList = new ArrayList<Note>();
finalList.addAll(atSamePosition);
finalList.addAll(atPrevPosition);
finalList.addAll(atNextPosition);
return finalList;
}
//doesn't account for going out of the current measure... don't know if we need to do that
}