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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/system/config/items/SoundOption.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.system.config.items;
 
2
 
 
3
import java.util.List;
 
4
 
 
5
import org.eclipse.swt.SWT;
 
6
import org.eclipse.swt.layout.GridData;
 
7
import org.eclipse.swt.layout.GridLayout;
 
8
import org.eclipse.swt.widgets.Combo;
 
9
import org.eclipse.swt.widgets.Composite;
 
10
import org.eclipse.swt.widgets.ToolBar;
 
11
import org.herac.tuxguitar.gui.TuxGuitar;
 
12
import org.herac.tuxguitar.gui.helper.SyncThread;
 
13
import org.herac.tuxguitar.gui.system.config.TGConfigEditor;
 
14
import org.herac.tuxguitar.gui.system.config.TGConfigKeys;
 
15
import org.herac.tuxguitar.player.base.MidiPort;
 
16
import org.herac.tuxguitar.player.base.MidiSequencer;
 
17
 
 
18
public class SoundOption extends Option{
 
19
        protected boolean initialized;
 
20
        
 
21
        //**MidiSequencer module**//
 
22
        protected String msCurrentKey;
 
23
        protected List msList;
 
24
        protected Combo msCombo;
 
25
        
 
26
        //**MidiPort module**//
 
27
        protected String mpCurrentKey;
 
28
        protected List mpList;
 
29
        protected Combo mpCombo;
 
30
        
 
31
        public SoundOption(TGConfigEditor configEditor,ToolBar toolBar,final Composite parent){
 
32
                super(configEditor,toolBar,parent,TuxGuitar.getProperty("settings.config.sound"));
 
33
                this.initialized = false;
 
34
        }
 
35
        
 
36
        public void createOption(){
 
37
                getToolItem().setText(TuxGuitar.getProperty("settings.config.sound"));
 
38
                getToolItem().setImage(TuxGuitar.instance().getIconManager().getOptionSound());
 
39
                getToolItem().addSelectionListener(this);
 
40
                
 
41
                //---Midi Sequencer---//
 
42
                showLabel(getComposite(),SWT.TOP | SWT.LEFT | SWT.WRAP,SWT.BOLD,0,TuxGuitar.getProperty("midi.sequencer"));
 
43
                
 
44
                Composite msComposite = new Composite(getComposite(),SWT.NONE);
 
45
                msComposite.setLayout(new GridLayout());
 
46
                msComposite.setLayoutData(getTabbedData());
 
47
                
 
48
                this.msCombo = new Combo(msComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
 
49
                this.msCombo.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
50
                
 
51
                //---Midi Port---//
 
52
                showLabel(getComposite(),SWT.TOP | SWT.LEFT | SWT.WRAP,SWT.BOLD,0,TuxGuitar.getProperty("midi.port"));
 
53
                
 
54
                Composite mpComposite = new Composite(getComposite(),SWT.NONE);
 
55
                mpComposite.setLayout(new GridLayout());
 
56
                mpComposite.setLayoutData(getTabbedData());
 
57
                
 
58
                this.mpCombo = new Combo(mpComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
 
59
                this.mpCombo.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
60
                
 
61
                this.loadConfig();
 
62
        }
 
63
        
 
64
        protected void loadConfig(){
 
65
                new Thread(new Runnable() {
 
66
                        public void run() {
 
67
                                SoundOption.this.mpList = TuxGuitar.instance().getPlayer().listPorts();
 
68
                                SoundOption.this.msList = TuxGuitar.instance().getPlayer().listSequencers();
 
69
                                
 
70
                                SoundOption.this.mpCurrentKey = getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT);
 
71
                                SoundOption.this.msCurrentKey = getConfig().getStringConfigValue(TGConfigKeys.MIDI_SEQUENCER);
 
72
                                
 
73
                                final String mpLoaded = TuxGuitar.instance().getPlayer().getMidiPort().getKey();
 
74
                                final String msLoaded = TuxGuitar.instance().getPlayer().getSequencer().getKey();
 
75
                                
 
76
                                new SyncThread(new Runnable() {
 
77
                                        public void run() {
 
78
                                                if(!isDisposed()){
 
79
                                                        //---Midi Sequencer---//
 
80
                                                        String loadedSequencer = msLoaded;
 
81
                                                        for (int i = 0; i < SoundOption.this.msList.size(); i++) {
 
82
                                                                MidiSequencer sequencer = (MidiSequencer)SoundOption.this.msList.get(i);
 
83
                                                                SoundOption.this.msCombo.add(sequencer.getName());
 
84
                                                                if(SoundOption.this.msCurrentKey != null && SoundOption.this.msCurrentKey.equals(sequencer.getKey())){
 
85
                                                                        SoundOption.this.msCombo.select(i);
 
86
                                                                        loadedSequencer = null;
 
87
                                                                }else if(loadedSequencer != null && loadedSequencer.equals(sequencer.getKey())){
 
88
                                                                        SoundOption.this.msCombo.select(i);
 
89
                                                                }
 
90
                                                        }
 
91
                                                        if(SoundOption.this.msCombo.getSelectionIndex() < 0 && SoundOption.this.msCombo.getItemCount() > 0){
 
92
                                                                SoundOption.this.msCombo.select(0);
 
93
                                                        }
 
94
                                                        
 
95
                                                        //---Midi Port---//
 
96
                                                        String loadedPort = mpLoaded;
 
97
                                                        for (int i = 0; i < SoundOption.this.mpList.size(); i++) {
 
98
                                                                MidiPort port = (MidiPort)SoundOption.this.mpList.get(i);
 
99
                                                                SoundOption.this.mpCombo.add(port.getName());
 
100
                                                                if(SoundOption.this.mpCurrentKey != null && SoundOption.this.mpCurrentKey.equals(port.getKey())){
 
101
                                                                        SoundOption.this.mpCombo.select(i);
 
102
                                                                        loadedPort = null;
 
103
                                                                }else if(loadedPort != null && loadedPort.equals(port.getKey())){
 
104
                                                                        SoundOption.this.mpCombo.select(i);
 
105
                                                                }
 
106
                                                        }
 
107
                                                        if(SoundOption.this.mpCombo.getSelectionIndex() < 0 && SoundOption.this.mpCombo.getItemCount() > 0){
 
108
                                                                SoundOption.this.mpCombo.select(0);
 
109
                                                        }
 
110
                                                        
 
111
                                                        SoundOption.this.initialized = true;
 
112
                                                        SoundOption.this.pack();
 
113
                                                }
 
114
                                        }
 
115
                                }).start();
 
116
                        }
 
117
                }).start();
 
118
        }
 
119
        
 
120
        public void updateConfig(){
 
121
                if(this.initialized){
 
122
                        int msIndex = this.msCombo.getSelectionIndex();
 
123
                        if(msIndex >= 0 && msIndex < this.msList.size()){
 
124
                                getConfig().setProperty(TGConfigKeys.MIDI_SEQUENCER, ((MidiSequencer)this.msList.get(msIndex)).getKey());
 
125
                        }
 
126
                        int mpIndex = this.mpCombo.getSelectionIndex();
 
127
                        if(mpIndex >= 0 && mpIndex < this.mpList.size()){
 
128
                                MidiPort midiPort = (MidiPort)this.mpList.get(mpIndex);
 
129
                                getConfig().setProperty(TGConfigKeys.MIDI_PORT, midiPort.getKey());
 
130
                        }
 
131
                }
 
132
        }
 
133
        
 
134
        public void updateDefaults(){
 
135
                if(this.initialized){
 
136
                        getConfig().setProperty(TGConfigKeys.MIDI_PORT,getDefaults().getProperty(TGConfigKeys.MIDI_PORT));
 
137
                        getConfig().setProperty(TGConfigKeys.MIDI_SEQUENCER,getDefaults().getProperty(TGConfigKeys.MIDI_SEQUENCER));
 
138
                }
 
139
        }
 
140
        
 
141
        public void applyConfig(final boolean force){
 
142
                if(force || this.initialized){
 
143
                        String midiSequencer = getConfig().getStringConfigValue(TGConfigKeys.MIDI_SEQUENCER);
 
144
                        if(force || !TuxGuitar.instance().getPlayer().isSequencerOpen(midiSequencer)){
 
145
                                TuxGuitar.instance().getPlayer().openSequencer(midiSequencer);
 
146
                        }
 
147
                        String midiPort = getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT);
 
148
                        if(force || !TuxGuitar.instance().getPlayer().isMidiPortOpen(midiPort)){
 
149
                                TuxGuitar.instance().getPlayer().openPort(midiPort);
 
150
                        }
 
151
                }
 
152
        }
 
153
}
 
 
b'\\ No newline at end of file'