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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/song/models/TGBeat.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.List;
 
11
 
 
12
import org.herac.tuxguitar.song.factory.TGFactory;
 
13
 
 
14
/**
 
15
 * @author julian
 
16
 * 
 
17
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
 
18
 */
 
19
public abstract class TGBeat {
 
20
        private long start;
 
21
        private TGDuration duration;
 
22
        private TGMeasure measure;
 
23
        
 
24
        private List notes;
 
25
        private TGChord chord;
 
26
        private TGText text;
 
27
        
 
28
        public TGBeat(TGFactory factory) {
 
29
                this.start = TGDuration.QUARTER_TIME;
 
30
                this.duration = factory.newDuration();
 
31
                this.notes = new ArrayList();
 
32
        }
 
33
        
 
34
        public long getStart() {
 
35
                return this.start;
 
36
        }
 
37
        
 
38
        public void setStart(long start) {
 
39
                this.start = start;
 
40
        }
 
41
        
 
42
        public TGDuration getDuration() {
 
43
                return this.duration;
 
44
        }
 
45
        
 
46
        public void setDuration(TGDuration duration) {
 
47
                this.duration = duration;
 
48
        }
 
49
        
 
50
        public TGMeasure getMeasure() {
 
51
                return this.measure;
 
52
        }
 
53
        
 
54
        public void setMeasure(TGMeasure measure) {
 
55
                this.measure = measure;
 
56
        }
 
57
        
 
58
        public List getNotes() {
 
59
                return this.notes;
 
60
        }
 
61
        
 
62
        public void addNote(TGNote note){
 
63
                note.setBeat(this);
 
64
                this.notes.add(note);
 
65
        }
 
66
        
 
67
        public void moveNote(int index,TGNote note){
 
68
                getNotes().remove(note);
 
69
                getNotes().add(index,note);
 
70
        }
 
71
        
 
72
        public void removeNote(TGNote note){
 
73
                this.notes.remove(note);
 
74
        }
 
75
        
 
76
        public TGNote getNote(int index){
 
77
                if(index >= 0 && index < countNotes()){
 
78
                        return (TGNote)this.notes.get(index);
 
79
                }
 
80
                return null;
 
81
        }
 
82
        
 
83
        public int countNotes(){
 
84
                return this.notes.size();
 
85
        }
 
86
        
 
87
        public void setChord(TGChord chord) {
 
88
                this.chord = chord;
 
89
                this.chord.setBeat(this);
 
90
        }
 
91
        
 
92
        public TGChord getChord() {
 
93
                return this.chord;
 
94
        }
 
95
        
 
96
        public void removeChord() {
 
97
                this.chord = null;
 
98
        }
 
99
        
 
100
        public TGText getText() {
 
101
                return this.text;
 
102
        }
 
103
        
 
104
        public void setText(TGText text) {
 
105
                this.text = text;
 
106
                this.text.setBeat(this);
 
107
        }
 
108
        
 
109
        public void removeText(){
 
110
                this.text = null;
 
111
        }
 
112
        
 
113
        public boolean isRestBeat(){
 
114
                return this.notes.isEmpty();
 
115
        }
 
116
        
 
117
        public boolean isChordBeat(){
 
118
                return ( this.chord != null );
 
119
        }
 
120
        
 
121
        public boolean isTextBeat(){
 
122
                return ( this.text != null );
 
123
        }
 
124
        
 
125
        public TGBeat clone(TGFactory factory){
 
126
                TGBeat beat = factory.newBeat();
 
127
                beat.setStart(getStart());
 
128
                getDuration().copy(beat.getDuration());
 
129
                
 
130
                for(int i = 0;i < countNotes();i++){
 
131
                        TGNote note = (TGNote)this.notes.get(i);
 
132
                        beat.addNote(note.clone(factory));
 
133
                }
 
134
                if(this.chord != null){
 
135
                        beat.setChord( this.chord.clone(factory));
 
136
                }
 
137
                if(this.text != null){
 
138
                        beat.setText( this.text.clone(factory));
 
139
                }
 
140
                return beat;
 
141
        }
 
142
        
 
143
}
 
 
b'\\ No newline at end of file'