/[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 1357 - (show annotations) (download)
Sat Sep 22 17:27:06 2007 UTC (16 years, 7 months ago) by iliev
File size: 8981 byte(s)
* Added options for setting the maximum master and channel volume
  (choose Edit/Preferences)
* Fantasia: Edit instrument button is now shown on the channel
  screen only when there is loaded instrument on that channel
* Fantasia: Added options for showing additional device parameters in
  audio/MIDI device panes (Edit/Preferences, then click the `View' tab)
* Fantasia: Master volume is now fully implemented

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

  ViewVC Help
Powered by ViewVC