/[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 1743 - (show annotations) (download)
Sat May 31 23:04:01 2008 UTC (15 years, 10 months ago) by iliev
File size: 9458 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 /*
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
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
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 protected void
101 destroyDevice() {
102 final Task t = new Midi.DestroyDevice(midiDeviceModel.getDeviceId());
103 t.addTaskListener(new TaskListener() {
104 public void
105 taskPerformed(TaskEvent e) {
106 if(t.doneWithErrors()) restoreDevice();
107 }
108 });
109
110 CC.getTaskQueue().add(t);
111 }
112
113 public int
114 getDeviceId() { return midiDeviceModel.getDeviceId(); }
115
116 class OptionsPane extends PixmapPane implements ActionListener, ItemListener,
117 ChangeListener, MidiDeviceListener, ParameterListener {
118
119 private final JCheckBox checkActive =
120 new JCheckBox(i18n.getLabel("MidiDevicePane.checkActive"));
121
122 private final JLabel lPorts = new JLabel(i18n.getLabel("MidiDevicePane.lPorts"));
123 private final JSpinner spinnerPorts;
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
156 Parameter<Integer> prm = midiDeviceModel.getDeviceInfo().getPortsParameter();
157 int min = 1;
158 if(prm.getRangeMin() != null) min = prm.getRangeMin().intValue();
159 int max = 50;
160 if(prm.getRangeMax() != null) max = prm.getRangeMax().intValue();
161 spinnerPorts = new JSpinner(new SpinnerNumberModel(1, min, max, 1));
162 if(prm.isFixed()) spinnerPorts.setEnabled(false);
163
164 p.add(spinnerPorts);
165 p.setOpaque(false);
166
167 mainPane.add(p);
168 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
169
170 JPanel p2 = additionalParamsPane;
171 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
172 p2.setOpaque(false);
173
174 p2.add(createHSeparator());
175 p2.add(Box.createRigidArea(new Dimension(0, 5)));
176
177 JScrollPane sp = new JScrollPane(additionalParamsTable);
178
179 sp.setPreferredSize(new Dimension(77, 90));
180 p2.add(sp);
181 mainPane.add(p2);
182
183 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
184
185 mainPane.add(createHSeparator());
186 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
187
188 p = new JPanel();
189 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
190 p.setOpaque(false);
191
192 p2 = new JPanel();
193 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
194 p2.add(lPort);
195 p2.add(Box.createRigidArea(new Dimension(5, 0)));
196 p2.add(cbPort);
197 p2.setOpaque(false);
198 p.add(p2);
199
200 p.add(Box.createRigidArea(new Dimension(0, 5)));
201
202 sp = new JScrollPane(portParamTable);
203 sp.setPreferredSize(new Dimension(77, 90));
204 p.add(sp);
205
206 mainPane.add(p);
207 add(mainPane);
208
209 checkActive.setSelected(midiDeviceModel.isActive());
210 spinnerPorts.setValue(midiDeviceModel.getDeviceInfo().getMidiPortCount());
211
212 cbPort.addActionListener(this);
213 checkActive.addItemListener(this);
214 spinnerPorts.addChangeListener(this);
215 midiDeviceModel.addMidiDeviceListener(this);
216 portParamTable.getModel().addParameterListener(this);
217
218 for(MidiPort port : midiDeviceModel.getDeviceInfo().getMidiPorts()) {
219 cbPort.addItem(port);
220 }
221
222 Parameter[] pS = midiDeviceModel.getDeviceInfo().getAdditionalParameters();
223 additionalParamsTable.getModel().setParameters(pS);
224 additionalParamsTable.getModel().addParameterListener(new ParameterListener() {
225 public void
226 parameterChanged(ParameterEvent e) {
227 midiDeviceModel.setBackendDeviceParameter(e.getParameter());
228 }
229 });
230
231 updateAdditionalParamsViewState();
232 String s = "MidiDevice.showAdditionalParameters";
233 preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
234 public void
235 propertyChange(PropertyChangeEvent e) {
236 updateAdditionalParamsViewState();
237 }
238 });
239 }
240
241 private void
242 updateAdditionalParamsViewState() {
243 String s = "MidiDevice.showAdditionalParameters";
244 additionalParamsPane.setVisible(preferences().getBoolProperty(s));
245 validate();
246 }
247
248 public void
249 actionPerformed(ActionEvent e) {
250 Object obj = cbPort.getSelectedItem();
251 if(obj == null) {
252 portParamTable.getModel().setParameters(new Parameter[0]);
253 return;
254 }
255
256 MidiPort port = (MidiPort)obj;
257
258 portParamTable.getModel().setParameters(port.getAllParameters());
259 }
260
261 public void
262 itemStateChanged(ItemEvent e) {
263 boolean a = checkActive.isSelected();
264 if(a != midiDeviceModel.isActive()) midiDeviceModel.setBackendActive(a);
265 }
266
267 public void
268 stateChanged(ChangeEvent e) {
269 int p = (Integer)spinnerPorts.getValue();
270 if(p != midiDeviceModel.getDeviceInfo().getMidiPortCount()) {
271 midiDeviceModel.setBackendPortCount(p);
272 }
273 }
274
275 public void
276 settingsChanged(MidiDeviceEvent e) {
277 int p = (Integer)spinnerPorts.getValue();
278 int np = midiDeviceModel.getDeviceInfo().getMidiPortCount();
279 if(p != np) spinnerPorts.setValue(np);
280
281 boolean a = checkActive.isSelected();
282 boolean na = midiDeviceModel.isActive();
283 if(a != na) checkActive.setSelected(na);
284
285 MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
286
287 Parameter[] params = d.getAdditionalParameters();
288 additionalParamsTable.getModel().setParameters(params);
289
290 int idx = cbPort.getSelectedIndex();
291 cbPort.removeAllItems();
292 for(MidiPort port : d.getMidiPorts()) cbPort.addItem(port);
293
294 if(idx >= cbPort.getModel().getSize()) idx = 0;
295
296 if(cbPort.getModel().getSize() > 0) cbPort.setSelectedIndex(idx);
297 }
298
299 /** Invoked when when the value of a particular parameter is changed. */
300 public void
301 parameterChanged(ParameterEvent e) {
302 int port = cbPort.getSelectedIndex();
303 if(port == -1) {
304 CC.getLogger().warning("There is no MIDI port selected!");
305 return;
306 }
307
308 midiDeviceModel.setBackendPortParameter(port, e.getParameter());
309 }
310 }
311 }

  ViewVC Help
Powered by ViewVC