~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 29-nov-2005
3
 
 *
4
 
 * TODO To change the template for this generated file go to
5
 
 * Window - Preferences - Java - Code Style - Code Templates
6
 
 */
7
 
package org.herac.tuxguitar.gui.editors.tab;
8
 
 
9
 
import java.util.ArrayList;
10
 
import java.util.Iterator;
11
 
import java.util.List;
12
 
 
13
 
import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
14
 
import org.herac.tuxguitar.song.managers.SongManager;
15
 
import org.herac.tuxguitar.song.models.Measure;
16
 
import org.herac.tuxguitar.song.models.SongTrack;
17
 
 
18
 
/**
19
 
 * @author julian
20
 
 * 
21
 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
22
 
 */
23
 
public class SongTrackCoords {           
24
 
    private Tablature tablature;
25
 
    private SongManager songManager;
26
 
    private SongTrack track;
27
 
    private List measuresCoords;
28
 
    private LyricPainter lyricPainter;
29
 
    
30
 
    private int tabHeight;
31
 
    private int scoreHeight;
32
 
    
33
 
    public SongTrackCoords(Tablature tablature,SongManager songManager,SongTrack track,ViewLayout layout) {
34
 
        this.tablature = tablature;
35
 
        this.track = track;
36
 
        this.songManager = songManager;
37
 
        this.measuresCoords = new ArrayList();
38
 
        this.lyricPainter = new LyricPainter(this);
39
 
        this.calculateTabHeight(layout);
40
 
        this.calculateScoreHeight(layout);
41
 
    }
42
 
    
43
 
    
44
 
    /**
45
 
     * Calcula el el ancho de la tablatura
46
 
     */
47
 
    public void calculateTabHeight(ViewLayout layout) {
48
 
        this.tabHeight = ((layout.isTablatureEnabled())?((getTrack().stringCount() - 1) * layout.getStringSpan()):0);
49
 
    }
50
 
    
51
 
    /**
52
 
     * Calcula el el ancho de la partitura
53
 
     */
54
 
    public void calculateScoreHeight(ViewLayout layout) {
55
 
        this.scoreHeight = ((layout.isScoreEnabled())?(layout.getScoreLineSpan() * 5):0);
56
 
    }
57
 
    
58
 
    public List getMeasuresCoords(){
59
 
        return this.measuresCoords;
60
 
    }
61
 
    
62
 
    public SongTrack getTrack(){
63
 
        return this.track;
64
 
    }
65
 
    
66
 
    public MeasureCoords getFirstMeasure(){
67
 
        MeasureCoords firstMeasure = null;    
68
 
        for(int measureIdx = 0;measureIdx < measuresCoords.size();measureIdx++){
69
 
            MeasureCoords currMeasure = (MeasureCoords)measuresCoords.get(measureIdx);
70
 
            if(firstMeasure == null || (currMeasure.getMeasure().getStart() < firstMeasure.getMeasure().getStart())){
71
 
                firstMeasure = currMeasure;
72
 
            }
73
 
        }        
74
 
        return firstMeasure;
75
 
    }     
76
 
 
77
 
    public MeasureCoords getLastMeasure(){
78
 
        int lastIndex = this.measuresCoords.size() - 1; 
79
 
        return (MeasureCoords)measuresCoords.get(lastIndex);
80
 
    }      
81
 
    
82
 
    public MeasureCoords getPrevMeasure(MeasureCoords measureCoords){
83
 
        int prevNumber = measureCoords.getMeasure().getNumber() - 1;
84
 
        int prevIndex = prevNumber - 1;
85
 
        if(prevIndex >= 0){
86
 
            return (MeasureCoords)measuresCoords.get(prevIndex);
87
 
        }        
88
 
        return null;
89
 
    }      
90
 
    
91
 
    public MeasureCoords getNextMeasure(MeasureCoords measureCoords){
92
 
        int nextNumber = measureCoords.getMeasure().getNumber() + 1; 
93
 
        int nextIndex = nextNumber - 1; 
94
 
        if(nextIndex < measuresCoords.size()){
95
 
            return (MeasureCoords)measuresCoords.get(nextIndex);
96
 
        }
97
 
        return null;        
98
 
    }       
99
 
 
100
 
    public MeasureCoords getMeasureCoords(long start){
101
 
        MeasureCoords measureCoords = null;
102
 
        for (int measureIdx = 0; measureIdx < this.measuresCoords.size(); measureIdx++) {
103
 
            MeasureCoords measure = (MeasureCoords) this.measuresCoords.get(measureIdx);  
104
 
            long measureStart = measure.getMeasure().getStart();
105
 
            long measureLength = measure.getMeasure().getLength();
106
 
            if(start >= measureStart && start < measureStart + measureLength){
107
 
                return measure;
108
 
            }
109
 
        }     
110
 
        return null;
111
 
    }          
112
 
    
113
 
    public MeasureCoords getMeasure(Measure measure){
114
 
        MeasureCoords measureCoords = null;
115
 
        for (int measureIdx = 0; measureIdx < this.measuresCoords.size(); measureIdx++) {
116
 
            MeasureCoords currMeasure = (MeasureCoords) this.measuresCoords.get(measureIdx);            
117
 
            if(currMeasure.getMeasure().equals(measure)){
118
 
                measureCoords = currMeasure;
119
 
                break;
120
 
            }
121
 
        }     
122
 
        return measureCoords;
123
 
    }      
124
 
 
125
 
    public MeasureCoords getMeasureAt(int x,int y){
126
 
        MeasureCoords measure = null;     
127
 
        int minorDistance = 0;
128
 
        
129
 
        
130
 
        Iterator it = measuresCoords.iterator();
131
 
        while(it.hasNext()){           
132
 
            MeasureCoords m = (MeasureCoords)it.next();
133
 
                if(!m.isOutOfBounds() && m.getTs() != null){            
134
 
                        boolean isAtX = (x >= m.getPosX() && x <= m.getPosX() + m.getWidth() + m.getSpan());
135
 
                        if(isAtX){
136
 
                                int measureHeight = m.getTs().getSize();
137
 
                                int distanceY = Math.min(Math.abs(y - (m.getPosY())),Math.abs(y - ( m.getPosY() + measureHeight - 10)));
138
 
                                if(measure == null || distanceY < minorDistance){
139
 
                                        measure = m;
140
 
                                        minorDistance = distanceY;
141
 
                                }
142
 
                        }
143
 
                }
144
 
        }        
145
 
            
146
 
        return measure;
147
 
    }
148
 
    
149
 
    public boolean hasCaret(){
150
 
        return (this.equals(this.tablature.getCaret().getSongTrackCoords()));
151
 
    }
152
 
 
153
 
    public int getTabHeight() {
154
 
                return tabHeight;
155
 
        }
156
 
    
157
 
    public int getScoreHeight() {
158
 
                return scoreHeight;
159
 
        }
160
 
 
161
 
        public void setTabHeight(int tabHeight) {
162
 
                this.tabHeight = tabHeight;
163
 
        }
164
 
 
165
 
        public LyricPainter getLyricPainter(){
166
 
        return this.lyricPainter;
167
 
    }
168
 
}
 
 
b'\\ No newline at end of file'