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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.gui.mixer;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.Iterator;
 
5
import java.util.List;
 
6
 
 
7
import org.eclipse.swt.SWT;
 
8
import org.eclipse.swt.events.SelectionAdapter;
 
9
import org.eclipse.swt.events.SelectionEvent;
 
10
import org.eclipse.swt.layout.GridData;
 
11
import org.eclipse.swt.widgets.Combo;
 
12
import org.eclipse.swt.widgets.Composite;
 
13
import org.herac.tuxguitar.gui.TuxGuitar;
 
14
import org.herac.tuxguitar.gui.undo.undoables.track.UndoableTrackChannel;
 
15
import org.herac.tuxguitar.song.models.TGChannel;
 
16
import org.herac.tuxguitar.song.models.TGTrack;
 
17
 
 
18
public class TGMixerTrackChannel {
 
19
        
 
20
        private TGMixerTrack mixer;
 
21
        protected Combo normalChannel;
 
22
        protected Combo effectChannel;
 
23
        protected ChannelList normalChannels;
 
24
        protected ChannelList effectChannels;
 
25
        
 
26
        public TGMixerTrackChannel(TGMixerTrack mixer){
 
27
                this.mixer = mixer;
 
28
        }
 
29
        
 
30
        protected TGTrack getTrack(){
 
31
                return this.mixer.getTrack();
 
32
        }
 
33
        
 
34
        protected TGChannel getChannel(){
 
35
                return this.mixer.getTrack().getChannel();
 
36
        }
 
37
        
 
38
        public void init(Composite parent){
 
39
                this.normalChannels = new ChannelList();
 
40
                this.normalChannel = new Combo(parent,SWT.DROP_DOWN | SWT.READ_ONLY);
 
41
                this.normalChannel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 
42
                
 
43
                this.effectChannels = new ChannelList();
 
44
                this.effectChannel = new Combo(parent,SWT.DROP_DOWN | SWT.READ_ONLY);
 
45
                this.effectChannel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 
46
                
 
47
                this.normalChannel.addSelectionListener(new SelectionAdapter() {
 
48
                        public void widgetSelected(SelectionEvent e) {
 
49
                                UndoableTrackChannel undoable = UndoableTrackChannel.startUndo();
 
50
                                
 
51
                                TGChannel channel = getTrack().getChannel();
 
52
                                boolean[] usedChannels = TuxGuitar.instance().getSongManager().getUsedChannels();
 
53
                                int idx = TGMixerTrackChannel.this.normalChannels.getChannel(TGMixerTrackChannel.this.normalChannel.getSelectionIndex());
 
54
                                if(!usedChannels[idx]){
 
55
                                        channel.setChannel((short)idx);
 
56
                                        channel.setEffectChannel(channel.getChannel());
 
57
                                }else{
 
58
                                        boolean solo = channel.isSolo();
 
59
                                        boolean mute = channel.isMute();
 
60
                                        TuxGuitar.instance().getSongManager().getUsedChannel(idx).copy(channel);
 
61
                                        channel.setSolo( solo );
 
62
                                        channel.setMute( mute );
 
63
                                }
 
64
                                fireChannelChange(channel);
 
65
                                
 
66
                                TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
 
67
                                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
68
                                TuxGuitar.instance().updateCache(true);
 
69
                        }
 
70
                });
 
71
                
 
72
                this.effectChannel.addSelectionListener(new SelectionAdapter() {
 
73
                        public void widgetSelected(SelectionEvent e) {
 
74
                                UndoableTrackChannel undoable = UndoableTrackChannel.startUndo();
 
75
                                
 
76
                                TGChannel channel = getTrack().getChannel();
 
77
                                int idx = TGMixerTrackChannel.this.effectChannels.getChannel(TGMixerTrackChannel.this.effectChannel.getSelectionIndex());
 
78
                                channel.setEffectChannel((short)idx);
 
79
                                fireChannelChange(channel);
 
80
                                
 
81
                                TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
 
82
                                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
83
                                TuxGuitar.instance().updateCache(true);
 
84
                        }
 
85
                });
 
86
                
 
87
                this.updateItems(true);
 
88
        }
 
89
        
 
90
        public void updateItems(boolean reload){
 
91
                if(reload){
 
92
                        this.updateNormalChannel();
 
93
                        this.updateEffectChannel();
 
94
                }
 
95
                this.normalChannel.setEnabled(!TuxGuitar.instance().getPlayer().isRunning());
 
96
                this.effectChannel.setEnabled(!TuxGuitar.instance().getPlayer().isRunning());
 
97
        }
 
98
        
 
99
        private void updateNormalChannel(){
 
100
                this.normalChannel.removeAll();
 
101
                this.normalChannels.clear();
 
102
                
 
103
                boolean[] usedChannels = TuxGuitar.instance().getSongManager().getUsedChannels();
 
104
                boolean[] usedEffectChannels = TuxGuitar.instance().getSongManager().getUsedEffectChannels();
 
105
                if(getChannel().isPercussionChannel()){
 
106
                        this.normalChannel.add(Integer.toString(TGChannel.DEFAULT_PERCUSSION_CHANNEL));
 
107
                        this.normalChannel.select(0);
 
108
                        this.normalChannels.addChannel(0,0);
 
109
                }else{
 
110
                        int itemIndex = 0;
 
111
                        for(int i = 0;i < usedChannels.length;i++){
 
112
                                if(!TGChannel.isPercussionChannel(i)){
 
113
                                        if(!usedEffectChannels[i] || (usedEffectChannels[i] && usedChannels[i]) || (getChannel().getChannel() == i && getChannel().getEffectChannel() == getChannel().getChannel())){
 
114
                                                String itemName = new String();
 
115
                                                if(usedChannels[i] && (getChannel().getChannel() != i || TuxGuitar.instance().getSongManager().countTracksForChannel(i) > 1)){
 
116
                                                        itemName = i + " " + TuxGuitar.getProperty("mixer.channel.link");
 
117
                                                }else{
 
118
                                                        itemName =  i + " " + TuxGuitar.getProperty("mixer.channel.free");
 
119
                                                }
 
120
                                                this.normalChannel.add(itemName);
 
121
                                                
 
122
                                                if(i == getChannel().getChannel()){
 
123
                                                        this.normalChannel.select(itemIndex);
 
124
                                                }
 
125
                                                this.normalChannels.addChannel(itemIndex,i);
 
126
                                                itemIndex ++;
 
127
                                        }
 
128
                                }
 
129
                        }
 
130
                }
 
131
        }
 
132
        
 
133
        private void updateEffectChannel(){
 
134
                this.effectChannel.removeAll();
 
135
                this.effectChannels.clear();
 
136
                
 
137
                boolean[] usedChannels = TuxGuitar.instance().getSongManager().getUsedChannels();
 
138
                boolean[] usedEffectChannels = TuxGuitar.instance().getSongManager().getUsedEffectChannels();
 
139
                if(getChannel().isPercussionChannel()){
 
140
                        this.effectChannel.add(Integer.toString(TGChannel.DEFAULT_PERCUSSION_CHANNEL));
 
141
                        this.effectChannel.select(0);
 
142
                        this.effectChannels.addChannel(0,0);
 
143
                }else{
 
144
                        int itemIndex = 0;
 
145
                        for(int i = 0;i < usedEffectChannels.length;i++){
 
146
                                if(!TGChannel.isPercussionChannel(i)){
 
147
                                        if((!usedEffectChannels[i] || getChannel().getEffectChannel() == i) && (!usedChannels[i] || i == getChannel().getChannel())){
 
148
                                                this.effectChannel.add(Integer.toString(i));
 
149
                                                
 
150
                                                if(i == getChannel().getEffectChannel()){
 
151
                                                        this.effectChannel.select(itemIndex);
 
152
                                                }
 
153
                                                this.effectChannels.addChannel(itemIndex,i);
 
154
                                                itemIndex ++;
 
155
                                        }
 
156
                                }
 
157
                        }
 
158
                }
 
159
        }
 
160
        
 
161
        public void fireChannelChange(TGChannel channel){
 
162
                this.mixer.getMixer().fireChanges(channel,TGMixer.CHANNEL);
 
163
        }
 
164
        
 
165
        private class ChannelList{
 
166
                private List channelIndexs;
 
167
                
 
168
                public ChannelList(){
 
169
                        this.channelIndexs = new ArrayList();
 
170
                }
 
171
                
 
172
                public void addChannel(int index,int channel){
 
173
                        this.channelIndexs.add(new ChannelIndex(index,channel));
 
174
                }
 
175
                
 
176
                public int getChannel(int index){
 
177
                        Iterator it = this.channelIndexs.iterator();
 
178
                        while (it.hasNext()) {
 
179
                                ChannelIndex channelIndex = (ChannelIndex) it.next();
 
180
                                if(index == channelIndex.getIndex()){
 
181
                                        return channelIndex.getChannel();
 
182
                                }
 
183
                        }
 
184
                        return -1;
 
185
                }
 
186
                
 
187
                public void clear(){
 
188
                        this.channelIndexs.clear();
 
189
                }
 
190
        }
 
191
        
 
192
        private class ChannelIndex{
 
193
                private int index;
 
194
                private int channel;
 
195
                
 
196
                public ChannelIndex(int index,int channel){
 
197
                        this.index = index;
 
198
                        this.channel = channel;
 
199
                }
 
200
                
 
201
                public int getChannel() {
 
202
                        return this.channel;
 
203
                }
 
204
                
 
205
                public int getIndex() {
 
206
                        return this.index;
 
207
                }
 
208
        }
 
209
}