/[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 1286 - (show annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 8 months ago) by iliev
File size: 7333 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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 net.sf.juife.Task;
48 import net.sf.juife.event.TaskEvent;
49 import net.sf.juife.event.TaskListener;
50
51 import org.jsampler.CC;
52 import org.jsampler.MidiDeviceModel;
53
54 import org.jsampler.event.MidiDeviceEvent;
55 import org.jsampler.event.MidiDeviceListener;
56 import org.jsampler.event.ParameterEvent;
57 import org.jsampler.event.ParameterListener;
58
59 import org.jsampler.task.Midi;
60
61 import org.jsampler.view.ParameterTable;
62
63 import org.linuxsampler.lscp.MidiInputDevice;
64 import org.linuxsampler.lscp.MidiPort;
65 import org.linuxsampler.lscp.Parameter;
66
67 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
68
69
70 /**
71 *
72 * @author Grigor Iliev
73 */
74 public class MidiDevicePane extends DevicePane {
75 private final OptionsPane optionsPane;
76 private final ParameterTable portParamTable = new ParameterTable();
77
78 private MidiDeviceModel midiDeviceModel;
79
80 /** Creates a new instance of <code>MidiDevicePane</code> */
81 public
82 MidiDevicePane(MidiDeviceModel model) {
83 midiDeviceModel = model;
84 optionsPane = new OptionsPane();
85 setOptionsPane(optionsPane);
86
87 int id = model.getDeviceId();
88 setDeviceName(i18n.getLabel("MidiDevicePane.lDevName", id));
89 }
90
91 protected void
92 destroyDevice() {
93 final Task t = new Midi.DestroyDevice(midiDeviceModel.getDeviceId());
94 t.addTaskListener(new TaskListener() {
95 public void
96 taskPerformed(TaskEvent e) {
97 if(t.doneWithErrors()) restoreDevice();
98 }
99 });
100
101 CC.getTaskQueue().add(t);
102 }
103
104 public int
105 getDeviceId() { return midiDeviceModel.getDeviceId(); }
106
107 class OptionsPane extends PixmapPane implements ActionListener, ItemListener,
108 ChangeListener, MidiDeviceListener, ParameterListener {
109
110 private final JCheckBox checkActive =
111 new JCheckBox(i18n.getLabel("MidiDevicePane.checkActive"));
112
113 private final JLabel lPorts = new JLabel(i18n.getLabel("MidiDevicePane.lPorts"));
114
115 private final JSpinner spinnerPorts
116 = new JSpinner(new SpinnerNumberModel(1, 1, 100, 1));
117
118 private final JLabel lPort = new JLabel(i18n.getLabel("MidiDevicePane.lPort"));
119 private final JComboBox cbPort = new JComboBox();
120
121 OptionsPane() {
122 super(Res.gfxChannelOptions);
123
124 setAlignmentX(LEFT_ALIGNMENT);
125
126 setPixmapInsets(new Insets(1, 1, 1, 1));
127 setLayout(new java.awt.BorderLayout());
128 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
129 setOpaque(false);
130
131 PixmapPane mainPane = new PixmapPane(Res.gfxRoundBg7);
132 mainPane.setPixmapInsets(new Insets(3, 3, 3, 3));
133 mainPane.setOpaque(false);
134
135 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
136 mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
137 mainPane.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
138
139 JPanel p = new JPanel();
140 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
141
142 p.add(checkActive);
143 p.add(Box.createRigidArea(new Dimension(12, 0)));
144 p.add(lPorts);
145 p.add(Box.createRigidArea(new Dimension(5, 0)));
146 p.add(spinnerPorts);
147 p.setOpaque(false);
148
149 mainPane.add(p);
150 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
151
152 mainPane.add(createHSeparator());
153 mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
154
155 p = new JPanel();
156 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
157 p.setOpaque(false);
158
159 JPanel p2 = new JPanel();
160 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
161 p2.add(lPort);
162 p2.add(Box.createRigidArea(new Dimension(5, 0)));
163 p2.add(cbPort);
164 p2.setOpaque(false);
165 p.add(p2);
166
167 p.add(Box.createRigidArea(new Dimension(0, 5)));
168
169 JScrollPane sp = new JScrollPane(portParamTable);
170 sp.setPreferredSize(new Dimension(77, 90));
171 p.add(sp);
172
173 mainPane.add(p);
174 add(mainPane);
175
176 checkActive.setSelected(midiDeviceModel.isActive());
177 spinnerPorts.setValue(midiDeviceModel.getDeviceInfo().getMidiPortCount());
178
179 cbPort.addActionListener(this);
180 checkActive.addItemListener(this);
181 spinnerPorts.addChangeListener(this);
182 midiDeviceModel.addMidiDeviceListener(this);
183 portParamTable.getModel().addParameterListener(this);
184
185 for(MidiPort port : midiDeviceModel.getDeviceInfo().getMidiPorts()) {
186 cbPort.addItem(port);
187 }
188 }
189
190 public void
191 actionPerformed(ActionEvent e) {
192 Object obj = cbPort.getSelectedItem();
193 if(obj == null) {
194 portParamTable.getModel().setParameters(new Parameter[0]);
195 return;
196 }
197
198 MidiPort port = (MidiPort)obj;
199
200 portParamTable.getModel().setParameters(port.getAllParameters());
201 }
202
203 public void
204 itemStateChanged(ItemEvent e) {
205 boolean a = checkActive.isSelected();
206 if(a != midiDeviceModel.isActive()) midiDeviceModel.setBackendActive(a);
207 }
208
209 public void
210 stateChanged(ChangeEvent e) {
211 int p = (Integer)spinnerPorts.getValue();
212 if(p != midiDeviceModel.getDeviceInfo().getMidiPortCount()) {
213 midiDeviceModel.setBackendPortCount(p);
214 }
215 }
216
217 public void
218 settingsChanged(MidiDeviceEvent e) {
219 int p = (Integer)spinnerPorts.getValue();
220 int np = midiDeviceModel.getDeviceInfo().getMidiPortCount();
221 if(p != np) spinnerPorts.setValue(np);
222
223 boolean a = checkActive.isSelected();
224 boolean na = midiDeviceModel.isActive();
225 if(a != na) checkActive.setSelected(na);
226
227 MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
228
229 int idx = cbPort.getSelectedIndex();
230 cbPort.removeAllItems();
231 for(MidiPort port : d.getMidiPorts()) cbPort.addItem(port);
232
233 if(idx >= cbPort.getModel().getSize()) idx = 0;
234
235 if(cbPort.getModel().getSize() > 0) cbPort.setSelectedIndex(idx);
236 }
237
238 /** Invoked when when the value of a particular parameter is changed. */
239 public void
240 parameterChanged(ParameterEvent e) {
241 int port = cbPort.getSelectedIndex();
242 if(port == -1) {
243 CC.getLogger().warning("There is no MIDI port selected!");
244 return;
245 }
246
247 midiDeviceModel.setBackendPortParameter(port, e.getParameter());
248 }
249 }
250 }

  ViewVC Help
Powered by ViewVC