1
package org.herac.tuxguitar.gui.mixer;
3
import java.util.ArrayList;
4
import java.util.Iterator;
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;
18
public class TGMixerTrackChannel {
20
private TGMixerTrack mixer;
21
protected Combo normalChannel;
22
protected Combo effectChannel;
23
protected ChannelList normalChannels;
24
protected ChannelList effectChannels;
26
public TGMixerTrackChannel(TGMixerTrack mixer){
30
protected TGTrack getTrack(){
31
return this.mixer.getTrack();
34
protected TGChannel getChannel(){
35
return this.mixer.getTrack().getChannel();
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));
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));
47
this.normalChannel.addSelectionListener(new SelectionAdapter() {
48
public void widgetSelected(SelectionEvent e) {
49
UndoableTrackChannel undoable = UndoableTrackChannel.startUndo();
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());
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 );
64
fireChannelChange(channel);
66
TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
67
TuxGuitar.instance().getFileHistory().setUnsavedFile();
68
TuxGuitar.instance().updateCache(true);
72
this.effectChannel.addSelectionListener(new SelectionAdapter() {
73
public void widgetSelected(SelectionEvent e) {
74
UndoableTrackChannel undoable = UndoableTrackChannel.startUndo();
76
TGChannel channel = getTrack().getChannel();
77
int idx = TGMixerTrackChannel.this.effectChannels.getChannel(TGMixerTrackChannel.this.effectChannel.getSelectionIndex());
78
channel.setEffectChannel((short)idx);
79
fireChannelChange(channel);
81
TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
82
TuxGuitar.instance().getFileHistory().setUnsavedFile();
83
TuxGuitar.instance().updateCache(true);
87
this.updateItems(true);
90
public void updateItems(boolean reload){
92
this.updateNormalChannel();
93
this.updateEffectChannel();
95
this.normalChannel.setEnabled(!TuxGuitar.instance().getPlayer().isRunning());
96
this.effectChannel.setEnabled(!TuxGuitar.instance().getPlayer().isRunning());
99
private void updateNormalChannel(){
100
this.normalChannel.removeAll();
101
this.normalChannels.clear();
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);
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");
118
itemName = i + " " + TuxGuitar.getProperty("mixer.channel.free");
120
this.normalChannel.add(itemName);
122
if(i == getChannel().getChannel()){
123
this.normalChannel.select(itemIndex);
125
this.normalChannels.addChannel(itemIndex,i);
133
private void updateEffectChannel(){
134
this.effectChannel.removeAll();
135
this.effectChannels.clear();
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);
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));
150
if(i == getChannel().getEffectChannel()){
151
this.effectChannel.select(itemIndex);
153
this.effectChannels.addChannel(itemIndex,i);
161
public void fireChannelChange(TGChannel channel){
162
this.mixer.getMixer().fireChanges(channel,TGMixer.CHANNEL);
165
private class ChannelList{
166
private List channelIndexs;
168
public ChannelList(){
169
this.channelIndexs = new ArrayList();
172
public void addChannel(int index,int channel){
173
this.channelIndexs.add(new ChannelIndex(index,channel));
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();
188
this.channelIndexs.clear();
192
private class ChannelIndex{
196
public ChannelIndex(int index,int channel){
198
this.channel = channel;
201
public int getChannel() {
205
public int getIndex() {