1
package org.herac.tuxguitar.gui.editors;
3
import org.herac.tuxguitar.gui.TuxGuitar;
4
import org.herac.tuxguitar.gui.editors.tab.Caret;
5
import org.herac.tuxguitar.gui.editors.tab.TGBeatImpl;
6
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
7
import org.herac.tuxguitar.gui.util.MidiTickUtil;
8
import org.herac.tuxguitar.song.managers.TGSongManager;
9
import org.herac.tuxguitar.song.models.TGBeat;
10
import org.herac.tuxguitar.song.models.TGMeasure;
11
import org.herac.tuxguitar.song.models.TGTrack;
13
public class EditorCache {
16
private boolean editUpdate;
17
private TGBeatImpl editBeat;
20
private int playTrack;
21
private long playTick;
22
private long playStart;
23
private long playBeatEnd;
24
private boolean playChanges;
25
private boolean playUpdate;
26
private TGBeatImpl playBeat;
27
private TGMeasureImpl playMeasure;
38
private void resetEditMode(){
40
this.editUpdate = false;
43
private void resetPlayMode(){
45
this.playMeasure = null;
46
this.playUpdate = false;
47
this.playChanges = false;
54
public void updateEditMode(){
55
this.editUpdate = true;
60
public void updatePlayMode(){
61
this.playUpdate = true;
66
public TGBeatImpl getEditBeat() {
68
this.editBeat = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getSelectedBeat();
69
this.editUpdate = false;
74
public TGBeatImpl getPlayBeat(){
76
this.playChanges = false;
78
TGSongManager manager = TuxGuitar.instance().getSongManager();
79
if(TuxGuitar.instance().getPlayer().isRunning()){
80
Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
81
TGTrack track = caret.getTrack();
83
long tick = TuxGuitar.instance().getPlayer().getTickPosition();
84
long start = this.playStart + (tick - this.playTick);
85
if(this.playMeasure == null || start < this.playMeasure.getStart() || start > (this.playMeasure.getStart() + this.playMeasure.getLength())){
86
this.playMeasure = null;
87
start = MidiTickUtil.getStart(tick);
90
if(this.playMeasure == null || this.playBeatEnd == 0 || start > this.playBeatEnd || start < this.playStart || track.getNumber() != this.playTrack){
93
this.playChanges = true;
95
if(this.playMeasure == null || !this.playMeasure.hasTrack(track.getNumber()) || !isPlaying(this.playMeasure)){
96
this.playMeasure = (TGMeasureImpl)manager.getTrackManager().getMeasureAt(track,start);
98
if (this.playMeasure != null) {
99
this.playBeat = (TGBeatImpl)manager.getMeasureManager().getBeatIn(this.playMeasure, start);
100
if(this.playBeat != null){
101
this.playBeatEnd = (this.playBeat.getStart() + this.playBeat.getDuration().getTime());
105
this.playTrack = track.getNumber();
106
this.playTick = tick;
107
this.playStart = start;
109
this.playUpdate = false;
111
return this.playBeat;
114
public long getPlayTick(){
115
return this.playTick;
118
public long getPlayStart(){
119
return this.playStart;
122
public TGMeasureImpl getPlayMeasure(){
123
return this.playMeasure;
126
public boolean shouldRedraw(){
127
return this.playChanges;
130
public boolean isPlaying(TGMeasure measure){
131
return (TuxGuitar.instance().getPlayer().isRunning() && this.playMeasure != null && measure.equals(this.playMeasure));
134
public boolean isPlaying(TGMeasure measure,TGBeat b){
135
return (isPlaying(measure) && this.playStart >= b.getStart() && this.playStart < (b.getStart() + b.getDuration().getTime()));