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.mixer;
9
import java.util.ArrayList;
10
import java.util.Iterator;
11
import java.util.List;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.Listener;
21
import org.eclipse.swt.widgets.Scale;
22
import org.eclipse.swt.widgets.Shell;
23
import org.herac.tuxguitar.gui.TuxGuitar;
24
import org.herac.tuxguitar.gui.helper.SyncThread;
25
import org.herac.tuxguitar.gui.system.icons.IconLoader;
26
import org.herac.tuxguitar.gui.system.language.LanguageLoader;
27
import org.herac.tuxguitar.gui.util.DialogUtils;
28
import org.herac.tuxguitar.song.models.TGChannel;
29
import org.herac.tuxguitar.song.models.TGTrack;
34
* TODO To change the template for this generated type comment go to Window -
35
* Preferences - Java - Code Style - Code Templates
37
public class TGMixer implements IconLoader,LanguageLoader{
39
public static final int MUTE = 0x01;
40
public static final int SOLO = 0x02;
41
public static final int VOLUME = 0x04;
42
public static final int BALANCE = 0x08;
43
public static final int CHANNEL = 0x10;
44
public static final int CHANGE_ALL = (MUTE | SOLO | VOLUME | BALANCE | CHANNEL);
46
protected Shell dialog;
48
private Scale volumeScale;
49
private Label volumeValueLabel;
50
private Label volumeValueTitleLabel;
51
private String volumeTip;
52
private int volumeValue;
55
this.tracks = new ArrayList();
56
TuxGuitar.instance().getIconManager().addLoader(this);
57
TuxGuitar.instance().getLanguageManager().addLoader(this);
61
this.dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM);
64
TuxGuitar.instance().updateCache(true);
66
DialogUtils.openDialog(this.dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_WAIT);
68
TuxGuitar.instance().updateCache(true);
71
protected void loadData(){
73
Iterator it = TuxGuitar.instance().getSongManager().getSong().getTracks();
74
while (it.hasNext()) {
75
TGTrack track = (TGTrack) it.next();
76
TGMixerTrack trackMixer = new TGMixerTrack(this,track);
77
trackMixer.init(this.dialog);
78
this.tracks.add(trackMixer);
80
Composite composite = new Composite(this.dialog, SWT.BORDER);
81
composite.setLayout(new GridLayout());
82
composite.setLayoutData(new GridData(SWT.CENTER,SWT.FILL,true,true));
84
this.volumeValue = -1;
86
this.volumeScale = new Scale(composite, SWT.VERTICAL);
87
this.volumeScale.setMaximum(10);
88
this.volumeScale.setMinimum(0);
89
this.volumeScale.setIncrement(1);
90
this.volumeScale.setPageIncrement(1);
91
this.volumeScale.setLayoutData(new GridData(SWT.CENTER,SWT.FILL,true,true));
93
Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
94
separator.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,false));
96
Composite volumeValueComposite = new Composite(composite, SWT.NONE);
97
volumeValueComposite.setLayout(new GridLayout(2,false));
99
this.volumeValueTitleLabel = new Label(volumeValueComposite, SWT.NONE);
101
this.volumeValueLabel = new Label(volumeValueComposite, SWT.CENTER);
102
this.volumeValueLabel.setLayoutData(getVolumeValueLabelData());
104
this.volumeScale.addListener(SWT.Selection, new Listener() {
105
public void handleEvent(Event event) {
112
this.loadProperties();
114
this.dialog.setLayout(getLayout(this.dialog.getChildren().length));
118
private GridLayout getLayout(int columns){
119
GridLayout layout = new GridLayout(columns, false);
120
layout.verticalSpacing = 1;
121
layout.horizontalSpacing = 1;
125
protected void changeVolume(){
126
int volume = (short)(TGMixer.this.volumeScale.getMaximum() - TGMixer.this.volumeScale.getSelection());
127
if(volume != TuxGuitar.instance().getPlayer().getVolume()){
128
TuxGuitar.instance().getPlayer().setVolume(volume);
129
this.volumeScale.setToolTipText(TGMixer.this.volumeTip + ": " + TuxGuitar.instance().getPlayer().getVolume());
130
this.volumeValueLabel.setText(Integer.toString(TGMixer.this.volumeScale.getMaximum() - TGMixer.this.volumeScale.getSelection()));
131
this.volumeValue = volume;
135
protected void loadVolume(){
136
int volume = TuxGuitar.instance().getPlayer().getVolume();
137
if(this.volumeValue != volume){
138
this.volumeScale.setSelection(this.volumeScale.getMaximum() - TuxGuitar.instance().getPlayer().getVolume());
139
this.volumeValueLabel.setText(Integer.toString(this.volumeScale.getMaximum() - this.volumeScale.getSelection()));
140
this.volumeValue = volume;
144
private GridData getVolumeValueLabelData(){
145
GridData data = new GridData(SWT.CENTER,SWT.NONE,true,false);
146
data.minimumWidth = 40;
150
protected void clear(){
151
Control[] controls = this.dialog.getChildren();
152
for(int i = 0;i < controls.length;i++){
153
controls[i].dispose();
157
public boolean isDisposed() {
158
return (this.dialog == null || this.dialog.isDisposed());
161
public synchronized void fireChanges(TGChannel channel,int type){
162
Iterator it = this.tracks.iterator();
164
TGMixerTrack mixer = (TGMixerTrack)it.next();
165
if(mixer.getTrack().getChannel().getChannel() == channel.getChannel()){
166
boolean solo = mixer.getTrack().getChannel().isSolo();
167
boolean mute = mixer.getTrack().getChannel().isMute();
168
channel.copy(mixer.getTrack().getChannel());
169
mixer.getTrack().getChannel().setSolo(solo);
170
mixer.getTrack().getChannel().setMute(mute);
172
mixer.fireChanges(type);
174
if (TuxGuitar.instance().getPlayer().isRunning()) {
175
TuxGuitar.instance().getPlayer().updateControllers();
179
public synchronized void loadProperties(){
181
Iterator it = this.tracks.iterator();
183
TGMixerTrack mixer = (TGMixerTrack)it.next();
184
mixer.loadProperties();
186
this.volumeValueTitleLabel.setText(TuxGuitar.getProperty("mixer.volume") + ":");
187
this.volumeTip = TuxGuitar.getProperty("mixer.volume");
188
this.volumeScale.setToolTipText(this.volumeTip + ": " + TuxGuitar.instance().getPlayer().getVolume());
189
this.dialog.setText(TuxGuitar.getProperty("mixer"));
191
this.dialog.layout(true,true);
192
this.dialog.redraw();
196
public synchronized void loadIcons(){
198
this.dialog.setImage(TuxGuitar.instance().getIconManager().getAppIcon());
202
public synchronized void updateItems(){
204
Iterator it = this.tracks.iterator();
206
TGMixerTrack mixer = (TGMixerTrack)it.next();
212
public synchronized void updateValues(){
216
Iterator it = this.tracks.iterator();
218
TGMixerTrack mixer = (TGMixerTrack)it.next();
219
mixer.fireChanges(CHANGE_ALL);
224
public synchronized void update(){
226
new SyncThread(new Runnable() {
229
TGMixer.this.clear();
230
TGMixer.this.loadData();
231
TGMixer.this.dialog.layout(true,true);
232
TGMixer.this.dialog.redraw();
239
public synchronized void dispose() {
241
this.dialog.dispose();