/[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 1785 - (show annotations) (download)
Tue Oct 7 00:07:14 2008 UTC (15 years, 6 months ago) by iliev
File size: 9534 byte(s)
* Fantasia: Implemented multiple channels panels
* Fantasia: Refactoring - all basic UI components moved to
  org.jsampler.view.fantasia.basic package

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2008 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 import org.jsampler.view.fantasia.basic.PixmapPane;
66
67 import org.linuxsampler.lscp.MidiInputDevice;
68 import org.linuxsampler.lscp.MidiPort;
69 import org.linuxsampler.lscp.Parameter;
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
90 portParamTable.setFillsViewportHeight(true);
91
92 optionsPane = new OptionsPane();
93 setOptionsPane(optionsPane);
94
95 int id = model.getDeviceId();
96 String s = model.getDeviceInfo().getDriverName();
97 setDeviceName(i18n.getLabel("MidiDevicePane.lDevName", id, s));
98 }
99
100 @Override
101 protected void
102 destroyDevice() {
103 final Task t = new Midi.DestroyDevice(midiDeviceModel.getDeviceId());
104 t.addTaskListener(new TaskListener() {
105 public void
106 taskPerformed(TaskEvent e) {
107 if(t.doneWithErrors()) restoreDevice();
108 }
109 });
110
111 CC.getTaskQueue().add(t);
112 }
113
114 public int
115 getDeviceId() { return midiDeviceModel.getDeviceId(); }
116
117 class OptionsPane extends PixmapPane implements ActionListener, ItemListener,
118 ChangeListener, MidiDeviceListener, ParameterListener {
119
120 private final JCheckBox checkActive =
121 new JCheckBox(i18n.getLabel("MidiDevicePane.checkActive"));
122
123 private final JLabel lPorts = new JLabel(i18n.getLabel("MidiDevicePane.lPorts"));
124 private final JSpinner spinnerPorts;
125 private final JLabel lPort = new JLabel(i18n.getLabel("MidiDevicePane.lPort"));
126 private final JComboBox cbPort = new JComboBox();
127
128 private final ParameterTable additionalParamsTable = new ParameterTable();
129 private final JPanel additionalParamsPane = new JPanel();
130
131 OptionsPane() {
132 super(Res.gfxChannelOptions);
133
134 setAlignmentX(LEFT_ALIGNMENT);
135
136 setPixmapInsets(new Insets(1, 1, 1, 1));
137 setLayout(new java.awt.BorderLayout());
138 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
139 setOpaque(false);
140
141 PixmapPane mainPane = new PixmapPane(Res.gfxRoundBg7);
142 mainPane.setPixmapInsets(new Insets(3, 3, 3, 3));
143 mainPane.setOpaque(false);
144
145 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
146 mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
147 mainPane.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
148
149 JPanel p = new JPanel();
150 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
151
152 p.add(checkActive);
153 p.add(Box.createRigidArea(new Dimension(12, 0)));
154 p.add(lPorts);
155 p.add(Box.createRigidArea(new Dimension(5, 0)));
156
157 Parameter<Integer> prm = midiDeviceModel.getDeviceInfo().getPortsParameter();
158 int min = 1;
159 if(prm.getRangeMin() != null) min = prm.getRangeMin().intValue();
160 int max = 50;
161 if(prm.getRangeMax() != null) max = prm.getRangeMax().intValue();
162 spinnerPorts = new JSpinner(new SpinnerNumberModel(1, min, max, 1));
163 if(prm.isFixed()) spinnerPorts.setEnabled(false);
164
165 p.add(spinnerPorts);
166 p.setOpaque(false);
167
168 mainPane.add(p);
169 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
170
171 JPanel p2 = additionalParamsPane;
172 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
173 p2.setOpaque(false);
174
175 p2.add(createHSeparator());
176 p2.add(Box.createRigidArea(new Dimension(0, 5)));
177
178 JScrollPane sp = new JScrollPane(additionalParamsTable);
179
180 sp.setPreferredSize(new Dimension(77, 90));
181 p2.add(sp);
182 mainPane.add(p2);
183
184 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
185
186 mainPane.add(createHSeparator());
187 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
188
189 p = new JPanel();
190 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
191 p.setOpaque(false);
192
193 p2 = new JPanel();
194 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
195 p2.add(lPort);
196 p2.add(Box.createRigidArea(new Dimension(5, 0)));
197 p2.add(cbPort);
198 p2.setOpaque(false);
199 p.add(p2);
200
201 p.add(Box.createRigidArea(new Dimension(0, 5)));
202
203 sp = new JScrollPane(portParamTable);
204 sp.setPreferredSize(new Dimension(77, 90));
205 p.add(sp);
206
207 mainPane.add(p);
208 add(mainPane);
209
210 checkActive.setSelected(midiDeviceModel.isActive());
211 spinnerPorts.setValue(midiDeviceModel.getDeviceInfo().getMidiPortCount());
212
213 cbPort.addActionListener(this);
214 checkActive.addItemListener(this);
215 spinnerPorts.addChangeListener(this);
216 midiDeviceModel.addMidiDeviceListener(this);
217 portParamTable.getModel().addParameterListener(this);
218
219 for(MidiPort port : midiDeviceModel.getDeviceInfo().getMidiPorts()) {
220 cbPort.addItem(port);
221 }
222
223 Parameter[] pS = midiDeviceModel.getDeviceInfo().getAdditionalParameters();
224 additionalParamsTable.getModel().setParameters(pS);
225 additionalParamsTable.getModel().addParameterListener(new ParameterListener() {
226 public void
227 parameterChanged(ParameterEvent e) {
228 midiDeviceModel.setBackendDeviceParameter(e.getParameter());
229 }
230 });
231
232 updateAdditionalParamsViewState();
233 String s = "MidiDevice.showAdditionalParameters";
234 preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
235 public void
236 propertyChange(PropertyChangeEvent e) {
237 updateAdditionalParamsViewState();
238 }
239 });
240 }
241
242 private void
243 updateAdditionalParamsViewState() {
244 String s = "MidiDevice.showAdditionalParameters";
245 additionalParamsPane.setVisible(preferences().getBoolProperty(s));
246 validate();
247 }
248
249 @Override
250 public void
251 actionPerformed(ActionEvent e) {
252 Object obj = cbPort.getSelectedItem();
253 if(obj == null) {
254 portParamTable.getModel().setParameters(new Parameter[0]);
255 return;
256 }
257
258 MidiPort port = (MidiPort)obj;
259
260 portParamTable.getModel().setParameters(port.getAllParameters());
261 }
262
263 @Override
264 public void
265 itemStateChanged(ItemEvent e) {
266 boolean a = checkActive.isSelected();
267 if(a != midiDeviceModel.isActive()) midiDeviceModel.setBackendActive(a);
268 }
269
270 @Override
271 public void
272 stateChanged(ChangeEvent e) {
273 int p = (Integer)spinnerPorts.getValue();
274 if(p != midiDeviceModel.getDeviceInfo().getMidiPortCount()) {
275 midiDeviceModel.setBackendPortCount(p);
276 }
277 }
278
279 @Override
280 public void
281 settingsChanged(MidiDeviceEvent e) {
282 int p = (Integer)spinnerPorts.getValue();
283 int np = midiDeviceModel.getDeviceInfo().getMidiPortCount();
284 if(p != np) spinnerPorts.setValue(np);
285
286 boolean a = checkActive.isSelected();
287 boolean na = midiDeviceModel.isActive();
288 if(a != na) checkActive.setSelected(na);
289
290 MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
291
292 Parameter[] params = d.getAdditionalParameters();
293 additionalParamsTable.getModel().setParameters(params);
294
295 int idx = cbPort.getSelectedIndex();
296 cbPort.removeAllItems();
297 for(MidiPort port : d.getMidiPorts()) cbPort.addItem(port);
298
299 if(idx >= cbPort.getModel().getSize()) idx = 0;
300
301 if(cbPort.getModel().getSize() > 0) cbPort.setSelectedIndex(idx);
302 }
303
304 /** Invoked when when the value of a particular parameter is changed. */
305 @Override
306 public void
307 parameterChanged(ParameterEvent e) {
308 int port = cbPort.getSelectedIndex();
309 if(port == -1) {
310 CC.getLogger().warning("There is no MIDI port selected!");
311 return;
312 }
313
314 midiDeviceModel.setBackendPortParameter(port, e.getParameter());
315 }
316 }
317 }

  ViewVC Help
Powered by ViewVC