1
package org.herac.tuxguitar.gui.editors.tab;
3
import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
6
public class MeasureTimeHelper {
7
private static final int SCORE_MIDDLE_KEYS[] = new int[]{55,40,40,50};
8
private static final int SCORE_SHARP_POSITIONS[] = new int[]{7,7,6,6,5,4,4,3,3,2,2,1};
9
private static final int SCORE_FLAT_POSITIONS[] = new int[]{7,6,6,5,5,4,3,3,2,2,1,1};
11
public static final int DIRECTION_UP = 1;
12
public static final int DIRECTION_DOWN = 2;
14
public static final int UP_OFFSET = 28;
15
public static final int DOWN_OFFSET = 35;
17
private int direction;
18
private NoteCoords firstMinNote;
19
private NoteCoords firstMaxNote;
20
private NoteCoords lastMinNote;
21
private NoteCoords lastMaxNote;
22
private NoteCoords maxNote;
23
private NoteCoords minNote;
25
public MeasureTimeHelper(){
26
this.direction = DIRECTION_UP;
27
this.firstMinNote = null;
28
this.firstMaxNote = null;
29
this.lastMinNote = null;
30
this.lastMaxNote = null;
35
public void check(NoteCoords note,int clef){
36
int value = note.getRealValue();
39
if(firstMinNote == null || note.getStart() < firstMinNote.getStart()){
41
}else if(note.getStart() == firstMinNote.getStart()){
42
if(note.getRealValue() < firstMinNote.getRealValue()){
47
if(firstMaxNote == null || note.getStart() < firstMaxNote.getStart()){
49
}else if(note.getStart() == firstMaxNote.getStart()){
50
if(note.getRealValue() > firstMaxNote.getRealValue()){
56
if(lastMinNote == null || note.getStart() > lastMinNote.getStart()){
58
}else if(note.getStart() == lastMinNote.getStart()){
59
if(note.getRealValue() < lastMinNote.getRealValue()){
64
if(lastMaxNote == null || note.getStart() > lastMaxNote.getStart()){
66
}else if(note.getStart() == lastMaxNote.getStart()){
67
if(note.getRealValue() > lastMaxNote.getRealValue()){
72
if(maxNote == null || value > maxNote.getRealValue()){
75
if(minNote == null || value < minNote.getRealValue()){
79
int max = Math.abs(minNote.getRealValue() - (SCORE_MIDDLE_KEYS[clef - 1] + 100));
80
int min = Math.abs(maxNote.getRealValue() - (SCORE_MIDDLE_KEYS[clef - 1] - 100));
82
this.direction = DIRECTION_UP;
84
this.direction = DIRECTION_DOWN;
88
public int getY1(ViewLayout layout,NoteCoords note,int key,int clef){
89
double scale = (layout.getScoreLineSpan() / 2.00);
90
int noteValue = note.getRealValue();
94
scoreLineY = (int)((SCORE_SHARP_POSITIONS[noteValue % 12]) * scale - (7 * (noteValue / 12)) * scale);
96
scoreLineY = (int)((SCORE_FLAT_POSITIONS[noteValue % 12]) * scale - (7 * (noteValue / 12)) * scale);
99
scoreLineY += MeasureCoords.SCORE_KEY_OFFSETS[clef - 1] * scale;
104
public int getY2(ViewLayout layout,int x,int key,int clef){
105
int maxDistance = 10;
106
if(direction == DIRECTION_DOWN){
107
if(minNote != firstMinNote && minNote != lastMinNote){
108
return getY1(layout,minNote,key,clef) + DOWN_OFFSET;
111
int x1 = firstMinNote.getPosX() + firstMinNote.getSpan();
112
int x2 = lastMinNote.getPosX() + lastMinNote.getSpan();
113
int y1 = getY1(layout,firstMinNote,key,clef) + DOWN_OFFSET;
114
int y2 = getY1(layout,lastMinNote,key,clef) + DOWN_OFFSET;
116
if(y1 > y2 && (y1 - y2) > maxDistance) y2 = (y1 - maxDistance);
117
if(y2 > y1 && (y2 - y1) > maxDistance) y1 = (y2 - maxDistance);
118
int y = (int)((((double)y1 -(double)y2) / ((double)x1 - (double)x2)) * ((double)x1 - (double)x));
121
if(maxNote != firstMaxNote && maxNote != lastMaxNote){
122
return getY1(layout,maxNote,key,clef) - UP_OFFSET;
124
int x1 = firstMaxNote.getPosX() + firstMaxNote.getSpan();
125
int x2 = lastMaxNote.getPosX() + lastMaxNote.getSpan();
126
int y1 = getY1(layout,firstMaxNote,key,clef) - UP_OFFSET;
127
int y2 = getY1(layout,lastMaxNote,key,clef) - UP_OFFSET;
129
if(y1 < y2 && (y2 - y1) > maxDistance) y2 = (y1 + maxDistance);
130
if(y2 < y1 && (y1 - y2) > maxDistance) y1 = (y2 + maxDistance);
131
int y = (int)((((double)y1 -(double)y2) / ((double)x1 - (double)x2)) * ((double)x1 - (double)x));
137
public int getDirection() {
141
public NoteCoords getMinNote(){
145
public NoteCoords getMaxNote(){