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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/song/models/TGTrack.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 23-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.song.models;
 
8
 
 
9
import java.util.ArrayList;
 
10
import java.util.Iterator;
 
11
import java.util.List;
 
12
 
 
13
import org.herac.tuxguitar.song.factory.TGFactory;
 
14
/**
 
15
 * @author julian
 
16
 *
 
17
 * TODO To change the template for this generated type comment go to
 
18
 * Window - Preferences - Java - Code Style - Code Templates
 
19
 */
 
20
public abstract class TGTrack {
 
21
        public static final int MAX_OFFSET = 24;
 
22
        public static final int MIN_OFFSET = -24;
 
23
        
 
24
        private int number;
 
25
        private int offset;     
 
26
        private String name;
 
27
        private List measures;
 
28
        private List strings;
 
29
        private TGChannel channel;
 
30
        private TGColor color;
 
31
        private TGLyric lyrics;
 
32
        private TGSong song;
 
33
        
 
34
        public TGTrack(TGFactory factory) {
 
35
                this.number = 0;
 
36
                this.offset = 0;
 
37
                this.name = new String();
 
38
                this.measures = new ArrayList();
 
39
                this.strings = new ArrayList();
 
40
                this.channel = factory.newChannel();
 
41
                this.color = factory.newColor();
 
42
                this.lyrics = factory.newLyric();
 
43
        }
 
44
        
 
45
        public int getNumber() {
 
46
                return this.number;
 
47
        }
 
48
        
 
49
        public void setNumber(int number) {
 
50
                this.number = number;
 
51
        }
 
52
        
 
53
        public Iterator getMeasures() {
 
54
                return this.measures.iterator();
 
55
        }
 
56
        
 
57
        public void addMeasure(TGMeasure measure){
 
58
                measure.setTrack(this);
 
59
                this.measures.add(measure);
 
60
        }
 
61
        
 
62
        public void addMeasure(int index,TGMeasure measure){
 
63
                measure.setTrack(this);
 
64
                this.measures.add(index,measure);
 
65
        }
 
66
        
 
67
        public TGMeasure getMeasure(int index){
 
68
                if(index >= 0 && index < countMeasures()){
 
69
                        return (TGMeasure)this.measures.get(index);
 
70
                }
 
71
                return null;
 
72
        }
 
73
        
 
74
        public void removeMeasure(int index){
 
75
                this.measures.remove(index);
 
76
        }
 
77
        
 
78
        public int countMeasures(){
 
79
                return this.measures.size();
 
80
        }
 
81
        
 
82
        public TGChannel getChannel() {
 
83
                return this.channel;
 
84
        }
 
85
        
 
86
        public void setChannel(TGChannel channel) {
 
87
                this.channel = channel;
 
88
        }
 
89
        
 
90
        public List getStrings() {
 
91
                return this.strings;
 
92
        }
 
93
        
 
94
        public void setStrings(List strings) {
 
95
                this.strings = strings;
 
96
        }
 
97
        
 
98
        public TGColor getColor() {
 
99
                return this.color;
 
100
        }
 
101
        
 
102
        public void setColor(TGColor color) {
 
103
                this.color = color;
 
104
        }
 
105
        
 
106
        public String getName() {
 
107
                return this.name;
 
108
        }
 
109
        
 
110
        public void setName(String name) {
 
111
                this.name = name;
 
112
        }
 
113
        
 
114
        public int getOffset() {
 
115
                return this.offset;
 
116
        }
 
117
        
 
118
        public void setOffset(int offset) {
 
119
                this.offset = offset;
 
120
        }
 
121
        
 
122
        public TGLyric getLyrics() {
 
123
                return this.lyrics;
 
124
        }
 
125
        
 
126
        public void setLyrics(TGLyric lyrics) {
 
127
                this.lyrics = lyrics;
 
128
        }
 
129
        
 
130
        public TGString getString(int number){
 
131
                return (TGString)this.strings.get(number - 1);
 
132
        }
 
133
        
 
134
        public int stringCount(){
 
135
                return this.strings.size();
 
136
        }
 
137
        
 
138
        public boolean isPercussionTrack(){
 
139
                return (getChannel().isPercussionChannel());
 
140
        }
 
141
        
 
142
        public TGSong getSong() {
 
143
                return this.song;
 
144
        }
 
145
        
 
146
        public void setSong(TGSong song) {
 
147
                this.song = song;
 
148
        }
 
149
        
 
150
        public void clear(){
 
151
                this.strings.clear();
 
152
                this.measures.clear();
 
153
        }
 
154
        
 
155
        public TGTrack clone(TGFactory factory,TGSong song){
 
156
                TGTrack track = factory.newTrack();
 
157
                copy(factory, song, track);
 
158
                return track;
 
159
        }
 
160
        
 
161
        public void copy(TGFactory factory,TGSong song,TGTrack track){
 
162
                track.clear();
 
163
                track.setNumber(getNumber());
 
164
                track.setName(getName());
 
165
                track.setOffset(getOffset());
 
166
                getChannel().copy(track.getChannel());
 
167
                getColor().copy(track.getColor());
 
168
                getLyrics().copy(track.getLyrics());
 
169
                for (int i = 0; i < getStrings().size(); i++) {
 
170
                        TGString string = (TGString) getStrings().get(i);
 
171
                        track.getStrings().add(string.clone(factory));
 
172
                }
 
173
                for (int i = 0; i < countMeasures(); i++) {
 
174
                        TGMeasure measure = getMeasure(i);
 
175
                        track.addMeasure(measure.clone(factory,song.getMeasureHeader(i)));
 
176
                }
 
177
        }
 
178
        
 
179
}