1 package fi.jyu.mit.Music;
2
3 import java.util.Iterator;
4 import java.util.LinkedList;
5 import java.util.List;
6
7
12 public class NoteTrack implements Iterable<Note> {
13 private List<Note> noteBuffer;
14
15 private int instrument = 1;
16 private int startTime = 0;
17
18 public int getStartTime() {
19 return startTime;
20 }
21
22 public int getCurrentTime() {
23 int t = getStartTime();
24 for (Note n:noteBuffer) t += n.getLength();
25 return t;
26 }
27
28 public void setStartTime(int startTime) {
29 this.startTime = startTime;
30 }
31
32 private boolean muted = false;
33
34 public NoteTrack() {
35 noteBuffer = new LinkedList<Note>();
36 }
37
38 public int getInstrument() {
39 return instrument;
40 }
41
42 public void setInstrument(int instrument) {
43 this.instrument = instrument;
44 }
45
46
50 public List<Note>getCopyOfNotes() {
51 List<Note> notes = new LinkedList<Note>();
52 for (Note n:noteBuffer)
53 notes.add(new Note(n));
54 return notes;
55 }
56
57
61 public List<Note>getNotes() {
62 return noteBuffer;
63 }
64
65
68 public void midiSoundNote(int note, int length, int velocity) {
69 noteBuffer.add(new Note(note, length, velocity));
70 }
71
72 public void rest(final int barLength) {
73 if (barLength < 0)
75 return;
76 noteBuffer.add(new Note.Delay(barLength));
77 }
78
79 public void add(Note note) {
80 noteBuffer.add(note);
81 }
82
83 @Override
84 public Iterator<Note> iterator() {
85 return noteBuffer.iterator();
86 }
87
88 public boolean isEmpty() {
89 return noteBuffer.isEmpty();
90 }
91
92 public Note remove(int index) {
93 return noteBuffer.remove(index);
94 }
95
96 public void mute(boolean muted) {
97 this.muted = muted;
98 }
99
100 public boolean isMuted() {
101 return muted;
102 }
103
104
105 public String toString() {
106 return noteBuffer.toString();
107 }
108
109
110 }
111