2
* Created on 17-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.actions.player;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.TypedEvent;
11
import org.eclipse.swt.widgets.Display;
12
import org.herac.tuxguitar.gui.TuxGuitar;
13
import org.herac.tuxguitar.gui.actions.Action;
14
import org.herac.tuxguitar.gui.editors.TablatureEditor;
15
import org.herac.tuxguitar.gui.helper.SyncThread;
16
import org.herac.tuxguitar.gui.util.MessageDialog;
17
import org.herac.tuxguitar.player.base.MidiPlayer;
18
import org.herac.tuxguitar.song.models.Measure;
23
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
25
public class PlaySongAction extends Action {
26
public static final String NAME = "action.player.play";
28
public PlaySongAction(TablatureEditor tablatureEditor) {
29
super(NAME,true, tablatureEditor);
32
public boolean doAction(TypedEvent e) {
33
MidiPlayer player = TuxGuitar.instance().getPlayer();
34
if(!player.isRunning()){
35
if(checkSoundbank(player)){
37
redrawTablaturePlayMode();
40
Measure measure = getSongManager().getTrackManager().getMeasureAt(getSongManager().getFirstTrack(),player.getTickPosition());
43
player.setTickPosition(measure.getStartWidthRepetitions(),measure.getStartWidthRepetitions() - measure.getStart());
45
getEditor().getTablature().getCaret().goToTickPosition();
46
redrawTablatureStopMode();
51
private boolean checkSoundbank(MidiPlayer player){
52
if(player.getSoundbank() == null){
53
String title = TuxGuitar.getProperty("soundbank.error");
54
String message = TuxGuitar.getProperty("soundbank.error.unavailable");
55
new MessageDialog(title,message,SWT.ICON_ERROR | SWT.OK).show(getEditor().getTablature().getShell());
61
protected void redrawTablaturePlayMode() {
62
final Display display = TuxGuitar.instance().getDisplay();
63
final Runnable playing = new Runnable() {
65
if(TuxGuitar.instance().getPlayer().isRunning()){
66
TuxGuitar.instance().redrawPayingMode();
70
final Runnable finish = new Runnable() {
73
TuxGuitar.instance().updateCache(true);
77
new Thread(new Runnable() {
79
while (TuxGuitar.instance().getPlayer().isRunning()) {
80
if(!display.isDisposed()){
81
display.syncExec(playing);
85
if(!display.isDisposed()){
86
display.syncExec(finish);
92
private void redrawTablatureStopMode(){
93
new SyncThread(new Runnable() {
95
if(!TuxGuitar.isDisposed()){
102
private void sleep(long time){
105
} catch (InterruptedException e) {
b'\\ No newline at end of file'