~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/mixer/TGMixer.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 20-mar-2006
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.mixer;
 
8
 
 
9
import java.util.ArrayList;
 
10
import java.util.Iterator;
 
11
import java.util.List;
 
12
 
 
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;
 
30
 
 
31
/**
 
32
 * @author julian
 
33
 * 
 
34
 * TODO To change the template for this generated type comment go to Window -
 
35
 * Preferences - Java - Code Style - Code Templates
 
36
 */
 
37
public class TGMixer implements IconLoader,LanguageLoader{
 
38
        
 
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);
 
45
        
 
46
        protected Shell dialog;
 
47
        private List tracks;
 
48
        private Scale volumeScale;
 
49
        private Label volumeValueLabel;
 
50
        private Label volumeValueTitleLabel;
 
51
        private String volumeTip;
 
52
        private int volumeValue;
 
53
        
 
54
        public TGMixer() {
 
55
                this.tracks = new ArrayList();
 
56
                TuxGuitar.instance().getIconManager().addLoader(this);
 
57
                TuxGuitar.instance().getLanguageManager().addLoader(this);
 
58
        }
 
59
        
 
60
        public void show() {
 
61
                this.dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM);
 
62
                this.loadData();
 
63
                
 
64
                TuxGuitar.instance().updateCache(true);
 
65
                
 
66
                DialogUtils.openDialog(this.dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_WAIT);
 
67
                
 
68
                TuxGuitar.instance().updateCache(true);
 
69
        }
 
70
        
 
71
        protected void loadData(){
 
72
                this.tracks.clear();
 
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);
 
79
                }
 
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));
 
83
                
 
84
                this.volumeValue = -1;
 
85
                
 
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));
 
92
                
 
93
                Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
 
94
                separator.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,false));
 
95
                
 
96
                Composite volumeValueComposite = new Composite(composite, SWT.NONE);
 
97
                volumeValueComposite.setLayout(new GridLayout(2,false));
 
98
                
 
99
                this.volumeValueTitleLabel = new Label(volumeValueComposite, SWT.NONE);
 
100
                
 
101
                this.volumeValueLabel = new Label(volumeValueComposite, SWT.CENTER);
 
102
                this.volumeValueLabel.setLayoutData(getVolumeValueLabelData());
 
103
                
 
104
                this.volumeScale.addListener(SWT.Selection, new Listener() {
 
105
                        public void handleEvent(Event event) {
 
106
                                changeVolume();
 
107
                        }
 
108
                });
 
109
                
 
110
                this.loadVolume();
 
111
                this.loadIcons();
 
112
                this.loadProperties();
 
113
                
 
114
                this.dialog.setLayout(getLayout(this.dialog.getChildren().length));
 
115
                this.dialog.pack();
 
116
        }
 
117
        
 
118
        private GridLayout getLayout(int columns){
 
119
                GridLayout layout = new GridLayout(columns, false);
 
120
                layout.verticalSpacing = 1;
 
121
                layout.horizontalSpacing = 1;
 
122
                return layout;
 
123
        }
 
124
        
 
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;
 
132
                }
 
133
        }
 
134
        
 
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;
 
141
                }
 
142
        }
 
143
        
 
144
        private GridData getVolumeValueLabelData(){
 
145
                GridData data = new GridData(SWT.CENTER,SWT.NONE,true,false);
 
146
                data.minimumWidth = 40;
 
147
                return data;
 
148
        }
 
149
        
 
150
        protected void clear(){
 
151
                Control[] controls = this.dialog.getChildren();
 
152
                for(int i = 0;i < controls.length;i++){
 
153
                        controls[i].dispose();
 
154
                }
 
155
        }
 
156
        
 
157
        public boolean isDisposed() {
 
158
                return (this.dialog == null || this.dialog.isDisposed());
 
159
        }
 
160
        
 
161
        public synchronized void fireChanges(TGChannel channel,int type){
 
162
                Iterator it = this.tracks.iterator();
 
163
                while(it.hasNext()){
 
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);
 
171
                        }
 
172
                        mixer.fireChanges(type);
 
173
                }
 
174
                if (TuxGuitar.instance().getPlayer().isRunning()) {
 
175
                        TuxGuitar.instance().getPlayer().updateControllers();
 
176
                }
 
177
        }
 
178
        
 
179
        public synchronized void loadProperties(){
 
180
                if(!isDisposed()){
 
181
                        Iterator it = this.tracks.iterator();
 
182
                        while(it.hasNext()){
 
183
                                TGMixerTrack mixer = (TGMixerTrack)it.next();
 
184
                                mixer.loadProperties();
 
185
                        }
 
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"));
 
190
                        this.dialog.pack();
 
191
                        this.dialog.layout(true,true);
 
192
                        this.dialog.redraw();
 
193
                }
 
194
        }
 
195
        
 
196
        public synchronized void loadIcons(){
 
197
                if(!isDisposed()){
 
198
                        this.dialog.setImage(TuxGuitar.instance().getIconManager().getAppIcon());
 
199
                }
 
200
        }
 
201
        
 
202
        public synchronized void updateItems(){
 
203
                if(!isDisposed()){
 
204
                        Iterator it = this.tracks.iterator();
 
205
                        while(it.hasNext()){
 
206
                                TGMixerTrack mixer = (TGMixerTrack)it.next();
 
207
                                mixer.updateItems();
 
208
                        }
 
209
                }
 
210
        }
 
211
        
 
212
        public synchronized void updateValues(){
 
213
                if(!isDisposed()){
 
214
                        this.loadVolume();
 
215
                        
 
216
                        Iterator it = this.tracks.iterator();
 
217
                        while(it.hasNext()){
 
218
                                TGMixerTrack mixer = (TGMixerTrack)it.next();
 
219
                                mixer.fireChanges(CHANGE_ALL);
 
220
                        }
 
221
                }
 
222
        }
 
223
        
 
224
        public synchronized void update(){
 
225
                if(!isDisposed()){
 
226
                        new SyncThread(new Runnable() {
 
227
                                public void run() {
 
228
                                        if(!isDisposed()){
 
229
                                                TGMixer.this.clear();
 
230
                                                TGMixer.this.loadData();
 
231
                                                TGMixer.this.dialog.layout(true,true);
 
232
                                                TGMixer.this.dialog.redraw();
 
233
                                        }
 
234
                                }
 
235
                        }).start();
 
236
                }
 
237
        }
 
238
        
 
239
        public synchronized void dispose() {
 
240
                if(!isDisposed()){
 
241
                        this.dialog.dispose();
 
242
                }
 
243
        }
 
244
}