1
package org.herac.tuxguitar.gui.mixer;
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.MouseAdapter;
5
import org.eclipse.swt.events.MouseEvent;
6
import org.eclipse.swt.events.SelectionAdapter;
7
import org.eclipse.swt.events.SelectionEvent;
8
import org.eclipse.swt.layout.GridData;
9
import org.eclipse.swt.layout.GridLayout;
10
import org.eclipse.swt.widgets.Button;
11
import org.eclipse.swt.widgets.Composite;
12
import org.eclipse.swt.widgets.Event;
13
import org.eclipse.swt.widgets.Label;
14
import org.eclipse.swt.widgets.Listener;
15
import org.eclipse.swt.widgets.Scale;
16
import org.herac.tuxguitar.gui.TuxGuitar;
17
import org.herac.tuxguitar.gui.undo.undoables.track.UndoableTrackChannel;
18
import org.herac.tuxguitar.song.models.TGTrack;
20
public class TGMixerTrack {
21
protected TGTrack track;
22
protected TGMixer mixer;
23
protected TGMixerTrackChannel mixerChannel;
24
protected Button soloCheckBox;
25
protected Button muteCheckBox;
26
protected Scale balanceScale;
27
protected Scale volumeScale;
28
private Label volumeValueLabel;
29
private Label volumeValueTitleLabel;
31
protected String tipVolume;
32
protected String tipBalance;
34
protected UndoableTrackChannel undoableVolume;
35
protected UndoableTrackChannel undoableBalance;
37
public TGMixerTrack(TGMixer mixer,TGTrack track){
42
public void init(final Composite parent) {
43
final Composite composite = new Composite(parent, SWT.BORDER);
44
composite.setLayout(new GridLayout(1, true));
45
composite.setLayoutData(new GridData(SWT.CENTER,SWT.FILL,true,true));
47
this.mixerChannel = new TGMixerTrackChannel(this);
48
this.mixerChannel.init(composite);
50
this.soloCheckBox = new Button(composite,SWT.CHECK);
51
this.soloCheckBox.setSelection(TGMixerTrack.this.track.getChannel().isSolo());
52
this.soloCheckBox.addSelectionListener(new SelectionAdapter() {
53
public void widgetSelected(SelectionEvent e) {
54
UndoableTrackChannel undoable = UndoableTrackChannel.startUndo();
56
TGMixerTrack.this.track.getChannel().setSolo(TGMixerTrack.this.soloCheckBox.getSelection());
57
if(TGMixerTrack.this.track.getChannel().isSolo()){
58
TGMixerTrack.this.track.getChannel().setMute(false);
60
TGMixerTrack.this.mixer.fireChanges(TGMixerTrack.this.track.getChannel(),TGMixer.SOLO);
62
TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
63
TuxGuitar.instance().updateCache(true);
66
this.muteCheckBox = new Button(composite,SWT.CHECK);
67
this.muteCheckBox.setSelection(TGMixerTrack.this.track.getChannel().isMute());
68
this.muteCheckBox.addSelectionListener(new SelectionAdapter() {
69
public void widgetSelected(SelectionEvent e) {
70
UndoableTrackChannel undoable = UndoableTrackChannel.startUndo();
72
TGMixerTrack.this.track.getChannel().setMute(TGMixerTrack.this.muteCheckBox.getSelection());
73
if(TGMixerTrack.this.track.getChannel().isMute()){
74
TGMixerTrack.this.track.getChannel().setSolo(false);
76
TGMixerTrack.this.mixer.fireChanges(TGMixerTrack.this.track.getChannel(),TGMixer.MUTE);
78
TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
79
TuxGuitar.instance().updateCache(true);
83
this.balanceScale = new Scale(composite, SWT.HORIZONTAL);
84
this.balanceScale.setMaximum(127);
85
this.balanceScale.setMinimum(0);
86
this.balanceScale.setIncrement(1);
87
this.balanceScale.setPageIncrement(64);
88
this.balanceScale.setLayoutData(getBalanceScaleData());
90
this.volumeScale = new Scale(composite, SWT.VERTICAL);
91
this.volumeScale.setMaximum(127);
92
this.volumeScale.setMinimum(0);
93
this.volumeScale.setIncrement(1);
94
this.volumeScale.setPageIncrement(16);
95
this.volumeScale.setLayoutData(new GridData(SWT.CENTER,SWT.FILL,true,true));
97
Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
98
separator.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,false));
100
Composite volumeValueComposite = new Composite(composite, SWT.NONE);
101
volumeValueComposite.setLayout(new GridLayout(2,false));
103
this.volumeValueTitleLabel = new Label(volumeValueComposite, SWT.LEFT);
105
this.volumeValueLabel = new Label(volumeValueComposite, SWT.CENTER);
106
this.volumeValueLabel.setLayoutData(getVolumeValueLabelData());
108
this.balanceScale.addListener(SWT.Selection, new Listener() {
109
public void handleEvent(Event event) {
110
TGMixerTrack.this.track.getChannel().setBalance((short)TGMixerTrack.this.balanceScale.getSelection());
111
TGMixerTrack.this.balanceScale.setToolTipText(TGMixerTrack.this.tipBalance + ": " + TGMixerTrack.this.track.getChannel().getBalance());
112
TGMixerTrack.this.mixer.fireChanges(TGMixerTrack.this.track.getChannel(),TGMixer.BALANCE);
115
this.balanceScale.addMouseListener(new MouseAdapter() {
116
public void mouseDown(MouseEvent arg0) {
117
TGMixerTrack.this.undoableBalance = UndoableTrackChannel.startUndo();
119
public void mouseUp(MouseEvent arg0) {
120
if(TGMixerTrack.this.undoableBalance != null){
121
TuxGuitar.instance().getUndoableManager().addEdit(TGMixerTrack.this.undoableBalance.endUndo());
122
TuxGuitar.instance().getFileHistory().setUnsavedFile();
123
TuxGuitar.instance().updateCache(true);
124
TGMixerTrack.this.undoableBalance = null;
129
this.volumeScale.addListener(SWT.Selection, new Listener() {
130
public void handleEvent(Event event) {
131
TGMixerTrack.this.track.getChannel().setVolume((short)(TGMixerTrack.this.volumeScale.getMaximum() - TGMixerTrack.this.volumeScale.getSelection()));
132
TGMixerTrack.this.volumeScale.setToolTipText(TGMixerTrack.this.tipVolume + ": " + TGMixerTrack.this.track.getChannel().getVolume());
133
TGMixerTrack.this.mixer.fireChanges(TGMixerTrack.this.track.getChannel(),TGMixer.VOLUME);
136
this.volumeScale.addMouseListener(new MouseAdapter() {
137
public void mouseDown(MouseEvent arg0) {
138
TGMixerTrack.this.undoableVolume = UndoableTrackChannel.startUndo();
140
public void mouseUp(MouseEvent arg0) {
141
if(TGMixerTrack.this.undoableVolume != null){
142
TuxGuitar.instance().getUndoableManager().addEdit(TGMixerTrack.this.undoableVolume.endUndo());
143
TuxGuitar.instance().getFileHistory().setUnsavedFile();
144
TuxGuitar.instance().updateCache(true);
145
TGMixerTrack.this.undoableVolume = null;
150
this.balanceScale.setSelection(this.track.getChannel().getBalance());
151
this.volumeScale.setSelection(this.volumeScale.getMaximum() - this.track.getChannel().getVolume());
152
this.volumeValueLabel.setText(Integer.toString(this.volumeScale.getMaximum() - this.volumeScale.getSelection()));
155
private GridData getBalanceScaleData(){
156
GridData data = new GridData(SWT.CENTER,SWT.NONE,false,true);
161
private GridData getVolumeValueLabelData(){
162
GridData data = new GridData(SWT.CENTER,SWT.NONE,true,false);
163
data.minimumWidth = 40;
167
public void fireChanges(int type){
168
if((type & TGMixer.SOLO) != 0 || (type & TGMixer.MUTE) != 0){
169
this.soloCheckBox.setSelection(this.track.getChannel().isSolo());
170
this.muteCheckBox.setSelection(this.track.getChannel().isMute());
172
if((type & TGMixer.CHANNEL) != 0 || (type & TGMixer.VOLUME) != 0){
173
this.volumeScale.setSelection(this.volumeScale.getMaximum() - this.track.getChannel().getVolume());
174
this.volumeValueLabel.setText(Integer.toString(this.volumeScale.getMaximum() - this.volumeScale.getSelection()));
176
if((type & TGMixer.CHANNEL) != 0 || (type & TGMixer.BALANCE) != 0){
177
this.balanceScale.setSelection(this.track.getChannel().getBalance());
179
if((type & TGMixer.CHANNEL) != 0){
180
this.mixerChannel.updateItems(true);
184
public void loadProperties(){
185
this.soloCheckBox.setText(TuxGuitar.getProperty("mixer.track.solo"));
186
this.muteCheckBox.setText(TuxGuitar.getProperty("mixer.track.mute"));
187
this.volumeValueTitleLabel.setText(TuxGuitar.getProperty("mixer.channel.volume") + ":");
188
this.tipVolume = TuxGuitar.getProperty("mixer.channel.volume");
189
this.tipBalance = TuxGuitar.getProperty("mixer.channel.balance");
191
this.volumeScale.setToolTipText(this.tipVolume + ": " + this.track.getChannel().getBalance());
192
this.balanceScale.setToolTipText(this.tipBalance + ": " + this.track.getChannel().getBalance());
194
this.mixerChannel.updateItems(true);
197
public void updateItems(){
198
this.mixerChannel.updateItems(false);
201
public TGTrack getTrack(){
205
public TGMixer getMixer(){