1
package org.herac.tuxguitar.gui.editors.tab;
3
import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
4
import org.herac.tuxguitar.song.factory.TGFactory;
5
import org.herac.tuxguitar.song.models.TGMeasureHeader;
7
public class TGMeasureHeaderImpl extends TGMeasureHeader{
9
* Espacio por defecto del timeSignature
11
private static final int DEFAULT_TIME_SIGNATURE_SPACING = 30;
13
* Espacio por defecto a la izquierda
15
private static final int DEFAULT_LEFT_SPACING = 15;
17
* Espacio por defecto a la derecha
19
private static final int DEFAULT_RIGHT_SPACING = 15;
21
private static final int PAINT_TEMPO = 0x01;
23
private static final int PAINT_TRIPLET_FEEL = 0x02;
25
private static final int PAINT_TIME_SIGNATURE = 0x04;
27
private int paintFlags;
29
private int maxQuarterSpacing;
31
private int maxClefSpacing;
33
private int maxKeySignatureSpacing;
37
public TGMeasureHeaderImpl(TGFactory factory){
44
this.maxQuarterSpacing = 0;
45
this.maxClefSpacing = 0;
46
this.maxKeySignatureSpacing = 0;
49
public void update(ViewLayout layout, int index) {
51
this.calculateMeasureChanges(layout);
53
int trackCount = getSong().countTracks();
54
for (int trackIdx = 0; trackIdx < trackCount; trackIdx++) {
55
TGTrackImpl track = (TGTrackImpl)getSong().getTrack(trackIdx);
56
TGMeasureImpl measure = (TGMeasureImpl) track.getMeasure( index );
57
measure.calculateMeasureChanges(layout);
61
public void calculateMeasureChanges(ViewLayout layout) {
62
TGMeasureHeader previous = layout.getSongManager().getPrevMeasureHeader(this);
64
this.paintFlags |= PAINT_TEMPO;
65
this.paintFlags |= ((this.getTripletFeel() != TGMeasureHeader.TRIPLET_FEEL_NONE)?PAINT_TRIPLET_FEEL:0);
66
this.paintFlags |= PAINT_TIME_SIGNATURE;
69
if(this.getTempo().getValue() != previous.getTempo().getValue()){
70
this.paintFlags |= PAINT_TEMPO;
73
if(this.getTripletFeel() != previous.getTripletFeel()){
74
this.paintFlags |= PAINT_TRIPLET_FEEL;
77
int thisNumerator = this.getTimeSignature().getNumerator();
78
int thisValue = this.getTimeSignature().getDenominator().getValue();
79
int prevNumerator = previous.getTimeSignature().getNumerator();
80
int prevValue = previous.getTimeSignature().getDenominator().getValue();
81
if(thisNumerator != prevNumerator || thisValue != prevValue){
82
this.paintFlags |= PAINT_TIME_SIGNATURE;
87
public boolean shouldPaintTempo(){
88
return ( (this.paintFlags & PAINT_TEMPO) != 0 );
91
public boolean shouldPaintTripletFeel(){
92
return ( (this.paintFlags & PAINT_TRIPLET_FEEL) != 0 );
95
public boolean shouldPaintTimeSignature(){
96
return ( (this.paintFlags & PAINT_TIME_SIGNATURE) != 0 );
99
public int getMaxQuarterSpacing() {
100
return this.maxQuarterSpacing;
103
public void notifyQuarterSpacing(int spacing) {
104
this.maxQuarterSpacing = ((spacing > this.maxQuarterSpacing) ? spacing : this.maxQuarterSpacing );
107
public int getClefSpacing(ViewLayout layout, TGMeasureImpl measure){
108
return (!measure.isPaintClef() && (layout.getStyle() & ViewLayout.DISPLAY_MULTITRACK) == 0 ? 0 : this.maxClefSpacing );
111
public int getKeySignatureSpacing(ViewLayout layout, TGMeasureImpl measure){
112
return (!measure.isPaintKeySignature() && (layout.getStyle() & ViewLayout.DISPLAY_MULTITRACK) == 0 ? 0 : this.maxKeySignatureSpacing );
115
public int getTempoSpacing(ViewLayout layout){
116
return (shouldPaintTempo()? Math.round( 45 * layout.getScale() ):0);
119
public int getTripletFeelSpacing(ViewLayout layout){
120
return (shouldPaintTripletFeel()? Math.round( 55 * layout.getScale() ):0);
123
public int getTimeSignatureSpacing(ViewLayout layout){
124
return (shouldPaintTimeSignature()? Math.round( DEFAULT_TIME_SIGNATURE_SPACING * layout.getScale() ):0);
127
public int getLeftSpacing(ViewLayout layout){
128
return Math.round( DEFAULT_LEFT_SPACING * layout.getScale() );
131
public int getRightSpacing(ViewLayout layout){
132
return Math.round( DEFAULT_RIGHT_SPACING * layout.getScale() );
135
public int getFirstNoteSpacing(ViewLayout layout, TGMeasureImpl measure){
136
int topSpacing = getTempoSpacing(layout) + getTripletFeelSpacing(layout);
137
int middleSpacing = getClefSpacing(layout,measure) + getKeySignatureSpacing(layout,measure) + getTimeSignatureSpacing(layout);
139
return Math.round(Math.max( topSpacing , middleSpacing) + (10f * layout.getScale()));
142
public void notifyClefSpacing(int spacing){
143
this.maxClefSpacing = ((spacing > this.maxClefSpacing)?spacing:this.maxClefSpacing);
146
public void notifyKeySignatureSpacing(int spacing){
147
this.maxKeySignatureSpacing = ((spacing > this.maxKeySignatureSpacing) ? spacing : this.maxKeySignatureSpacing);
150
public void notifyWidth(int width){
151
this.maxWidth = ((width > this.maxWidth)?width:this.maxWidth);
154
public int getMaxWidth(){
155
return this.maxWidth;