/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSChannelsDefaultSettingsPane.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/std/JSChannelsDefaultSettingsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 9139 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 iliev 1313 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2288 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1313 *
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 iliev 1334 import java.awt.Dimension;
27 iliev 1313 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 iliev 1545 import java.text.NumberFormat;
35    
36 iliev 1334 import javax.swing.Box;
37     import javax.swing.BoxLayout;
38 iliev 1313 import javax.swing.JComboBox;
39     import javax.swing.JDialog;
40     import javax.swing.JLabel;
41 iliev 1334 import javax.swing.JSlider;
42 iliev 1313 import javax.swing.JPanel;
43    
44 iliev 1334 import javax.swing.event.ChangeEvent;
45     import javax.swing.event.ChangeListener;
46    
47 iliev 2288 import net.sf.juife.swing.InformationDialog;
48 iliev 1313
49     import org.linuxsampler.lscp.SamplerEngine;
50    
51     import org.jsampler.CC;
52 iliev 1545 import org.jsampler.HF;
53 iliev 1313 import org.jsampler.JSPrefs;
54    
55     import static org.jsampler.view.std.StdI18n.i18n;
56 iliev 2288 import static org.jsampler.JSPrefs.*;
57 iliev 1313
58    
59     /**
60     *
61     * @author Grigor Iliev
62     */
63     public class JSChannelsDefaultSettingsPane extends JPanel {
64     private final JLabel lDefaultEngine =
65     new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lDefaultEngine"));
66    
67     private final JLabel lMidiInput =
68     new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lMidiInput"));
69    
70     private final JLabel lAudioOutput =
71     new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lAudioOutput"));
72    
73 iliev 1334 private final JLabel lChannelVolume =
74     new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lChannelVolume"));
75    
76     private final JLabel lMidiMap =
77     new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lMidiMap"));
78    
79 iliev 1313 private final JComboBox cbDefaultEngine = new JComboBox();
80     private final JComboBox cbMidiInput = new JComboBox();
81     private final JComboBox cbAudioOutput = new JComboBox();
82 iliev 1334 private final JSlider slChannelVolume = new JSlider(0, 100);
83     private final JComboBox cbMidiMap = new JComboBox();
84 iliev 1313
85 iliev 1334 private final JLabel lVolume = new JLabel();
86    
87 iliev 1313 private final static String strFirstDevice =
88     i18n.getLabel("JSChannelsDefaultSettingsPane.strFirstDevice");
89    
90     private final static String strFirstDeviceNextChannel =
91     i18n.getLabel("JSChannelsDefaultSettingsPane.strFirstDeviceNextChannel");
92    
93 iliev 1334 private class NoMap {
94     public String
95     toString() { return "[None]"; }
96     }
97    
98     private NoMap noMap = new NoMap();
99    
100     private class DefaultMap {
101     public String
102     toString() { return "[Default]"; }
103     }
104    
105     private DefaultMap defaultMap = new DefaultMap();
106    
107 iliev 1545 private static NumberFormat numberFormat = NumberFormat.getInstance();
108    
109    
110 iliev 1313 /** Creates a new instance of <code>JSChannelsDefaultSettingsPane</code> */
111     public
112     JSChannelsDefaultSettingsPane() {
113 iliev 1545 numberFormat.setMaximumFractionDigits(1);
114    
115 iliev 1313 GridBagLayout gridbag = new GridBagLayout();
116     GridBagConstraints c = new GridBagConstraints();
117    
118     setLayout(gridbag);
119    
120     c.fill = GridBagConstraints.NONE;
121    
122     c.gridx = 0;
123     c.gridy = 0;
124     c.anchor = GridBagConstraints.EAST;
125     c.insets = new Insets(3, 3, 3, 3);
126     gridbag.setConstraints(lDefaultEngine, c);
127     add(lDefaultEngine);
128    
129     c.gridx = 0;
130     c.gridy = 1;
131     gridbag.setConstraints(lMidiInput, c);
132     add(lMidiInput);
133    
134     c.gridx = 0;
135     c.gridy = 2;
136     gridbag.setConstraints(lAudioOutput, c);
137     add(lAudioOutput);
138 iliev 1334
139     c.gridx = 0;
140     c.gridy = 3;
141     gridbag.setConstraints(lMidiMap, c);
142 iliev 1343 add(lMidiMap);
143 iliev 1334
144     c.gridx = 0;
145     c.gridy = 4;
146     gridbag.setConstraints(lChannelVolume, c);
147     add(lChannelVolume);
148 iliev 1313
149     c.fill = GridBagConstraints.HORIZONTAL;
150     c.gridx = 1;
151     c.gridy = 0;
152     c.weightx = 1.0;
153     c.anchor = GridBagConstraints.WEST;
154     gridbag.setConstraints(cbDefaultEngine, c);
155     add(cbDefaultEngine);
156    
157     c.gridx = 1;
158     c.gridy = 1;
159     gridbag.setConstraints(cbMidiInput, c);
160     add(cbMidiInput);
161    
162     c.gridx = 1;
163     c.gridy = 2;
164     gridbag.setConstraints(cbAudioOutput, c);
165     add(cbAudioOutput);
166    
167 iliev 1334 c.gridx = 1;
168     c.gridy = 3;
169     gridbag.setConstraints(cbMidiMap, c);
170     add(cbMidiMap);
171    
172     JPanel volumePane = new JPanel();
173     volumePane.setOpaque(false);
174     volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));
175    
176     Dimension d = slChannelVolume.getPreferredSize();
177     slChannelVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));
178     slChannelVolume.setOpaque(false);
179     volumePane.add(slChannelVolume);
180    
181     volumePane.add(Box.createRigidArea(new Dimension(6, 0)));
182    
183     lVolume.setHorizontalAlignment(lVolume.RIGHT);
184    
185 iliev 1545 // We use this to set the size of the lVolume
186 iliev 1334 // to prevent the frequent resizing of lVolume
187 iliev 1545 lVolume.setText("100000%");
188     lVolume.setPreferredSize(lVolume.getPreferredSize());
189     lVolume.setMinimumSize(lVolume.getPreferredSize());
190 iliev 1334
191     volumePane.add(lVolume);
192    
193     slChannelVolume.addChangeListener(new ChangeListener() {
194     public void
195     stateChanged(ChangeEvent e) { updateVolume(); }
196     });
197    
198     int v = preferences().getIntProperty(DEFAULT_CHANNEL_VOLUME);
199     slChannelVolume.setValue(v);
200    
201     c.gridx = 1;
202     c.gridy = 4;
203     gridbag.setConstraints(volumePane, c);
204     add(volumePane);
205    
206 iliev 1313 for(SamplerEngine e : CC.getSamplerModel().getEngines()) {
207     cbDefaultEngine.addItem(e);
208     }
209    
210     String defaultEngine = preferences().getStringProperty(DEFAULT_ENGINE);
211     for(SamplerEngine e : CC.getSamplerModel().getEngines()) {
212     if(e.getName().equals(defaultEngine)) cbDefaultEngine.setSelectedItem(e);
213     }
214    
215     cbDefaultEngine.addActionListener(new ActionListener() {
216     public void
217     actionPerformed(ActionEvent e) { changeDefaultEngine(); }
218     });
219    
220     cbMidiInput.addItem(strFirstDevice);
221     cbMidiInput.addItem(strFirstDeviceNextChannel);
222    
223     String s = preferences().getStringProperty(DEFAULT_MIDI_INPUT);
224    
225     if(s.equals("firstDevice")) {
226     cbMidiInput.setSelectedItem(strFirstDevice);
227     } else if(s.equals("firstDeviceNextChannel")) {
228     cbMidiInput.setSelectedItem(strFirstDeviceNextChannel);
229     }
230    
231     cbMidiInput.addActionListener(new ActionListener() {
232     public void
233     actionPerformed(ActionEvent e) { changeDefaultMidiInput(); }
234     });
235    
236     cbAudioOutput.addItem(strFirstDevice);
237    
238     cbAudioOutput.addActionListener(new ActionListener() {
239     public void
240     actionPerformed(ActionEvent e) { changeDefaultAudioOutput(); }
241     });
242 iliev 1334
243     cbMidiMap.addItem(noMap);
244     cbMidiMap.addItem(defaultMap);
245    
246     String midiMap = preferences().getStringProperty(DEFAULT_MIDI_INSTRUMENT_MAP);
247     if(midiMap.equals("midiInstrumentMap.none")) {
248     cbMidiMap.setSelectedItem(noMap);
249     } else if(midiMap.equals("midiInstrumentMap.default")) {
250     cbMidiMap.setSelectedItem(defaultMap);
251     }
252    
253     cbMidiMap.addActionListener(new ActionListener() {
254     public void
255     actionPerformed(ActionEvent e) { changeDefaultMidiMap(); }
256     });
257 iliev 1313 }
258    
259     public JDialog
260     createDialog(Dialog owner) {
261     String s = i18n.getLabel("JSChannelsDefaultSettingsPane.title");
262     InformationDialog dlg = new InformationDialog(owner, s, this);
263     return dlg;
264     }
265    
266     private void
267     changeDefaultEngine() {
268     Object o = cbDefaultEngine.getSelectedItem();
269     if(o == null) return;
270     String s = ((SamplerEngine) o).getName();
271     preferences().setStringProperty(DEFAULT_ENGINE, s);
272     }
273    
274     private void
275     changeDefaultMidiInput() {
276     Object o = cbMidiInput.getSelectedItem();
277     if(o == null) return;
278    
279     if(o == strFirstDevice) {
280     preferences().setStringProperty(DEFAULT_MIDI_INPUT, "firstDevice");
281     } else if(o == strFirstDeviceNextChannel) {
282     preferences().setStringProperty(DEFAULT_MIDI_INPUT, "firstDeviceNextChannel");
283     }
284     }
285    
286     private void
287     changeDefaultAudioOutput() {
288     Object o = cbAudioOutput.getSelectedItem();
289     if(o == null) return;
290    
291     if(o == strFirstDevice) {
292     preferences().setStringProperty(DEFAULT_AUDIO_OUTPUT, "firstDevice");
293     }
294     }
295    
296 iliev 1334 private void
297     changeDefaultMidiMap() {
298     Object o = cbMidiMap.getSelectedItem();
299     if(o == null) return;
300     String s = DEFAULT_MIDI_INSTRUMENT_MAP;
301     if(o == noMap) {
302     preferences().setStringProperty(s, "midiInstrumentMap.none");
303     } else if(o == defaultMap) {
304     preferences().setStringProperty(s, "midiInstrumentMap.default");
305     }
306     }
307    
308     private void
309     updateVolume() {
310     int volume = slChannelVolume.getValue();
311 iliev 1545 if(CC.getViewConfig().isMeasurementUnitDecibel()) {
312     double dB = HF.percentsToDecibels(volume);
313     lVolume.setText(numberFormat.format(dB) + "dB");
314     } else {
315     lVolume.setText(String.valueOf(volume) + '%');
316     }
317 iliev 1334
318     if(slChannelVolume.getValueIsAdjusting()) return;
319     preferences().setIntProperty(DEFAULT_CHANNEL_VOLUME, slChannelVolume.getValue());
320     }
321    
322 iliev 1313 private static JSPrefs
323     preferences() { return CC.getViewConfig().preferences(); }
324     }

  ViewVC Help
Powered by ViewVC