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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/song/models/TGMeasureHeader.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 26-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 org.herac.tuxguitar.song.factory.TGFactory;
 
10
 
 
11
/**
 
12
 * @author julian
 
13
 *
 
14
 * TODO To change the template for this generated type comment go to
 
15
 * Window - Preferences - Java - Code Style - Code Templates
 
16
 */
 
17
public abstract class TGMeasureHeader {
 
18
        public static final int TRIPLET_FEEL_NONE = 1;
 
19
        public static final int TRIPLET_FEEL_EIGHTH = 2;
 
20
        public static final int TRIPLET_FEEL_SIXTEENTH = 3;
 
21
        
 
22
        private int number;
 
23
        private long start;
 
24
        private TGTimeSignature timeSignature;
 
25
        private TGTempo tempo;
 
26
        private TGMarker marker;
 
27
        private boolean repeatOpen;
 
28
        private int repeatAlternative;
 
29
        private int repeatClose;
 
30
        private int tripletFeel;
 
31
        private TGSong song;
 
32
        
 
33
        public TGMeasureHeader(TGFactory factory){
 
34
                this.number = 0;
 
35
                this.start = TGDuration.QUARTER_TIME;
 
36
                this.timeSignature = factory.newTimeSignature();
 
37
                this.tempo = factory.newTempo();
 
38
                this.marker = null;
 
39
                this.tripletFeel = TRIPLET_FEEL_NONE;
 
40
                this.repeatOpen = false;
 
41
                this.repeatClose = 0;
 
42
                this.repeatAlternative = 0;
 
43
                this.checkMarker();
 
44
        }
 
45
        
 
46
        public int getNumber() {
 
47
                return this.number;
 
48
        }
 
49
        
 
50
        public void setNumber(int number) {
 
51
                this.number = number;
 
52
                this.checkMarker();
 
53
        }
 
54
        
 
55
        public int getRepeatClose() {
 
56
                return this.repeatClose;
 
57
        }
 
58
        
 
59
        public void setRepeatClose(int repeatClose) {
 
60
                this.repeatClose = repeatClose;
 
61
        }
 
62
        
 
63
        public int getRepeatAlternative() {
 
64
                return this.repeatAlternative;
 
65
        }
 
66
        
 
67
        /**
 
68
         * bitwise value 1 TO 8.
 
69
         * (1 << AlternativeNumber)
 
70
         */
 
71
        public void setRepeatAlternative(int repeatAlternative) {
 
72
                this.repeatAlternative = repeatAlternative;
 
73
        }
 
74
        
 
75
        public boolean isRepeatOpen() {
 
76
                return this.repeatOpen;
 
77
        }
 
78
        
 
79
        public void setRepeatOpen(boolean repeatOpen) {
 
80
                this.repeatOpen = repeatOpen;
 
81
        }
 
82
        
 
83
        public long getStart() {
 
84
                return this.start;
 
85
        }
 
86
        
 
87
        public void setStart(long start) {
 
88
                this.start = start;
 
89
        }
 
90
        
 
91
        public int getTripletFeel() {
 
92
                return this.tripletFeel;
 
93
        }
 
94
        
 
95
        public void setTripletFeel(int tripletFeel) {
 
96
                this.tripletFeel = tripletFeel;
 
97
        }
 
98
        
 
99
        public TGTempo getTempo() {
 
100
                return this.tempo;
 
101
        }
 
102
        
 
103
        public void setTempo(TGTempo tempo) {
 
104
                this.tempo = tempo;
 
105
        }
 
106
        
 
107
        public TGTimeSignature getTimeSignature() {
 
108
                return this.timeSignature;
 
109
        }
 
110
        
 
111
        public void setTimeSignature(TGTimeSignature timeSignature) {
 
112
                this.timeSignature = timeSignature;
 
113
        }
 
114
        
 
115
        public TGMarker getMarker() {
 
116
                return this.marker;
 
117
        }
 
118
        
 
119
        public void setMarker(TGMarker marker) {
 
120
                this.marker = marker;
 
121
        }
 
122
        
 
123
        public boolean hasMarker(){
 
124
                return (getMarker() != null);
 
125
        }
 
126
        
 
127
        private void checkMarker(){
 
128
                if(hasMarker()){
 
129
                        this.marker.setMeasure(getNumber());
 
130
                }
 
131
        }
 
132
        
 
133
        public long getLength(){
 
134
                return getTimeSignature().getNumerator() * getTimeSignature().getDenominator().getTime();
 
135
        }
 
136
        
 
137
        public TGSong getSong() {
 
138
                return this.song;
 
139
        }
 
140
        
 
141
        public void setSong(TGSong song) {
 
142
                this.song = song;
 
143
        }
 
144
        
 
145
        public void makeEqual(TGMeasureHeader measure){
 
146
                this.start = measure.getStart();
 
147
                this.timeSignature = measure.getTimeSignature();
 
148
                this.tempo = measure.getTempo();
 
149
                this.marker = measure.getMarker();
 
150
                this.repeatOpen = measure.isRepeatOpen();
 
151
                this.repeatClose = measure.getRepeatClose();
 
152
                this.repeatAlternative = measure.getRepeatAlternative();
 
153
                this.checkMarker();
 
154
        }
 
155
        
 
156
        public TGMeasureHeader clone(TGFactory factory){
 
157
                TGMeasureHeader header = factory.newHeader();
 
158
                header.setNumber(getNumber());
 
159
                header.setStart(getStart());
 
160
                header.setRepeatOpen(isRepeatOpen());
 
161
                header.setRepeatAlternative(getRepeatAlternative());
 
162
                header.setRepeatClose(getRepeatClose());
 
163
                header.setTripletFeel(getTripletFeel());
 
164
                getTimeSignature().copy(header.getTimeSignature());
 
165
                getTempo().copy(header.getTempo());
 
166
                header.setMarker(hasMarker()?(TGMarker)getMarker().clone(factory):null);
 
167
                return header;
 
168
        }
 
169
}