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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/tab/TGMeasureHeaderImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.gui.editors.tab;
 
2
 
 
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;
 
6
 
 
7
public class TGMeasureHeaderImpl extends TGMeasureHeader{
 
8
        /**
 
9
         * Espacio por defecto del timeSignature
 
10
         */
 
11
        private static final int DEFAULT_TIME_SIGNATURE_SPACING = 30;
 
12
        /**
 
13
         * Espacio por defecto a la izquierda
 
14
         */
 
15
        private static final int DEFAULT_LEFT_SPACING = 15;
 
16
        /**
 
17
         * Espacio por defecto a la derecha
 
18
         */
 
19
        private static final int DEFAULT_RIGHT_SPACING = 15;
 
20
        
 
21
        private static final int PAINT_TEMPO = 0x01;
 
22
        
 
23
        private static final int PAINT_TRIPLET_FEEL = 0x02;
 
24
        
 
25
        private static final int PAINT_TIME_SIGNATURE = 0x04;
 
26
        
 
27
        private int paintFlags;
 
28
        
 
29
        private int maxQuarterSpacing;
 
30
        
 
31
        private int maxClefSpacing;
 
32
        
 
33
        private int maxKeySignatureSpacing;
 
34
        
 
35
        private int maxWidth;
 
36
        
 
37
        public TGMeasureHeaderImpl(TGFactory factory){
 
38
                super(factory);
 
39
        }
 
40
        
 
41
        public void reset() {
 
42
                this.maxWidth = 0;
 
43
                this.paintFlags = 0;
 
44
                this.maxQuarterSpacing = 0;
 
45
                this.maxClefSpacing = 0;
 
46
                this.maxKeySignatureSpacing = 0;
 
47
        }
 
48
        
 
49
        public void update(ViewLayout layout, int index) {
 
50
                this.reset();
 
51
                this.calculateMeasureChanges(layout);
 
52
                
 
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);
 
58
                }
 
59
        }
 
60
        
 
61
        public void calculateMeasureChanges(ViewLayout layout) {
 
62
                TGMeasureHeader previous = layout.getSongManager().getPrevMeasureHeader(this);
 
63
                if(previous == null){
 
64
                        this.paintFlags |= PAINT_TEMPO; 
 
65
                        this.paintFlags |= ((this.getTripletFeel() != TGMeasureHeader.TRIPLET_FEEL_NONE)?PAINT_TRIPLET_FEEL:0);
 
66
                        this.paintFlags |= PAINT_TIME_SIGNATURE;
 
67
                }else{
 
68
                        //Tempo
 
69
                        if(this.getTempo().getValue() != previous.getTempo().getValue()){
 
70
                                this.paintFlags |= PAINT_TEMPO; 
 
71
                        }
 
72
                        //Triplet Feel
 
73
                        if(this.getTripletFeel() != previous.getTripletFeel()){
 
74
                                this.paintFlags |= PAINT_TRIPLET_FEEL;
 
75
                        }
 
76
                        //Time Signature
 
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;
 
83
                        }
 
84
                }
 
85
        }
 
86
        
 
87
        public boolean shouldPaintTempo(){
 
88
                return ( (this.paintFlags & PAINT_TEMPO) != 0 );
 
89
        }
 
90
        
 
91
        public boolean shouldPaintTripletFeel(){
 
92
                return ( (this.paintFlags & PAINT_TRIPLET_FEEL) != 0 );
 
93
        }
 
94
        
 
95
        public boolean shouldPaintTimeSignature(){
 
96
                return ( (this.paintFlags & PAINT_TIME_SIGNATURE) != 0 );
 
97
        }
 
98
        
 
99
        public int getMaxQuarterSpacing() {
 
100
                return this.maxQuarterSpacing;
 
101
        }
 
102
        
 
103
        public void notifyQuarterSpacing(int spacing) {
 
104
                this.maxQuarterSpacing = ((spacing > this.maxQuarterSpacing) ? spacing : this.maxQuarterSpacing );
 
105
        }
 
106
        
 
107
        public int getClefSpacing(ViewLayout layout, TGMeasureImpl measure){
 
108
                return (!measure.isPaintClef() && (layout.getStyle() & ViewLayout.DISPLAY_MULTITRACK) == 0 ? 0 : this.maxClefSpacing );
 
109
        }
 
110
        
 
111
        public int getKeySignatureSpacing(ViewLayout layout, TGMeasureImpl measure){
 
112
                return (!measure.isPaintKeySignature() && (layout.getStyle() & ViewLayout.DISPLAY_MULTITRACK) == 0 ? 0 : this.maxKeySignatureSpacing );
 
113
        }
 
114
        
 
115
        public int getTempoSpacing(ViewLayout layout){
 
116
                return (shouldPaintTempo()? Math.round( 45 * layout.getScale() ):0);
 
117
        }
 
118
        
 
119
        public int getTripletFeelSpacing(ViewLayout layout){
 
120
                return (shouldPaintTripletFeel()? Math.round( 55 * layout.getScale() ):0);
 
121
        }
 
122
        
 
123
        public int getTimeSignatureSpacing(ViewLayout layout){
 
124
                return (shouldPaintTimeSignature()? Math.round( DEFAULT_TIME_SIGNATURE_SPACING * layout.getScale() ):0);
 
125
        }
 
126
        
 
127
        public int getLeftSpacing(ViewLayout layout){
 
128
                return Math.round( DEFAULT_LEFT_SPACING * layout.getScale() );
 
129
        }
 
130
        
 
131
        public int getRightSpacing(ViewLayout layout){
 
132
                return Math.round( DEFAULT_RIGHT_SPACING * layout.getScale() );
 
133
        }
 
134
        
 
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);
 
138
                
 
139
                return Math.round(Math.max( topSpacing , middleSpacing) + (10f * layout.getScale()));
 
140
        }
 
141
        
 
142
        public void notifyClefSpacing(int spacing){
 
143
                this.maxClefSpacing = ((spacing > this.maxClefSpacing)?spacing:this.maxClefSpacing);
 
144
        }
 
145
        
 
146
        public void notifyKeySignatureSpacing(int spacing){
 
147
                this.maxKeySignatureSpacing = ((spacing > this.maxKeySignatureSpacing) ? spacing : this.maxKeySignatureSpacing);
 
148
        }
 
149
        
 
150
        public void notifyWidth(int width){
 
151
                this.maxWidth = ((width > this.maxWidth)?width:this.maxWidth);
 
152
        }
 
153
        
 
154
        public int getMaxWidth(){
 
155
                return this.maxWidth;
 
156
        }
 
157
}