1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.view.std; |
24 |
|
25 |
import java.awt.Dialog; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.Box; |
36 |
import javax.swing.BoxLayout; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JDialog; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JSlider; |
41 |
import javax.swing.JPanel; |
42 |
|
43 |
import javax.swing.event.ChangeEvent; |
44 |
import javax.swing.event.ChangeListener; |
45 |
|
46 |
import net.sf.juife.InformationDialog; |
47 |
import net.sf.juife.JuifeUtils; |
48 |
|
49 |
import org.linuxsampler.lscp.SamplerEngine; |
50 |
|
51 |
import org.jsampler.CC; |
52 |
import org.jsampler.JSPrefs; |
53 |
|
54 |
import static org.jsampler.view.std.StdI18n.i18n; |
55 |
import static org.jsampler.view.std.StdPrefs.*; |
56 |
|
57 |
|
58 |
/** |
59 |
* |
60 |
* @author Grigor Iliev |
61 |
*/ |
62 |
public class JSChannelsDefaultSettingsPane extends JPanel { |
63 |
private final JLabel lDefaultEngine = |
64 |
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lDefaultEngine")); |
65 |
|
66 |
private final JLabel lMidiInput = |
67 |
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lMidiInput")); |
68 |
|
69 |
private final JLabel lAudioOutput = |
70 |
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lAudioOutput")); |
71 |
|
72 |
private final JLabel lChannelVolume = |
73 |
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lChannelVolume")); |
74 |
|
75 |
private final JLabel lMidiMap = |
76 |
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lMidiMap")); |
77 |
|
78 |
private final JComboBox cbDefaultEngine = new JComboBox(); |
79 |
private final JComboBox cbMidiInput = new JComboBox(); |
80 |
private final JComboBox cbAudioOutput = new JComboBox(); |
81 |
private final JSlider slChannelVolume = new JSlider(0, 100); |
82 |
private final JComboBox cbMidiMap = new JComboBox(); |
83 |
|
84 |
private final JLabel lVolume = new JLabel(); |
85 |
|
86 |
private final static String strFirstDevice = |
87 |
i18n.getLabel("JSChannelsDefaultSettingsPane.strFirstDevice"); |
88 |
|
89 |
private final static String strFirstDeviceNextChannel = |
90 |
i18n.getLabel("JSChannelsDefaultSettingsPane.strFirstDeviceNextChannel"); |
91 |
|
92 |
private class NoMap { |
93 |
public String |
94 |
toString() { return "[None]"; } |
95 |
} |
96 |
|
97 |
private NoMap noMap = new NoMap(); |
98 |
|
99 |
private class DefaultMap { |
100 |
public String |
101 |
toString() { return "[Default]"; } |
102 |
} |
103 |
|
104 |
private DefaultMap defaultMap = new DefaultMap(); |
105 |
|
106 |
/** Creates a new instance of <code>JSChannelsDefaultSettingsPane</code> */ |
107 |
public |
108 |
JSChannelsDefaultSettingsPane() { |
109 |
GridBagLayout gridbag = new GridBagLayout(); |
110 |
GridBagConstraints c = new GridBagConstraints(); |
111 |
|
112 |
setLayout(gridbag); |
113 |
|
114 |
c.fill = GridBagConstraints.NONE; |
115 |
|
116 |
c.gridx = 0; |
117 |
c.gridy = 0; |
118 |
c.anchor = GridBagConstraints.EAST; |
119 |
c.insets = new Insets(3, 3, 3, 3); |
120 |
gridbag.setConstraints(lDefaultEngine, c); |
121 |
add(lDefaultEngine); |
122 |
|
123 |
c.gridx = 0; |
124 |
c.gridy = 1; |
125 |
gridbag.setConstraints(lMidiInput, c); |
126 |
add(lMidiInput); |
127 |
|
128 |
c.gridx = 0; |
129 |
c.gridy = 2; |
130 |
gridbag.setConstraints(lAudioOutput, c); |
131 |
add(lAudioOutput); |
132 |
|
133 |
c.gridx = 0; |
134 |
c.gridy = 3; |
135 |
gridbag.setConstraints(lMidiMap, c); |
136 |
add(lMidiMap); |
137 |
|
138 |
c.gridx = 0; |
139 |
c.gridy = 4; |
140 |
gridbag.setConstraints(lChannelVolume, c); |
141 |
add(lChannelVolume); |
142 |
|
143 |
c.fill = GridBagConstraints.HORIZONTAL; |
144 |
c.gridx = 1; |
145 |
c.gridy = 0; |
146 |
c.weightx = 1.0; |
147 |
c.anchor = GridBagConstraints.WEST; |
148 |
gridbag.setConstraints(cbDefaultEngine, c); |
149 |
add(cbDefaultEngine); |
150 |
|
151 |
c.gridx = 1; |
152 |
c.gridy = 1; |
153 |
gridbag.setConstraints(cbMidiInput, c); |
154 |
add(cbMidiInput); |
155 |
|
156 |
c.gridx = 1; |
157 |
c.gridy = 2; |
158 |
gridbag.setConstraints(cbAudioOutput, c); |
159 |
add(cbAudioOutput); |
160 |
|
161 |
c.gridx = 1; |
162 |
c.gridy = 3; |
163 |
gridbag.setConstraints(cbMidiMap, c); |
164 |
add(cbMidiMap); |
165 |
|
166 |
JPanel volumePane = new JPanel(); |
167 |
volumePane.setOpaque(false); |
168 |
volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS)); |
169 |
|
170 |
Dimension d = slChannelVolume.getPreferredSize(); |
171 |
slChannelVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height)); |
172 |
slChannelVolume.setOpaque(false); |
173 |
volumePane.add(slChannelVolume); |
174 |
|
175 |
volumePane.add(Box.createRigidArea(new Dimension(6, 0))); |
176 |
|
177 |
lVolume.setHorizontalAlignment(lVolume.RIGHT); |
178 |
|
179 |
// We use this to set the size of the lVolume that will be used in setVolume() |
180 |
// to prevent the frequent resizing of lVolume |
181 |
lVolume.setText("100%"); |
182 |
|
183 |
volumePane.add(lVolume); |
184 |
|
185 |
slChannelVolume.addChangeListener(new ChangeListener() { |
186 |
public void |
187 |
stateChanged(ChangeEvent e) { updateVolume(); } |
188 |
}); |
189 |
|
190 |
int v = preferences().getIntProperty(DEFAULT_CHANNEL_VOLUME); |
191 |
slChannelVolume.setValue(v); |
192 |
|
193 |
c.gridx = 1; |
194 |
c.gridy = 4; |
195 |
gridbag.setConstraints(volumePane, c); |
196 |
add(volumePane); |
197 |
|
198 |
for(SamplerEngine e : CC.getSamplerModel().getEngines()) { |
199 |
cbDefaultEngine.addItem(e); |
200 |
} |
201 |
|
202 |
String defaultEngine = preferences().getStringProperty(DEFAULT_ENGINE); |
203 |
for(SamplerEngine e : CC.getSamplerModel().getEngines()) { |
204 |
if(e.getName().equals(defaultEngine)) cbDefaultEngine.setSelectedItem(e); |
205 |
} |
206 |
|
207 |
cbDefaultEngine.addActionListener(new ActionListener() { |
208 |
public void |
209 |
actionPerformed(ActionEvent e) { changeDefaultEngine(); } |
210 |
}); |
211 |
|
212 |
cbMidiInput.addItem(strFirstDevice); |
213 |
cbMidiInput.addItem(strFirstDeviceNextChannel); |
214 |
|
215 |
String s = preferences().getStringProperty(DEFAULT_MIDI_INPUT); |
216 |
|
217 |
if(s.equals("firstDevice")) { |
218 |
cbMidiInput.setSelectedItem(strFirstDevice); |
219 |
} else if(s.equals("firstDeviceNextChannel")) { |
220 |
cbMidiInput.setSelectedItem(strFirstDeviceNextChannel); |
221 |
} |
222 |
|
223 |
cbMidiInput.addActionListener(new ActionListener() { |
224 |
public void |
225 |
actionPerformed(ActionEvent e) { changeDefaultMidiInput(); } |
226 |
}); |
227 |
|
228 |
cbAudioOutput.addItem(strFirstDevice); |
229 |
|
230 |
cbAudioOutput.addActionListener(new ActionListener() { |
231 |
public void |
232 |
actionPerformed(ActionEvent e) { changeDefaultAudioOutput(); } |
233 |
}); |
234 |
|
235 |
cbMidiMap.addItem(noMap); |
236 |
cbMidiMap.addItem(defaultMap); |
237 |
|
238 |
String midiMap = preferences().getStringProperty(DEFAULT_MIDI_INSTRUMENT_MAP); |
239 |
if(midiMap.equals("midiInstrumentMap.none")) { |
240 |
cbMidiMap.setSelectedItem(noMap); |
241 |
} else if(midiMap.equals("midiInstrumentMap.default")) { |
242 |
cbMidiMap.setSelectedItem(defaultMap); |
243 |
} |
244 |
|
245 |
cbMidiMap.addActionListener(new ActionListener() { |
246 |
public void |
247 |
actionPerformed(ActionEvent e) { changeDefaultMidiMap(); } |
248 |
}); |
249 |
} |
250 |
|
251 |
public JDialog |
252 |
createDialog(Dialog owner) { |
253 |
String s = i18n.getLabel("JSChannelsDefaultSettingsPane.title"); |
254 |
InformationDialog dlg = new InformationDialog(owner, s, this); |
255 |
return dlg; |
256 |
} |
257 |
|
258 |
private void |
259 |
changeDefaultEngine() { |
260 |
Object o = cbDefaultEngine.getSelectedItem(); |
261 |
if(o == null) return; |
262 |
String s = ((SamplerEngine) o).getName(); |
263 |
preferences().setStringProperty(DEFAULT_ENGINE, s); |
264 |
} |
265 |
|
266 |
private void |
267 |
changeDefaultMidiInput() { |
268 |
Object o = cbMidiInput.getSelectedItem(); |
269 |
if(o == null) return; |
270 |
|
271 |
if(o == strFirstDevice) { |
272 |
preferences().setStringProperty(DEFAULT_MIDI_INPUT, "firstDevice"); |
273 |
} else if(o == strFirstDeviceNextChannel) { |
274 |
preferences().setStringProperty(DEFAULT_MIDI_INPUT, "firstDeviceNextChannel"); |
275 |
} |
276 |
} |
277 |
|
278 |
private void |
279 |
changeDefaultAudioOutput() { |
280 |
Object o = cbAudioOutput.getSelectedItem(); |
281 |
if(o == null) return; |
282 |
|
283 |
if(o == strFirstDevice) { |
284 |
preferences().setStringProperty(DEFAULT_AUDIO_OUTPUT, "firstDevice"); |
285 |
} |
286 |
} |
287 |
|
288 |
private void |
289 |
changeDefaultMidiMap() { |
290 |
Object o = cbMidiMap.getSelectedItem(); |
291 |
if(o == null) return; |
292 |
String s = DEFAULT_MIDI_INSTRUMENT_MAP; |
293 |
if(o == noMap) { |
294 |
preferences().setStringProperty(s, "midiInstrumentMap.none"); |
295 |
} else if(o == defaultMap) { |
296 |
preferences().setStringProperty(s, "midiInstrumentMap.default"); |
297 |
} |
298 |
} |
299 |
|
300 |
private void |
301 |
updateVolume() { |
302 |
int volume = slChannelVolume.getValue(); |
303 |
Dimension d = lVolume.getPreferredSize(); |
304 |
lVolume.setText(String.valueOf(volume) + '%'); |
305 |
d = JuifeUtils.getUnionSize(d, lVolume.getPreferredSize()); |
306 |
lVolume.setMinimumSize(d); |
307 |
lVolume.setPreferredSize(d); |
308 |
lVolume.setMaximumSize(d); |
309 |
|
310 |
if(slChannelVolume.getValueIsAdjusting()) return; |
311 |
preferences().setIntProperty(DEFAULT_CHANNEL_VOLUME, slChannelVolume.getValue()); |
312 |
} |
313 |
|
314 |
private static JSPrefs |
315 |
preferences() { return CC.getViewConfig().preferences(); } |
316 |
} |