1
package org.herac.tuxguitar.gui.editors;
3
import java.util.ArrayList;
4
import java.util.Iterator;
7
import org.herac.tuxguitar.gui.TuxGuitar;
8
import org.herac.tuxguitar.gui.editors.tab.Caret;
9
import org.herac.tuxguitar.gui.editors.tab.MeasureComponent;
10
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
11
import org.herac.tuxguitar.song.managers.SongManager;
12
import org.herac.tuxguitar.song.models.SongTrack;
14
public class EditorCache {
16
private List playingComponents;
17
private List caretComponents;
18
private boolean playingUpdate;
19
private boolean caretUpdate;
21
//Variables para el cache de reproduccion
22
private MeasureCoords playingMeasure;
23
private int lastTrack;
24
private long lastTick;
25
private long playBeatEnd;
26
private boolean playingChanges;
34
this.playingComponents = new ArrayList();
35
this.caretComponents = new ArrayList();
36
this.playingUpdate = false;
37
this.caretUpdate = false;
39
this.playingMeasure = null;
43
this.playingChanges = false;
46
public void updateCaretMode(){
47
this.caretUpdate = true;
50
public void updatePlayingMode(){
51
this.playingUpdate = true;
52
this.getPlayingComponents();
55
public List getCaretComponents() {
57
this.caretComponents.clear();
58
Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
59
MeasureCoords measure = caret.getMeasureCoords();
60
if (measure != null) {
61
this.caretComponents = measure.getComponents(caret.getPosition());
63
this.caretUpdate = false;
65
return this.caretComponents;
68
public List getPlayingComponents(){
69
if(this.playingUpdate){
70
playingChanges = false;
72
SongManager manager = TuxGuitar.instance().getSongManager();
73
if(TuxGuitar.instance().getPlayer().isRunning()){
74
long tick = TuxGuitar.instance().getPlayer().getTickPosition();
75
Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
76
SongTrack track = caret.getSongTrackCoords().getTrack();
78
if(playingMeasure == null || playBeatEnd == 0 || tick > playBeatEnd || tick < lastTick || track.getNumber() != lastTrack){
79
this.playingComponents.clear();
81
this.playingChanges = true;
83
if(playingMeasure == null || !playingMeasure.hasTrack((int)track.getNumber()) || !playingMeasure.isPlaying()){
84
playingMeasure = caret.getSongTrackCoords().getMeasure(manager.getTrackManager().getMeasureAt(track,tick));
86
if (playingMeasure != null) {
87
this.playingComponents = playingMeasure.getComponentsBetween(tick);
89
Iterator it = this.playingComponents.iterator();
91
MeasureComponent component = (MeasureComponent)it.next();
92
long componentEnd = (component.getStart() + component.getDuration().getTime());
93
if(playBeatEnd == 0 || componentEnd < playBeatEnd){
94
playBeatEnd = componentEnd;
99
this.lastTrack = track.getNumber();
100
this.lastTick = tick;
103
this.playingUpdate = false;
106
return this.playingComponents;
109
public MeasureCoords getPlayingMeasure(){
110
return this.playingMeasure;
114
public boolean shouldRedraw(){
115
return this.playingChanges;