1
package org.herac.tuxguitar.gui.system.config.items;
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;
18
public class SoundOption extends Option{
19
protected boolean initialized;
21
//**MidiSequencer module**//
22
protected String msCurrentKey;
23
protected List msList;
24
protected Combo msCombo;
26
//**MidiPort module**//
27
protected String mpCurrentKey;
28
protected List mpList;
29
protected Combo mpCombo;
31
public SoundOption(TGConfigEditor configEditor,ToolBar toolBar,final Composite parent){
32
super(configEditor,toolBar,parent,TuxGuitar.getProperty("settings.config.sound"));
33
this.initialized = false;
36
public void createOption(){
37
getToolItem().setText(TuxGuitar.getProperty("settings.config.sound"));
38
getToolItem().setImage(TuxGuitar.instance().getIconManager().getOptionSound());
39
getToolItem().addSelectionListener(this);
41
//---Midi Sequencer---//
42
showLabel(getComposite(),SWT.TOP | SWT.LEFT | SWT.WRAP,SWT.BOLD,0,TuxGuitar.getProperty("midi.sequencer"));
44
Composite msComposite = new Composite(getComposite(),SWT.NONE);
45
msComposite.setLayout(new GridLayout());
46
msComposite.setLayoutData(getTabbedData());
48
this.msCombo = new Combo(msComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
49
this.msCombo.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
52
showLabel(getComposite(),SWT.TOP | SWT.LEFT | SWT.WRAP,SWT.BOLD,0,TuxGuitar.getProperty("midi.port"));
54
Composite mpComposite = new Composite(getComposite(),SWT.NONE);
55
mpComposite.setLayout(new GridLayout());
56
mpComposite.setLayoutData(getTabbedData());
58
this.mpCombo = new Combo(mpComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
59
this.mpCombo.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
64
protected void loadConfig(){
65
new Thread(new Runnable() {
67
SoundOption.this.mpList = TuxGuitar.instance().getPlayer().listPorts();
68
SoundOption.this.msList = TuxGuitar.instance().getPlayer().listSequencers();
70
SoundOption.this.mpCurrentKey = getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT);
71
SoundOption.this.msCurrentKey = getConfig().getStringConfigValue(TGConfigKeys.MIDI_SEQUENCER);
73
final String mpLoaded = TuxGuitar.instance().getPlayer().getMidiPort().getKey();
74
final String msLoaded = TuxGuitar.instance().getPlayer().getSequencer().getKey();
76
new SyncThread(new Runnable() {
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);
91
if(SoundOption.this.msCombo.getSelectionIndex() < 0 && SoundOption.this.msCombo.getItemCount() > 0){
92
SoundOption.this.msCombo.select(0);
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);
103
}else if(loadedPort != null && loadedPort.equals(port.getKey())){
104
SoundOption.this.mpCombo.select(i);
107
if(SoundOption.this.mpCombo.getSelectionIndex() < 0 && SoundOption.this.mpCombo.getItemCount() > 0){
108
SoundOption.this.mpCombo.select(0);
111
SoundOption.this.initialized = true;
112
SoundOption.this.pack();
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());
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());
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));
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);
147
String midiPort = getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT);
148
if(force || !TuxGuitar.instance().getPlayer().isMidiPortOpen(midiPort)){
149
TuxGuitar.instance().getPlayer().openPort(midiPort);
b'\\ No newline at end of file'