1
package org.herac.tuxguitar.gui.editors.tab;
3
import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
5
public class TGBeatGroup {
6
private static final int SCORE_MIDDLE_KEYS[] = new int[]{55,40,40,50};
7
private static final int SCORE_SHARP_POSITIONS[] = new int[]{7,7,6,6,5,4,4,3,3,2,2,1};
8
private static final int SCORE_FLAT_POSITIONS[] = new int[]{7,6,6,5,5,4,3,3,2,2,1,1};
10
public static final int DIRECTION_UP = 1;
11
public static final int DIRECTION_DOWN = 2;
13
private static final int UP_OFFSET = 28;
14
private static final int DOWN_OFFSET = 35;
16
private int direction;
17
private TGNoteImpl firstMinNote;
18
private TGNoteImpl firstMaxNote;
19
private TGNoteImpl lastMinNote;
20
private TGNoteImpl lastMaxNote;
21
private TGNoteImpl maxNote;
22
private TGNoteImpl minNote;
25
this.direction = DIRECTION_UP;
26
this.firstMinNote = null;
27
this.firstMaxNote = null;
28
this.lastMinNote = null;
29
this.lastMaxNote = null;
34
public void check(TGNoteImpl note,int clef){
35
int value = note.getRealValue();
38
if(this.firstMinNote == null || note.getBeat().getStart() < this.firstMinNote.getBeat().getStart()){
39
this.firstMinNote = note;
40
}else if(note.getBeat().getStart() == this.firstMinNote.getBeat().getStart()){
41
if(note.getRealValue() < this.firstMinNote.getRealValue()){
42
this.firstMinNote = note;
46
if(this.firstMaxNote == null || note.getBeat().getStart() < this.firstMaxNote.getBeat().getStart()){
47
this.firstMaxNote = note;
48
}else if(note.getBeat().getStart() == this.firstMaxNote.getBeat().getStart()){
49
if(note.getRealValue() > this.firstMaxNote.getRealValue()){
50
this.firstMaxNote = note;
55
if(this.lastMinNote == null || note.getBeat().getStart() > this.lastMinNote.getBeat().getStart()){
56
this.lastMinNote = note;
57
}else if(note.getBeat().getStart() == this.lastMinNote.getBeat().getStart()){
58
if(note.getRealValue() < this.lastMinNote.getRealValue()){
59
this.lastMinNote = note;
63
if(this.lastMaxNote == null || note.getBeat().getStart() > this.lastMaxNote.getBeat().getStart()){
64
this.lastMaxNote = note;
65
}else if(note.getBeat().getStart() == this.lastMaxNote.getBeat().getStart()){
66
if(note.getRealValue() > this.lastMaxNote.getRealValue()){
67
this.lastMaxNote = note;
71
if(this.maxNote == null || value > this.maxNote.getRealValue()){
74
if(this.minNote == null || value < this.minNote.getRealValue()){
78
int max = Math.abs(this.minNote.getRealValue() - (SCORE_MIDDLE_KEYS[clef - 1] + 100));
79
int min = Math.abs(this.maxNote.getRealValue() - (SCORE_MIDDLE_KEYS[clef - 1] - 100));
81
this.direction = DIRECTION_UP;
83
this.direction = DIRECTION_DOWN;
87
public int getY1(ViewLayout layout,TGNoteImpl note,int key,int clef){
88
double scale = (layout.getScoreLineSpacing() / 2.00);
89
int noteValue = note.getRealValue();
93
scoreLineY = (int)((SCORE_SHARP_POSITIONS[noteValue % 12]) * scale - (7 * (noteValue / 12)) * scale);
95
scoreLineY = (int)((SCORE_FLAT_POSITIONS[noteValue % 12]) * scale - (7 * (noteValue / 12)) * scale);
98
scoreLineY += TGMeasureImpl.SCORE_KEY_OFFSETS[clef - 1] * scale;
103
public int getY2(ViewLayout layout,int x,int key,int clef){
104
int maxDistance = 10;
105
float upOffset = TGBeatGroup.getUpOffset(layout);
106
float downOffset = TGBeatGroup.getDownOffset(layout);
107
if(this.direction == DIRECTION_DOWN){
108
if(this.minNote != this.firstMinNote && this.minNote != this.lastMinNote){
109
return (int) (getY1(layout,this.minNote,key,clef) + downOffset);
112
int x1 = this.firstMinNote.getPosX() + this.firstMinNote.getBeatImpl().getSpacing();
113
int x2 = this.lastMinNote.getPosX() + this.lastMinNote.getBeatImpl().getSpacing();
114
int y1 = (int) (getY1(layout,this.firstMinNote,key,clef) + downOffset);
115
int y2 = (int) (getY1(layout,this.lastMinNote,key,clef) + downOffset);
117
if(y1 > y2 && (y1 - y2) > maxDistance) y2 = (y1 - maxDistance);
118
if(y2 > y1 && (y2 - y1) > maxDistance) y1 = (y2 - maxDistance);
119
int y = (int)((((double)y1 -(double)y2) / ((double)x1 - (double)x2)) * ((double)x1 - (double)x));
121
}else if(this.maxNote != this.firstMaxNote && this.maxNote != this.lastMaxNote){
122
return (int)(getY1(layout,this.maxNote,key,clef) - upOffset);
124
int x1 = this.firstMaxNote.getPosX() + this.firstMaxNote.getBeatImpl().getSpacing();
125
int x2 = this.lastMaxNote.getPosX() + this.lastMaxNote.getBeatImpl().getSpacing();
126
int y1 = (int)(getY1(layout,this.firstMaxNote,key,clef) - upOffset);
127
int y2 = (int)(getY1(layout,this.lastMaxNote,key,clef) - upOffset);
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));
136
public int getDirection() {
137
return this.direction;
140
public TGNoteImpl getMinNote(){
144
public TGNoteImpl getMaxNote(){
148
public static float getUpOffset(ViewLayout layout){
149
float scale = (layout.getScoreLineSpacing() / 8.0f);
150
return (UP_OFFSET * scale);
153
public static float getDownOffset(ViewLayout layout){
154
float scale = (layout.getScoreLineSpacing() / 8.0f);
155
return (DOWN_OFFSET * scale);