/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/AudioDevicePane.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/AudioDevicePane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1743 - (hide annotations) (download)
Sat May 31 23:04:01 2008 UTC (15 years, 11 months ago) by iliev
File size: 10068 byte(s)
* Renamed the column labels in the Channel Routing dialog: The column
  representing the sampler channel's audio channels is "Audio In" and
  the column representing the audio device's channels is "Audio Out"
* Remember the last used tab in the Preferences dialog
* Fantasia: The sampler channels are now referenced by their position
  in the list, not by their ID
* Fantasia: Implemented options to show the channel number and/or the MIDI
  input port/channel on the sampler channel screen when using Small View
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: Migrated to substance 5

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1743 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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.fantasia;
24    
25     import java.awt.Dimension;
26     import java.awt.Insets;
27    
28     import java.awt.event.ActionEvent;
29     import java.awt.event.ActionListener;
30     import java.awt.event.ItemEvent;
31     import java.awt.event.ItemListener;
32    
33 iliev 1357 import java.beans.PropertyChangeEvent;
34     import java.beans.PropertyChangeListener;
35    
36 iliev 1286 import javax.swing.BorderFactory;
37     import javax.swing.Box;
38     import javax.swing.BoxLayout;
39     import javax.swing.JCheckBox;
40     import javax.swing.JComboBox;
41     import javax.swing.JLabel;
42     import javax.swing.JPanel;
43     import javax.swing.JScrollPane;
44     import javax.swing.JSpinner;
45     import javax.swing.SpinnerNumberModel;
46    
47     import javax.swing.event.ChangeEvent;
48     import javax.swing.event.ChangeListener;
49    
50 iliev 1310 import net.sf.juife.Task;
51     import net.sf.juife.event.TaskEvent;
52     import net.sf.juife.event.TaskListener;
53    
54 iliev 1286 import org.jsampler.AudioDeviceModel;
55     import org.jsampler.CC;
56    
57     import org.jsampler.event.AudioDeviceEvent;
58     import org.jsampler.event.AudioDeviceListener;
59     import org.jsampler.event.ParameterEvent;
60     import org.jsampler.event.ParameterListener;
61    
62 iliev 1310 import org.jsampler.task.Audio;
63 iliev 1286 import org.jsampler.view.ParameterTable;
64    
65     import org.linuxsampler.lscp.AudioOutputChannel;
66     import org.linuxsampler.lscp.AudioOutputDevice;
67     import org.linuxsampler.lscp.Parameter;
68 iliev 1445 import org.linuxsampler.lscp.ParameterFactory;
69 iliev 1286
70     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
71 iliev 1357 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
72 iliev 1286
73     /**
74     *
75     * @author Grigor Iliev
76     */
77     public class AudioDevicePane extends DevicePane {
78     private final OptionsPane optionsPane;
79     private final ParameterTable channelParamTable = new ParameterTable();
80    
81     private final AudioDeviceModel audioDeviceModel;
82    
83    
84     /** Creates a new instance of <code>AudioDevicePane</code> */
85     public
86     AudioDevicePane(AudioDeviceModel model) {
87     audioDeviceModel = model;
88    
89 iliev 1743 channelParamTable.setFillsViewportHeight(true);
90    
91 iliev 1286 optionsPane = new OptionsPane();
92     setOptionsPane(optionsPane);
93    
94     int id = model.getDeviceId();
95 iliev 1445 String s = model.getDeviceInfo().getDriverName();
96     setDeviceName(i18n.getLabel("AudioDevicePane.lDevName", id, s));
97 iliev 1286 }
98    
99     protected void
100     destroyDevice() {
101 iliev 1310 final Task t = new Audio.DestroyDevice(getDeviceId());
102     t.addTaskListener(new TaskListener() {
103     public void
104     taskPerformed(TaskEvent e) {
105     if(t.doneWithErrors()) restoreDevice();
106     }
107     });
108    
109     CC.getTaskQueue().add(t);
110 iliev 1286 }
111    
112     public int
113     getDeviceId() { return audioDeviceModel.getDeviceId(); }
114    
115     class OptionsPane extends PixmapPane implements ActionListener, ItemListener,
116     ChangeListener, AudioDeviceListener, ParameterListener {
117    
118     private final JCheckBox checkActive =
119     new JCheckBox(i18n.getLabel("AudioDevicePane.checkActive"));
120    
121     private final JLabel lChannels
122     = new JLabel(i18n.getLabel("AudioDevicePane.lChannels"));
123    
124 iliev 1496 private final JSpinner spinnerChannels;
125 iliev 1286
126     private final JLabel lChannel =
127     new JLabel(i18n.getLabel("AudioDevicePane.lChannel"));
128    
129     private final JComboBox cbChannel = new JComboBox();
130    
131 iliev 1357 private final ParameterTable additionalParamsTable = new ParameterTable();
132     private final JPanel additionalParamsPane = new JPanel();
133    
134 iliev 1286 OptionsPane() {
135     super(Res.gfxChannelOptions);
136    
137     setAlignmentX(LEFT_ALIGNMENT);
138    
139     setPixmapInsets(new Insets(1, 1, 1, 1));
140     setLayout(new java.awt.BorderLayout());
141     setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
142     setOpaque(false);
143    
144     PixmapPane mainPane = new PixmapPane(Res.gfxRoundBg7);
145     mainPane.setPixmapInsets(new Insets(3, 3, 3, 3));
146     mainPane.setOpaque(false);
147    
148     mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
149     mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
150     mainPane.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
151    
152     JPanel p = new JPanel();
153     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
154    
155     p.add(checkActive);
156     p.add(Box.createRigidArea(new Dimension(12, 0)));
157     p.add(lChannels);
158     p.add(Box.createRigidArea(new Dimension(5, 0)));
159 iliev 1496
160     Parameter<Integer> prm =
161     audioDeviceModel.getDeviceInfo().getChannelsParameter();
162     int min = 1;
163     if(prm.getRangeMin() != null) min = prm.getRangeMin().intValue();
164 iliev 1606 int max = 10000;
165 iliev 1496 if(prm.getRangeMax() != null) max = prm.getRangeMax().intValue();
166    
167     spinnerChannels = new JSpinner(new SpinnerNumberModel(1, min, max, 1));
168     if(prm.isFixed()) spinnerChannels.setEnabled(false);
169 iliev 1743 int h = spinnerChannels.getPreferredSize().height;
170     spinnerChannels.setPreferredSize(new Dimension(30, h));
171 iliev 1286 p.add(spinnerChannels);
172     p.setOpaque(false);
173    
174     mainPane.add(p);
175     mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
176    
177 iliev 1357 JPanel p2 = additionalParamsPane;
178     p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
179     p2.setOpaque(false);
180    
181     p2.add(createHSeparator());
182     p2.add(Box.createRigidArea(new Dimension(0, 5)));
183    
184     JScrollPane sp = new JScrollPane(additionalParamsTable);
185    
186     sp.setPreferredSize(new Dimension(77, 90));
187     p2.add(sp);
188     mainPane.add(p2);
189    
190     mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
191    
192 iliev 1286 mainPane.add(createHSeparator());
193     mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
194    
195     p = new JPanel();
196     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
197     p.setOpaque(false);
198    
199 iliev 1357 p2 = new JPanel();
200 iliev 1286 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
201     p2.add(lChannel);
202     p2.add(Box.createRigidArea(new Dimension(5, 0)));
203     p2.add(cbChannel);
204     p2.setOpaque(false);
205     p.add(p2);
206    
207     p.add(Box.createRigidArea(new Dimension(0, 5)));
208    
209 iliev 1357 sp = new JScrollPane(channelParamTable);
210 iliev 1286 sp.setPreferredSize(new Dimension(77, 90));
211     p.add(sp);
212    
213     mainPane.add(p);
214     add(mainPane);
215    
216     checkActive.setSelected(audioDeviceModel.isActive());
217     spinnerChannels.setValue(audioDeviceModel.getDeviceInfo().getChannelCount());
218    
219     cbChannel.addActionListener(this);
220     checkActive.addItemListener(this);
221     spinnerChannels.addChangeListener(this);
222     audioDeviceModel.addAudioDeviceListener(this);
223     channelParamTable.getModel().addParameterListener(this);
224    
225     AudioDeviceModel m = audioDeviceModel;
226     for(AudioOutputChannel chn : m.getDeviceInfo().getAudioChannels()) {
227     cbChannel.addItem(chn);
228     }
229 iliev 1357
230 iliev 1445 updateParams(audioDeviceModel.getDeviceInfo());
231 iliev 1357 additionalParamsTable.getModel().addParameterListener(new ParameterListener() {
232     public void
233     parameterChanged(ParameterEvent e) {
234     audioDeviceModel.setBackendDeviceParameter(e.getParameter());
235     }
236     });
237    
238     updateAdditionalParamsViewState();
239     String s = "AudioDevice.showAdditionalParameters";
240     preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
241     public void
242     propertyChange(PropertyChangeEvent e) {
243     updateAdditionalParamsViewState();
244     }
245     });
246 iliev 1286 }
247    
248 iliev 1357 private void
249     updateAdditionalParamsViewState() {
250     String s = "AudioDevice.showAdditionalParameters";
251     additionalParamsPane.setVisible(preferences().getBoolProperty(s));
252     validate();
253     }
254    
255 iliev 1286 public void
256     actionPerformed(ActionEvent e) {
257     Object obj = cbChannel.getSelectedItem();
258     if(obj == null) {
259     channelParamTable.getModel().setParameters(new Parameter[0]);
260     return;
261     }
262    
263     AudioOutputChannel chn = (AudioOutputChannel)obj;
264    
265     channelParamTable.getModel().setParameters(chn.getAllParameters());
266     }
267    
268     public void
269     itemStateChanged(ItemEvent e) {
270     boolean a = checkActive.isSelected();
271     if(a != audioDeviceModel.isActive()) audioDeviceModel.setBackendActive(a);
272     }
273    
274     public void
275     stateChanged(ChangeEvent e) {
276     int c = (Integer)spinnerChannels.getValue();
277     if(c != audioDeviceModel.getDeviceInfo().getAudioChannelCount()) {
278     audioDeviceModel.setBackendChannelCount(c);
279     }
280     }
281    
282     public void
283     settingsChanged(AudioDeviceEvent e) {
284     int c = (Integer)spinnerChannels.getValue();
285     int nc = audioDeviceModel.getDeviceInfo().getAudioChannelCount();
286     if(c != nc) spinnerChannels.setValue(nc);
287    
288     boolean a = checkActive.isSelected();
289     boolean na = audioDeviceModel.isActive();
290     if(a != na) checkActive.setSelected(na);
291    
292     AudioOutputDevice d = e.getAudioDeviceModel().getDeviceInfo();
293 iliev 1445 updateParams(d);
294 iliev 1286
295     int idx = cbChannel.getSelectedIndex();
296     cbChannel.removeAllItems();
297     for(AudioOutputChannel chn : d.getAudioChannels()) cbChannel.addItem(chn);
298    
299     if(idx >= cbChannel.getModel().getSize()) idx = 0;
300    
301     if(cbChannel.getModel().getSize() > 0) cbChannel.setSelectedIndex(idx);
302     }
303    
304     public void
305     parameterChanged(ParameterEvent e) {
306     int c = cbChannel.getSelectedIndex();
307     if(c == -1) {
308     CC.getLogger().warning("There is no audio channel selected!");
309     return;
310     }
311    
312     audioDeviceModel.setBackendChannelParameter(c, e.getParameter());
313     }
314 iliev 1445
315     private void
316     updateParams(AudioOutputDevice d) {
317 iliev 1606 Parameter p = d.getSampleRateParameter();
318     boolean b = p == null || p.getName() == null || p.getValue() == null;
319 iliev 1445 Parameter[] params = d.getAdditionalParameters();
320 iliev 1606 Parameter[] p2s;
321     if(b) p2s = new Parameter[params.length];
322     else p2s = new Parameter[params.length + 1];
323 iliev 1445
324     for(int i = 0; i < params.length; i++) p2s[i] = params[i];
325    
326 iliev 1606 if(!b) p2s[params.length] = p;
327 iliev 1445
328     additionalParamsTable.getModel().setParameters(p2s);
329     }
330 iliev 1286 }
331    
332     }

  ViewVC Help
Powered by ViewVC