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 javax.swing.BorderFactory; |
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.JCheckBox; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JScrollPane; |
41 |
import javax.swing.JSpinner; |
42 |
import javax.swing.SpinnerNumberModel; |
43 |
|
44 |
import javax.swing.event.ChangeEvent; |
45 |
import javax.swing.event.ChangeListener; |
46 |
|
47 |
import org.jsampler.AudioDeviceModel; |
48 |
import org.jsampler.CC; |
49 |
|
50 |
import org.jsampler.event.AudioDeviceEvent; |
51 |
import org.jsampler.event.AudioDeviceListener; |
52 |
import org.jsampler.event.ParameterEvent; |
53 |
import org.jsampler.event.ParameterListener; |
54 |
|
55 |
import org.jsampler.view.ParameterTable; |
56 |
|
57 |
import org.linuxsampler.lscp.AudioOutputChannel; |
58 |
import org.linuxsampler.lscp.AudioOutputDevice; |
59 |
import org.linuxsampler.lscp.Parameter; |
60 |
|
61 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
62 |
|
63 |
/** |
64 |
* |
65 |
* @author Grigor Iliev |
66 |
*/ |
67 |
public class AudioDevicePane extends DevicePane { |
68 |
private final OptionsPane optionsPane; |
69 |
private final ParameterTable channelParamTable = new ParameterTable(); |
70 |
|
71 |
private final AudioDeviceModel audioDeviceModel; |
72 |
|
73 |
|
74 |
/** Creates a new instance of <code>AudioDevicePane</code> */ |
75 |
public |
76 |
AudioDevicePane(AudioDeviceModel model) { |
77 |
audioDeviceModel = model; |
78 |
|
79 |
optionsPane = new OptionsPane(); |
80 |
setOptionsPane(optionsPane); |
81 |
|
82 |
int id = model.getDeviceId(); |
83 |
setDeviceName(i18n.getLabel("AudioDevicePane.lDevName", id)); |
84 |
} |
85 |
|
86 |
protected void |
87 |
destroyDevice() { |
88 |
CC.getSamplerModel().removeBackendAudioDevice(getDeviceId()); |
89 |
} |
90 |
|
91 |
public int |
92 |
getDeviceId() { return audioDeviceModel.getDeviceId(); } |
93 |
|
94 |
class OptionsPane extends PixmapPane implements ActionListener, ItemListener, |
95 |
ChangeListener, AudioDeviceListener, ParameterListener { |
96 |
|
97 |
private final JCheckBox checkActive = |
98 |
new JCheckBox(i18n.getLabel("AudioDevicePane.checkActive")); |
99 |
|
100 |
private final JLabel lChannels |
101 |
= new JLabel(i18n.getLabel("AudioDevicePane.lChannels")); |
102 |
|
103 |
private final JSpinner spinnerChannels |
104 |
= new JSpinner(new SpinnerNumberModel(1, 1, 50, 1)); |
105 |
|
106 |
private final JLabel lChannel = |
107 |
new JLabel(i18n.getLabel("AudioDevicePane.lChannel")); |
108 |
|
109 |
private final JComboBox cbChannel = new JComboBox(); |
110 |
|
111 |
OptionsPane() { |
112 |
super(Res.gfxChannelOptions); |
113 |
|
114 |
setAlignmentX(LEFT_ALIGNMENT); |
115 |
|
116 |
setPixmapInsets(new Insets(1, 1, 1, 1)); |
117 |
setLayout(new java.awt.BorderLayout()); |
118 |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
119 |
setOpaque(false); |
120 |
|
121 |
PixmapPane mainPane = new PixmapPane(Res.gfxRoundBg7); |
122 |
mainPane.setPixmapInsets(new Insets(3, 3, 3, 3)); |
123 |
mainPane.setOpaque(false); |
124 |
|
125 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
126 |
mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
127 |
mainPane.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
128 |
|
129 |
JPanel p = new JPanel(); |
130 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
131 |
|
132 |
p.add(checkActive); |
133 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
134 |
p.add(lChannels); |
135 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
136 |
p.add(spinnerChannels); |
137 |
p.setOpaque(false); |
138 |
|
139 |
mainPane.add(p); |
140 |
mainPane.add(Box.createRigidArea(new Dimension(0, 5))); |
141 |
|
142 |
mainPane.add(createHSeparator()); |
143 |
mainPane.add(Box.createRigidArea(new Dimension(0, 5))); |
144 |
|
145 |
p = new JPanel(); |
146 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
147 |
p.setOpaque(false); |
148 |
|
149 |
JPanel p2 = new JPanel(); |
150 |
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
151 |
p2.add(lChannel); |
152 |
p2.add(Box.createRigidArea(new Dimension(5, 0))); |
153 |
p2.add(cbChannel); |
154 |
p2.setOpaque(false); |
155 |
p.add(p2); |
156 |
|
157 |
p.add(Box.createRigidArea(new Dimension(0, 5))); |
158 |
|
159 |
JScrollPane sp = new JScrollPane(channelParamTable); |
160 |
sp.setPreferredSize(new Dimension(77, 90)); |
161 |
p.add(sp); |
162 |
|
163 |
mainPane.add(p); |
164 |
add(mainPane); |
165 |
|
166 |
checkActive.setSelected(audioDeviceModel.isActive()); |
167 |
spinnerChannels.setValue(audioDeviceModel.getDeviceInfo().getChannelCount()); |
168 |
|
169 |
cbChannel.addActionListener(this); |
170 |
checkActive.addItemListener(this); |
171 |
spinnerChannels.addChangeListener(this); |
172 |
audioDeviceModel.addAudioDeviceListener(this); |
173 |
channelParamTable.getModel().addParameterListener(this); |
174 |
|
175 |
AudioDeviceModel m = audioDeviceModel; |
176 |
for(AudioOutputChannel chn : m.getDeviceInfo().getAudioChannels()) { |
177 |
cbChannel.addItem(chn); |
178 |
} |
179 |
} |
180 |
|
181 |
public void |
182 |
actionPerformed(ActionEvent e) { |
183 |
Object obj = cbChannel.getSelectedItem(); |
184 |
if(obj == null) { |
185 |
channelParamTable.getModel().setParameters(new Parameter[0]); |
186 |
return; |
187 |
} |
188 |
|
189 |
AudioOutputChannel chn = (AudioOutputChannel)obj; |
190 |
|
191 |
channelParamTable.getModel().setParameters(chn.getAllParameters()); |
192 |
} |
193 |
|
194 |
public void |
195 |
itemStateChanged(ItemEvent e) { |
196 |
boolean a = checkActive.isSelected(); |
197 |
if(a != audioDeviceModel.isActive()) audioDeviceModel.setBackendActive(a); |
198 |
} |
199 |
|
200 |
public void |
201 |
stateChanged(ChangeEvent e) { |
202 |
int c = (Integer)spinnerChannels.getValue(); |
203 |
if(c != audioDeviceModel.getDeviceInfo().getAudioChannelCount()) { |
204 |
audioDeviceModel.setBackendChannelCount(c); |
205 |
} |
206 |
} |
207 |
|
208 |
public void |
209 |
settingsChanged(AudioDeviceEvent e) { |
210 |
int c = (Integer)spinnerChannels.getValue(); |
211 |
int nc = audioDeviceModel.getDeviceInfo().getAudioChannelCount(); |
212 |
if(c != nc) spinnerChannels.setValue(nc); |
213 |
|
214 |
boolean a = checkActive.isSelected(); |
215 |
boolean na = audioDeviceModel.isActive(); |
216 |
if(a != na) checkActive.setSelected(na); |
217 |
|
218 |
AudioOutputDevice d = e.getAudioDeviceModel().getDeviceInfo(); |
219 |
|
220 |
int idx = cbChannel.getSelectedIndex(); |
221 |
cbChannel.removeAllItems(); |
222 |
for(AudioOutputChannel chn : d.getAudioChannels()) cbChannel.addItem(chn); |
223 |
|
224 |
if(idx >= cbChannel.getModel().getSize()) idx = 0; |
225 |
|
226 |
if(cbChannel.getModel().getSize() > 0) cbChannel.setSelectedIndex(idx); |
227 |
} |
228 |
|
229 |
public void |
230 |
parameterChanged(ParameterEvent e) { |
231 |
int c = cbChannel.getSelectedIndex(); |
232 |
if(c == -1) { |
233 |
CC.getLogger().warning("There is no audio channel selected!"); |
234 |
return; |
235 |
} |
236 |
|
237 |
audioDeviceModel.setBackendChannelParameter(c, e.getParameter()); |
238 |
} |
239 |
} |
240 |
|
241 |
} |