1 package net.kreatious.pianoleopard.midi.track;
2
3 import javax.sound.midi.Track;
4
5 import net.kreatious.pianoleopard.intervalset.IntervalSet;
6 import net.kreatious.pianoleopard.midi.event.Event;
7 import net.kreatious.pianoleopard.midi.event.EventPair;
8 import net.kreatious.pianoleopard.midi.event.NoteEvent;
9 import net.kreatious.pianoleopard.midi.event.PedalEvent;
10 import net.kreatious.pianoleopard.midi.event.TempoCache;
11
12
13
14
15
16
17 class ImmutableParsedTrack implements ParsedTrack {
18 private final IntervalSet<EventPair<NoteEvent>> notes;
19 private final IntervalSet<EventPair<PedalEvent>> pedals;
20
21
22
23
24
25
26
27
28
29
30 ImmutableParsedTrack(Track track, TempoCache cache) {
31 notes = new IntervalSet<>();
32 pedals = new IntervalSet<>();
33 new TrackVisitor() {
34 @Override
35 @SuppressWarnings("unchecked")
36 protected void visitEventPair(EventPair<? extends Event> pair) {
37 if (pair.getOff() instanceof NoteEvent) {
38 notes.put(pair.getOnTime(), pair.getOffTime(), (EventPair<NoteEvent>) pair);
39 } else if (pair.getOff() instanceof PedalEvent) {
40 pedals.put(pair.getOnTime(), pair.getOffTime(), (EventPair<PedalEvent>) pair);
41 }
42 }
43 }.accept(track, cache);
44 }
45
46 @Override
47 public Iterable<EventPair<NoteEvent>> getNotePairs(long low, long high) {
48 return notes.subSet(low, high);
49 }
50
51 @Override
52 public Iterable<EventPair<PedalEvent>> getPedalPairs(long low, long high) {
53 return pedals.subSet(low, high);
54 }
55 }