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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1445 - (show annotations) (download)
Mon Oct 15 20:55:33 2007 UTC (16 years, 6 months ago) by iliev
File size: 9397 byte(s)
* preparations for release 0.7a

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.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 import java.beans.PropertyChangeEvent;
34 import java.beans.PropertyChangeListener;
35
36 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 import net.sf.juife.Task;
51 import net.sf.juife.event.TaskEvent;
52 import net.sf.juife.event.TaskListener;
53
54 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 import org.jsampler.task.Audio;
63 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 import org.linuxsampler.lscp.ParameterFactory;
69
70 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
71 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
72
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 optionsPane = new OptionsPane();
90 setOptionsPane(optionsPane);
91
92 int id = model.getDeviceId();
93 String s = model.getDeviceInfo().getDriverName();
94 setDeviceName(i18n.getLabel("AudioDevicePane.lDevName", id, s));
95 }
96
97 protected void
98 destroyDevice() {
99 final Task t = new Audio.DestroyDevice(getDeviceId());
100 t.addTaskListener(new TaskListener() {
101 public void
102 taskPerformed(TaskEvent e) {
103 if(t.doneWithErrors()) restoreDevice();
104 }
105 });
106
107 CC.getTaskQueue().add(t);
108 }
109
110 public int
111 getDeviceId() { return audioDeviceModel.getDeviceId(); }
112
113 class OptionsPane extends PixmapPane implements ActionListener, ItemListener,
114 ChangeListener, AudioDeviceListener, ParameterListener {
115
116 private final JCheckBox checkActive =
117 new JCheckBox(i18n.getLabel("AudioDevicePane.checkActive"));
118
119 private final JLabel lChannels
120 = new JLabel(i18n.getLabel("AudioDevicePane.lChannels"));
121
122 private final JSpinner spinnerChannels
123 = new JSpinner(new SpinnerNumberModel(1, 1, 50, 1));
124
125 private final JLabel lChannel =
126 new JLabel(i18n.getLabel("AudioDevicePane.lChannel"));
127
128 private final JComboBox cbChannel = new JComboBox();
129
130 private final ParameterTable additionalParamsTable = new ParameterTable();
131 private final JPanel additionalParamsPane = new JPanel();
132
133 OptionsPane() {
134 super(Res.gfxChannelOptions);
135
136 setAlignmentX(LEFT_ALIGNMENT);
137
138 setPixmapInsets(new Insets(1, 1, 1, 1));
139 setLayout(new java.awt.BorderLayout());
140 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
141 setOpaque(false);
142
143 PixmapPane mainPane = new PixmapPane(Res.gfxRoundBg7);
144 mainPane.setPixmapInsets(new Insets(3, 3, 3, 3));
145 mainPane.setOpaque(false);
146
147 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
148 mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
149 mainPane.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
150
151 JPanel p = new JPanel();
152 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
153
154 p.add(checkActive);
155 p.add(Box.createRigidArea(new Dimension(12, 0)));
156 p.add(lChannels);
157 p.add(Box.createRigidArea(new Dimension(5, 0)));
158 p.add(spinnerChannels);
159 p.setOpaque(false);
160
161 mainPane.add(p);
162 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
163
164 JPanel p2 = additionalParamsPane;
165 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
166 p2.setOpaque(false);
167
168 p2.add(createHSeparator());
169 p2.add(Box.createRigidArea(new Dimension(0, 5)));
170
171 JScrollPane sp = new JScrollPane(additionalParamsTable);
172
173 sp.setPreferredSize(new Dimension(77, 90));
174 p2.add(sp);
175 mainPane.add(p2);
176
177 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
178
179 mainPane.add(createHSeparator());
180 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
181
182 p = new JPanel();
183 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
184 p.setOpaque(false);
185
186 p2 = new JPanel();
187 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
188 p2.add(lChannel);
189 p2.add(Box.createRigidArea(new Dimension(5, 0)));
190 p2.add(cbChannel);
191 p2.setOpaque(false);
192 p.add(p2);
193
194 p.add(Box.createRigidArea(new Dimension(0, 5)));
195
196 sp = new JScrollPane(channelParamTable);
197 sp.setPreferredSize(new Dimension(77, 90));
198 p.add(sp);
199
200 mainPane.add(p);
201 add(mainPane);
202
203 checkActive.setSelected(audioDeviceModel.isActive());
204 spinnerChannels.setValue(audioDeviceModel.getDeviceInfo().getChannelCount());
205
206 cbChannel.addActionListener(this);
207 checkActive.addItemListener(this);
208 spinnerChannels.addChangeListener(this);
209 audioDeviceModel.addAudioDeviceListener(this);
210 channelParamTable.getModel().addParameterListener(this);
211
212 AudioDeviceModel m = audioDeviceModel;
213 for(AudioOutputChannel chn : m.getDeviceInfo().getAudioChannels()) {
214 cbChannel.addItem(chn);
215 }
216
217 updateParams(audioDeviceModel.getDeviceInfo());
218 additionalParamsTable.getModel().addParameterListener(new ParameterListener() {
219 public void
220 parameterChanged(ParameterEvent e) {
221 audioDeviceModel.setBackendDeviceParameter(e.getParameter());
222 }
223 });
224
225 updateAdditionalParamsViewState();
226 String s = "AudioDevice.showAdditionalParameters";
227 preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
228 public void
229 propertyChange(PropertyChangeEvent e) {
230 updateAdditionalParamsViewState();
231 }
232 });
233 }
234
235 private void
236 updateAdditionalParamsViewState() {
237 String s = "AudioDevice.showAdditionalParameters";
238 additionalParamsPane.setVisible(preferences().getBoolProperty(s));
239 validate();
240 }
241
242 public void
243 actionPerformed(ActionEvent e) {
244 Object obj = cbChannel.getSelectedItem();
245 if(obj == null) {
246 channelParamTable.getModel().setParameters(new Parameter[0]);
247 return;
248 }
249
250 AudioOutputChannel chn = (AudioOutputChannel)obj;
251
252 channelParamTable.getModel().setParameters(chn.getAllParameters());
253 }
254
255 public void
256 itemStateChanged(ItemEvent e) {
257 boolean a = checkActive.isSelected();
258 if(a != audioDeviceModel.isActive()) audioDeviceModel.setBackendActive(a);
259 }
260
261 public void
262 stateChanged(ChangeEvent e) {
263 int c = (Integer)spinnerChannels.getValue();
264 if(c != audioDeviceModel.getDeviceInfo().getAudioChannelCount()) {
265 audioDeviceModel.setBackendChannelCount(c);
266 }
267 }
268
269 public void
270 settingsChanged(AudioDeviceEvent e) {
271 int c = (Integer)spinnerChannels.getValue();
272 int nc = audioDeviceModel.getDeviceInfo().getAudioChannelCount();
273 if(c != nc) spinnerChannels.setValue(nc);
274
275 boolean a = checkActive.isSelected();
276 boolean na = audioDeviceModel.isActive();
277 if(a != na) checkActive.setSelected(na);
278
279 AudioOutputDevice d = e.getAudioDeviceModel().getDeviceInfo();
280 updateParams(d);
281
282 int idx = cbChannel.getSelectedIndex();
283 cbChannel.removeAllItems();
284 for(AudioOutputChannel chn : d.getAudioChannels()) cbChannel.addItem(chn);
285
286 if(idx >= cbChannel.getModel().getSize()) idx = 0;
287
288 if(cbChannel.getModel().getSize() > 0) cbChannel.setSelectedIndex(idx);
289 }
290
291 public void
292 parameterChanged(ParameterEvent e) {
293 int c = cbChannel.getSelectedIndex();
294 if(c == -1) {
295 CC.getLogger().warning("There is no audio channel selected!");
296 return;
297 }
298
299 audioDeviceModel.setBackendChannelParameter(c, e.getParameter());
300 }
301
302 private void
303 updateParams(AudioOutputDevice d) {
304 Parameter[] params = d.getAdditionalParameters();
305 Parameter[] p2s = new Parameter[params.length + 1];
306
307 for(int i = 0; i < params.length; i++) p2s[i] = params[i];
308
309 p2s[params.length] = d.getSampleRateParameter();
310
311 additionalParamsTable.getModel().setParameters(p2s);
312 }
313 }
314
315 }

  ViewVC Help
Powered by ViewVC