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

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/MidiDevicePane.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: 9083 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.CC;
55 import org.jsampler.MidiDeviceModel;
56
57 import org.jsampler.event.MidiDeviceEvent;
58 import org.jsampler.event.MidiDeviceListener;
59 import org.jsampler.event.ParameterEvent;
60 import org.jsampler.event.ParameterListener;
61
62 import org.jsampler.task.Midi;
63
64 import org.jsampler.view.ParameterTable;
65
66 import org.linuxsampler.lscp.MidiInputDevice;
67 import org.linuxsampler.lscp.MidiPort;
68 import org.linuxsampler.lscp.Parameter;
69 import org.linuxsampler.lscp.ParameterFactory;
70
71 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
72 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
73
74
75 /**
76 *
77 * @author Grigor Iliev
78 */
79 public class MidiDevicePane extends DevicePane {
80 private final OptionsPane optionsPane;
81 private final ParameterTable portParamTable = new ParameterTable();
82
83 private MidiDeviceModel midiDeviceModel;
84
85 /** Creates a new instance of <code>MidiDevicePane</code> */
86 public
87 MidiDevicePane(MidiDeviceModel model) {
88 midiDeviceModel = model;
89 optionsPane = new OptionsPane();
90 setOptionsPane(optionsPane);
91
92 int id = model.getDeviceId();
93 String s = model.getDeviceInfo().getDriverName();
94 setDeviceName(i18n.getLabel("MidiDevicePane.lDevName", id, s));
95 }
96
97 protected void
98 destroyDevice() {
99 final Task t = new Midi.DestroyDevice(midiDeviceModel.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 midiDeviceModel.getDeviceId(); }
112
113 class OptionsPane extends PixmapPane implements ActionListener, ItemListener,
114 ChangeListener, MidiDeviceListener, ParameterListener {
115
116 private final JCheckBox checkActive =
117 new JCheckBox(i18n.getLabel("MidiDevicePane.checkActive"));
118
119 private final JLabel lPorts = new JLabel(i18n.getLabel("MidiDevicePane.lPorts"));
120
121 private final JSpinner spinnerPorts
122 = new JSpinner(new SpinnerNumberModel(1, 1, 100, 1));
123
124 private final JLabel lPort = new JLabel(i18n.getLabel("MidiDevicePane.lPort"));
125 private final JComboBox cbPort = new JComboBox();
126
127 private final ParameterTable additionalParamsTable = new ParameterTable();
128 private final JPanel additionalParamsPane = new JPanel();
129
130 OptionsPane() {
131 super(Res.gfxChannelOptions);
132
133 setAlignmentX(LEFT_ALIGNMENT);
134
135 setPixmapInsets(new Insets(1, 1, 1, 1));
136 setLayout(new java.awt.BorderLayout());
137 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
138 setOpaque(false);
139
140 PixmapPane mainPane = new PixmapPane(Res.gfxRoundBg7);
141 mainPane.setPixmapInsets(new Insets(3, 3, 3, 3));
142 mainPane.setOpaque(false);
143
144 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
145 mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
146 mainPane.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
147
148 JPanel p = new JPanel();
149 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
150
151 p.add(checkActive);
152 p.add(Box.createRigidArea(new Dimension(12, 0)));
153 p.add(lPorts);
154 p.add(Box.createRigidArea(new Dimension(5, 0)));
155 p.add(spinnerPorts);
156 p.setOpaque(false);
157
158 mainPane.add(p);
159 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
160
161 JPanel p2 = additionalParamsPane;
162 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
163 p2.setOpaque(false);
164
165 p2.add(createHSeparator());
166 p2.add(Box.createRigidArea(new Dimension(0, 5)));
167
168 JScrollPane sp = new JScrollPane(additionalParamsTable);
169
170 sp.setPreferredSize(new Dimension(77, 90));
171 p2.add(sp);
172 mainPane.add(p2);
173
174 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
175
176 mainPane.add(createHSeparator());
177 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
178
179 p = new JPanel();
180 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
181 p.setOpaque(false);
182
183 p2 = new JPanel();
184 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
185 p2.add(lPort);
186 p2.add(Box.createRigidArea(new Dimension(5, 0)));
187 p2.add(cbPort);
188 p2.setOpaque(false);
189 p.add(p2);
190
191 p.add(Box.createRigidArea(new Dimension(0, 5)));
192
193 sp = new JScrollPane(portParamTable);
194 sp.setPreferredSize(new Dimension(77, 90));
195 p.add(sp);
196
197 mainPane.add(p);
198 add(mainPane);
199
200 checkActive.setSelected(midiDeviceModel.isActive());
201 spinnerPorts.setValue(midiDeviceModel.getDeviceInfo().getMidiPortCount());
202
203 cbPort.addActionListener(this);
204 checkActive.addItemListener(this);
205 spinnerPorts.addChangeListener(this);
206 midiDeviceModel.addMidiDeviceListener(this);
207 portParamTable.getModel().addParameterListener(this);
208
209 for(MidiPort port : midiDeviceModel.getDeviceInfo().getMidiPorts()) {
210 cbPort.addItem(port);
211 }
212
213 Parameter[] pS = midiDeviceModel.getDeviceInfo().getAdditionalParameters();
214 additionalParamsTable.getModel().setParameters(pS);
215 additionalParamsTable.getModel().addParameterListener(new ParameterListener() {
216 public void
217 parameterChanged(ParameterEvent e) {
218 midiDeviceModel.setBackendDeviceParameter(e.getParameter());
219 }
220 });
221
222 updateAdditionalParamsViewState();
223 String s = "MidiDevice.showAdditionalParameters";
224 preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
225 public void
226 propertyChange(PropertyChangeEvent e) {
227 updateAdditionalParamsViewState();
228 }
229 });
230 }
231
232 private void
233 updateAdditionalParamsViewState() {
234 String s = "MidiDevice.showAdditionalParameters";
235 additionalParamsPane.setVisible(preferences().getBoolProperty(s));
236 validate();
237 }
238
239 public void
240 actionPerformed(ActionEvent e) {
241 Object obj = cbPort.getSelectedItem();
242 if(obj == null) {
243 portParamTable.getModel().setParameters(new Parameter[0]);
244 return;
245 }
246
247 MidiPort port = (MidiPort)obj;
248
249 portParamTable.getModel().setParameters(port.getAllParameters());
250 }
251
252 public void
253 itemStateChanged(ItemEvent e) {
254 boolean a = checkActive.isSelected();
255 if(a != midiDeviceModel.isActive()) midiDeviceModel.setBackendActive(a);
256 }
257
258 public void
259 stateChanged(ChangeEvent e) {
260 int p = (Integer)spinnerPorts.getValue();
261 if(p != midiDeviceModel.getDeviceInfo().getMidiPortCount()) {
262 midiDeviceModel.setBackendPortCount(p);
263 }
264 }
265
266 public void
267 settingsChanged(MidiDeviceEvent e) {
268 int p = (Integer)spinnerPorts.getValue();
269 int np = midiDeviceModel.getDeviceInfo().getMidiPortCount();
270 if(p != np) spinnerPorts.setValue(np);
271
272 boolean a = checkActive.isSelected();
273 boolean na = midiDeviceModel.isActive();
274 if(a != na) checkActive.setSelected(na);
275
276 MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
277
278 Parameter[] params = d.getAdditionalParameters();
279 additionalParamsTable.getModel().setParameters(params);
280
281 int idx = cbPort.getSelectedIndex();
282 cbPort.removeAllItems();
283 for(MidiPort port : d.getMidiPorts()) cbPort.addItem(port);
284
285 if(idx >= cbPort.getModel().getSize()) idx = 0;
286
287 if(cbPort.getModel().getSize() > 0) cbPort.setSelectedIndex(idx);
288 }
289
290 /** Invoked when when the value of a particular parameter is changed. */
291 public void
292 parameterChanged(ParameterEvent e) {
293 int port = cbPort.getSelectedIndex();
294 if(port == -1) {
295 CC.getLogger().warning("There is no MIDI port selected!");
296 return;
297 }
298
299 midiDeviceModel.setBackendPortParameter(port, e.getParameter());
300 }
301 }
302 }

  ViewVC Help
Powered by ViewVC