~ubuntu-branches/ubuntu/karmic/tuxguitar/karmic

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
package org.herac.tuxguitar.gui.editors.tab;

import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
import org.herac.tuxguitar.song.factory.TGFactory;
import org.herac.tuxguitar.song.models.TGMeasureHeader;

public class TGMeasureHeaderImpl extends TGMeasureHeader{
	/**
	 * Espacio por defecto del timeSignature
	 */
	private static final int DEFAULT_TIME_SIGNATURE_SPACING = 30;
	/**
	 * Espacio por defecto a la izquierda
	 */
	private static final int DEFAULT_LEFT_SPACING = 15;
	/**
	 * Espacio por defecto a la derecha
	 */
	private static final int DEFAULT_RIGHT_SPACING = 15;
	
	private static final int PAINT_TEMPO = 0x01;
	
	private static final int PAINT_TRIPLET_FEEL = 0x02;
	
	private static final int PAINT_TIME_SIGNATURE = 0x04;
	
	private int paintFlags;
	
	private int maxQuarterSpacing;
	
	private int maxClefSpacing;
	
	private int maxKeySignatureSpacing;
	
	private int maxWidth;
	
	public TGMeasureHeaderImpl(TGFactory factory){
		super(factory);
	}
	
	public void reset() {
		this.maxWidth = 0;
		this.paintFlags = 0;
		this.maxQuarterSpacing = 0;
		this.maxClefSpacing = 0;
		this.maxKeySignatureSpacing = 0;
	}
	
	public void update(ViewLayout layout, int index) {
		this.reset();
		this.calculateMeasureChanges(layout);
		
		int trackCount = getSong().countTracks();
		for (int trackIdx = 0; trackIdx < trackCount; trackIdx++) {
			TGTrackImpl track = (TGTrackImpl)getSong().getTrack(trackIdx);
			TGMeasureImpl measure = (TGMeasureImpl) track.getMeasure( index );
			measure.calculateMeasureChanges(layout);
		}
	}
	
	public void calculateMeasureChanges(ViewLayout layout) {
		TGMeasureHeader previous = layout.getSongManager().getPrevMeasureHeader(this);
		if(previous == null){
			this.paintFlags |= PAINT_TEMPO; 
			this.paintFlags |= ((this.getTripletFeel() != TGMeasureHeader.TRIPLET_FEEL_NONE)?PAINT_TRIPLET_FEEL:0);
			this.paintFlags |= PAINT_TIME_SIGNATURE;
		}else{
			//Tempo
			if(this.getTempo().getValue() != previous.getTempo().getValue()){
				this.paintFlags |= PAINT_TEMPO; 
			}
			//Triplet Feel
			if(this.getTripletFeel() != previous.getTripletFeel()){
				this.paintFlags |= PAINT_TRIPLET_FEEL;
			}
			//Time Signature
			int thisNumerator = this.getTimeSignature().getNumerator();
			int thisValue = this.getTimeSignature().getDenominator().getValue();
			int prevNumerator = previous.getTimeSignature().getNumerator();
			int prevValue = previous.getTimeSignature().getDenominator().getValue();
			if(thisNumerator != prevNumerator || thisValue != prevValue){
				this.paintFlags |= PAINT_TIME_SIGNATURE;
			}
		}
	}
	
	public boolean shouldPaintTempo(){
		return ( (this.paintFlags & PAINT_TEMPO) != 0 );
	}
	
	public boolean shouldPaintTripletFeel(){
		return ( (this.paintFlags & PAINT_TRIPLET_FEEL) != 0 );
	}
	
	public boolean shouldPaintTimeSignature(){
		return ( (this.paintFlags & PAINT_TIME_SIGNATURE) != 0 );
	}
	
	public int getMaxQuarterSpacing() {
		return this.maxQuarterSpacing;
	}
	
	public void notifyQuarterSpacing(int spacing) {
		this.maxQuarterSpacing = ((spacing > this.maxQuarterSpacing) ? spacing : this.maxQuarterSpacing );
	}
	
	public int getClefSpacing(ViewLayout layout, TGMeasureImpl measure){
		return (!measure.isPaintClef() && (layout.getStyle() & ViewLayout.DISPLAY_MULTITRACK) == 0 ? 0 : this.maxClefSpacing );
	}
	
	public int getKeySignatureSpacing(ViewLayout layout, TGMeasureImpl measure){
		return (!measure.isPaintKeySignature() && (layout.getStyle() & ViewLayout.DISPLAY_MULTITRACK) == 0 ? 0 : this.maxKeySignatureSpacing );
	}
	
	public int getTempoSpacing(ViewLayout layout){
		return (shouldPaintTempo()? Math.round( 45 * layout.getScale() ):0);
	}
	
	public int getTripletFeelSpacing(ViewLayout layout){
		return (shouldPaintTripletFeel()? Math.round( 55 * layout.getScale() ):0);
	}
	
	public int getTimeSignatureSpacing(ViewLayout layout){
		return (shouldPaintTimeSignature()? Math.round( DEFAULT_TIME_SIGNATURE_SPACING * layout.getScale() ):0);
	}
	
	public int getLeftSpacing(ViewLayout layout){
		return Math.round( DEFAULT_LEFT_SPACING * layout.getScale() );
	}
	
	public int getRightSpacing(ViewLayout layout){
		return Math.round( DEFAULT_RIGHT_SPACING * layout.getScale() );
	}
	
	public int getFirstNoteSpacing(ViewLayout layout, TGMeasureImpl measure){
		int topSpacing = getTempoSpacing(layout) + getTripletFeelSpacing(layout);
		int middleSpacing = getClefSpacing(layout,measure) + getKeySignatureSpacing(layout,measure) + getTimeSignatureSpacing(layout);
		
		return Math.round(Math.max( topSpacing , middleSpacing) + (10f * layout.getScale()));
	}
	
	public void notifyClefSpacing(int spacing){
		this.maxClefSpacing = ((spacing > this.maxClefSpacing)?spacing:this.maxClefSpacing);
	}
	
	public void notifyKeySignatureSpacing(int spacing){
		this.maxKeySignatureSpacing = ((spacing > this.maxKeySignatureSpacing) ? spacing : this.maxKeySignatureSpacing);
	}
	
	public void notifyWidth(int width){
		this.maxWidth = ((width > this.maxWidth)?width:this.maxWidth);
	}
	
	public int getMaxWidth(){
		return this.maxWidth;
	}
}