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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/mixer/TGMixerTrack.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
package org.herac.tuxguitar.gui.mixer;
 
2
 
 
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;
 
19
 
 
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;
 
30
        
 
31
        protected String tipVolume;
 
32
        protected String tipBalance;
 
33
        
 
34
        protected UndoableTrackChannel undoableVolume;
 
35
        protected UndoableTrackChannel undoableBalance;
 
36
        
 
37
        public TGMixerTrack(TGMixer mixer,TGTrack track){
 
38
                this.mixer = mixer;
 
39
                this.track = track;
 
40
        }
 
41
        
 
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));
 
46
                
 
47
                this.mixerChannel = new TGMixerTrackChannel(this);
 
48
                this.mixerChannel.init(composite);
 
49
                
 
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();
 
55
                                
 
56
                                TGMixerTrack.this.track.getChannel().setSolo(TGMixerTrack.this.soloCheckBox.getSelection());
 
57
                                if(TGMixerTrack.this.track.getChannel().isSolo()){
 
58
                                        TGMixerTrack.this.track.getChannel().setMute(false);
 
59
                                }
 
60
                                TGMixerTrack.this.mixer.fireChanges(TGMixerTrack.this.track.getChannel(),TGMixer.SOLO);
 
61
                                
 
62
                                TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
 
63
                                TuxGuitar.instance().updateCache(true);
 
64
                        }
 
65
                });
 
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();
 
71
                                
 
72
                                TGMixerTrack.this.track.getChannel().setMute(TGMixerTrack.this.muteCheckBox.getSelection());
 
73
                                if(TGMixerTrack.this.track.getChannel().isMute()){
 
74
                                        TGMixerTrack.this.track.getChannel().setSolo(false);
 
75
                                }
 
76
                                TGMixerTrack.this.mixer.fireChanges(TGMixerTrack.this.track.getChannel(),TGMixer.MUTE);
 
77
                                
 
78
                                TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
 
79
                                TuxGuitar.instance().updateCache(true);
 
80
                        }
 
81
                });
 
82
                
 
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());
 
89
                
 
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));
 
96
                
 
97
                Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
 
98
                separator.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,false));
 
99
                
 
100
                Composite volumeValueComposite = new Composite(composite, SWT.NONE);
 
101
                volumeValueComposite.setLayout(new GridLayout(2,false));
 
102
                
 
103
                this.volumeValueTitleLabel = new Label(volumeValueComposite, SWT.LEFT);
 
104
                
 
105
                this.volumeValueLabel = new Label(volumeValueComposite, SWT.CENTER);
 
106
                this.volumeValueLabel.setLayoutData(getVolumeValueLabelData());
 
107
                
 
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);
 
113
                        }
 
114
                });
 
115
                this.balanceScale.addMouseListener(new MouseAdapter() {
 
116
                        public void mouseDown(MouseEvent arg0) {
 
117
                                TGMixerTrack.this.undoableBalance = UndoableTrackChannel.startUndo();
 
118
                        }
 
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;
 
125
                                }
 
126
                        }
 
127
                });
 
128
                
 
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);
 
134
                        }
 
135
                });
 
136
                this.volumeScale.addMouseListener(new MouseAdapter() {
 
137
                        public void mouseDown(MouseEvent arg0) {
 
138
                                TGMixerTrack.this.undoableVolume = UndoableTrackChannel.startUndo();
 
139
                        }
 
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;
 
146
                                }
 
147
                        }
 
148
                });
 
149
                
 
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()));
 
153
        }
 
154
        
 
155
        private GridData getBalanceScaleData(){
 
156
                GridData data = new GridData(SWT.CENTER,SWT.NONE,false,true);
 
157
                data.widthHint = 65;
 
158
                return data;
 
159
        }
 
160
        
 
161
        private GridData getVolumeValueLabelData(){
 
162
                GridData data = new GridData(SWT.CENTER,SWT.NONE,true,false);
 
163
                data.minimumWidth = 40;
 
164
                return data;
 
165
        }
 
166
        
 
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());
 
171
                }
 
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()));
 
175
                }
 
176
                if((type & TGMixer.CHANNEL) != 0 || (type & TGMixer.BALANCE) != 0){
 
177
                        this.balanceScale.setSelection(this.track.getChannel().getBalance());
 
178
                }
 
179
                if((type & TGMixer.CHANNEL) != 0){
 
180
                        this.mixerChannel.updateItems(true);
 
181
                }
 
182
        }
 
183
        
 
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");
 
190
                
 
191
                this.volumeScale.setToolTipText(this.tipVolume + ": " + this.track.getChannel().getBalance());
 
192
                this.balanceScale.setToolTipText(this.tipBalance + ": " + this.track.getChannel().getBalance());
 
193
                
 
194
                this.mixerChannel.updateItems(true);
 
195
        }
 
196
        
 
197
        public void updateItems(){
 
198
                this.mixerChannel.updateItems(false);
 
199
        }
 
200
        
 
201
        public TGTrack getTrack(){
 
202
                return this.track;
 
203
        }
 
204
        
 
205
        public TGMixer getMixer(){
 
206
                return this.mixer;
 
207
        }
 
208
}