2
* Created on 20-mar-2006
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.transport;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.MouseAdapter;
11
import org.eclipse.swt.events.MouseEvent;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.events.TypedEvent;
15
import org.eclipse.swt.graphics.Font;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.Scale;
21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.ToolBar;
23
import org.eclipse.swt.widgets.ToolItem;
24
import org.herac.tuxguitar.gui.SystemImages;
25
import org.herac.tuxguitar.gui.TuxGuitar;
26
import org.herac.tuxguitar.gui.actions.player.PlaySongAction;
27
import org.herac.tuxguitar.gui.actions.player.StopSongAction;
28
import org.herac.tuxguitar.player.base.MidiPlayer;
29
import org.herac.tuxguitar.song.managers.SongManager;
30
import org.herac.tuxguitar.song.models.Duration;
31
import org.herac.tuxguitar.song.models.MeasureHeader;
36
* TODO To change the template for this generated type comment go to Window -
37
* Preferences - Java - Code Style - Code Templates
39
public class SongTransport {
40
public static final int STATUS_STOPED = 1;
41
public static final int STATUS_PAUSED = 2;
42
public static final int STATUS_RUNNING = 3;
46
private Scale tickScale;
47
private ToolItem first;
48
private ToolItem last;
49
private ToolItem previous;
50
private ToolItem next;
51
private ToolItem stop;
52
private ToolItem play;
53
private boolean editingTickScale;
56
public SongTransport() {
60
Shell shell = TuxGuitar.instance().getTablatureEditor().getTablature().getShell();
61
this.dialog = new Shell(shell, SWT.DIALOG_TRIM);
62
this.dialog.setLayout(new GridLayout());
67
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
68
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
69
this.dialog.setLocation(x, y);
71
TuxGuitar.instance().updateCache(true);
72
while (!this.dialog.isDisposed()) {
73
if (!this.dialog.getDisplay().readAndDispatch()) {
74
this.dialog.getDisplay().sleep();
77
TuxGuitar.instance().updateCache(true);
82
Composite composite = new Composite(this.dialog,SWT.NONE);
83
composite.setLayout(new GridLayout());
84
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
88
initButtons(composite);
94
private void initLabel(Composite parent){
95
this.label = new Label(parent,SWT.BORDER | SWT.RIGHT);
96
this.label.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
97
this.label.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
98
this.label.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
99
this.label.setFont(new Font(parent.getDisplay(),"Minisystem",36,SWT.NORMAL));
102
private void initScale(Composite parent){
103
this.tickScale = new Scale(parent, SWT.HORIZONTAL);
104
this.tickScale.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
105
this.tickScale.setIncrement(1000);
106
this.tickScale.setSelection(1000);
107
this.tickScale.addMouseListener(new MouseAdapter() {
108
public void mouseDown(MouseEvent e) {
109
setEditingTickScale(true);
111
public void mouseUp(MouseEvent e) {
112
if(tickScale.getSelection() < Duration.QUARTER_TIME){
113
tickScale.setSelection((int)Duration.QUARTER_TIME);
115
long position = tickScale.getSelection();
116
gotoMeasure(getSongManager().getMeasureHeaderAt(position),true);
118
setEditingTickScale(false);
123
private void initButtons(Composite parent){
124
ToolBar toolBar = new ToolBar(this.dialog,SWT.FLAT);
126
this.first = new ToolItem(toolBar,SWT.PUSH);
127
this.first.setImage(SystemImages.TRANSPORT_FIRST_1);
128
this.first.addSelectionListener(new SelectionAdapter() {
129
public void widgetSelected(SelectionEvent e) {
134
this.previous = new ToolItem(toolBar,SWT.PUSH);
135
this.previous.setImage(SystemImages.TRANSPORT_PREVIOUS_1);
136
this.previous.addSelectionListener(new SelectionAdapter() {
137
public void widgetSelected(SelectionEvent e) {
142
this.stop = new ToolItem(toolBar,SWT.PUSH);
143
this.stop.setImage(SystemImages.TRANSPORT_STOP_1);
144
this.stop.addSelectionListener(new SelectionAdapter() {
145
public void widgetSelected(SelectionEvent e) {
150
this.play = new ToolItem(toolBar,SWT.PUSH);
151
this.play.setImage(SystemImages.TRANSPORT_PLAY_1);
152
this.play.addSelectionListener(new SelectionAdapter() {
153
public void widgetSelected(SelectionEvent e) {
158
this.next = new ToolItem(toolBar,SWT.PUSH);
159
this.next.setImage(SystemImages.TRANSPORT_NEXT_1);
160
this.next.addSelectionListener(new SelectionAdapter() {
161
public void widgetSelected(SelectionEvent e) {
166
this.last = new ToolItem(toolBar,SWT.PUSH);
167
this.last.setImage(SystemImages.TRANSPORT_LAST_1);
168
this.last.addSelectionListener(new SelectionAdapter() {
169
public void widgetSelected(SelectionEvent e) {
174
this.setStatus(STATUS_STOPED);
179
public int getStatus() {
183
public void setStatus(int status) {
184
this.status = status;
187
public void redraw(){
189
if(isEditingTickScale()){
190
this.label.setText(Long.toString(this.tickScale.getSelection()));
192
long tickPosition = TuxGuitar.instance().getPlayer().getTickPosition();
193
this.label.setText(Long.toString(tickPosition));
194
this.tickScale.setSelection((int)tickPosition);
199
public void updateItems(){
201
int lastStatus = getStatus();
203
if(TuxGuitar.instance().getPlayer().isRunning()){
204
setStatus(STATUS_RUNNING);
205
}else if(TuxGuitar.instance().getPlayer().isPaused()){
206
setStatus(STATUS_PAUSED);
208
setStatus(STATUS_STOPED);
211
if(lastStatus != getStatus()){
212
if(getStatus() == STATUS_RUNNING){
213
this.first.setImage(SystemImages.TRANSPORT_FIRST_2);
214
this.last.setImage(SystemImages.TRANSPORT_LAST_2);
215
this.previous.setImage(SystemImages.TRANSPORT_PREVIOUS_2);
216
this.next.setImage(SystemImages.TRANSPORT_NEXT_2);
217
this.stop.setImage(SystemImages.TRANSPORT_STOP_2);
218
this.play.setImage(SystemImages.TRANSPORT_PAUSE);
219
}else if(getStatus() == STATUS_PAUSED){
220
this.first.setImage(SystemImages.TRANSPORT_FIRST_2);
221
this.last.setImage(SystemImages.TRANSPORT_LAST_2);
222
this.previous.setImage(SystemImages.TRANSPORT_PREVIOUS_2);
223
this.next.setImage(SystemImages.TRANSPORT_NEXT_2);
224
this.stop.setImage(SystemImages.TRANSPORT_STOP_2);
225
this.play.setImage(SystemImages.TRANSPORT_PLAY_2);
227
}else if(getStatus() == STATUS_STOPED){
228
this.first.setImage(SystemImages.TRANSPORT_FIRST_1);
229
this.last.setImage(SystemImages.TRANSPORT_LAST_1);
230
this.previous.setImage(SystemImages.TRANSPORT_PREVIOUS_1);
231
this.next.setImage(SystemImages.TRANSPORT_NEXT_1);
232
this.stop.setImage(SystemImages.TRANSPORT_STOP_1);
233
this.play.setImage(SystemImages.TRANSPORT_PLAY_1);
236
MeasureHeader first = getSongManager().getFirstMeasureHeader();
237
MeasureHeader last = getSongManager().getLastMeasureHeader();
238
this.tickScale.setMinimum((int)first.getStart());
239
this.tickScale.setMaximum((int)(last.getStart() + last.getLength()) -1);
240
this.tickScale.setPageIncrement((int) ((last.getStart() + last.getLength() - Duration.QUARTER_TIME) / 10));
247
public void loadProperties(){
252
public void dispose() {
254
this.dialog.dispose();
258
public boolean isDisposed() {
259
return (this.dialog == null || this.dialog.isDisposed());
262
public boolean isEditingTickScale() {
263
return editingTickScale;
266
public void setEditingTickScale(boolean editingTickScale) {
267
this.editingTickScale = editingTickScale;
270
private SongManager getSongManager(){
271
return TuxGuitar.instance().getSongManager();
274
public void gotoFirst(TypedEvent e){
275
gotoMeasure(getSongManager().getFirstMeasureHeader(),true);
278
public void gotoLast(TypedEvent e){
279
gotoMeasure(getSongManager().getLastMeasureHeader(),true) ;
282
public void gotoNext(TypedEvent e){
283
MidiPlayer player = TuxGuitar.instance().getPlayer();
284
MeasureHeader header = getSongManager().getMeasureHeaderAt(player.getTickPosition());
286
gotoMeasure(getSongManager().getNextMeasureHeader(header),true);
290
public void gotoPrevious(TypedEvent e){
291
MidiPlayer player = TuxGuitar.instance().getPlayer();
292
MeasureHeader header = getSongManager().getMeasureHeaderAt(player.getTickPosition());
294
gotoMeasure(getSongManager().getPrevMeasureHeader(header),true);
298
public void gotoMeasure(MeasureHeader header){
299
gotoMeasure(header,false);
302
private void gotoMeasure(MeasureHeader header,boolean moveCaret){
303
if(header != null && !getSongManager().isAtPosition(header,TuxGuitar.instance().getPlayer().getTickPosition())){
304
TuxGuitar.instance().getPlayer().setTickPosition(header.getStartWidthRepetitions(),header.getStartWidthRepetitions() - header.getStart());
306
TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().goToTickPosition();
307
TuxGuitar.instance().redraw();
313
public void play(TypedEvent e){
314
TuxGuitar.instance().getAction(PlaySongAction.NAME).process(e);
317
public void stop(TypedEvent e){
318
TuxGuitar.instance().getAction(StopSongAction.NAME).process(e);