1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005 Grigor Kirilov Iliev |
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.classic; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.GridBagLayout; |
28 |
import java.awt.Insets; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
|
33 |
import javax.swing.BorderFactory; |
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JFileChooser; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JRadioButton; |
42 |
import javax.swing.ButtonGroup; |
43 |
import javax.swing.JSpinner; |
44 |
import javax.swing.JTextField; |
45 |
import javax.swing.SpinnerNumberModel; |
46 |
|
47 |
import net.sf.juife.JuifeUtils; |
48 |
import net.sf.juife.Wizard; |
49 |
|
50 |
import net.sf.juife.event.TaskEvent; |
51 |
import net.sf.juife.event.TaskListener; |
52 |
|
53 |
import net.sf.juife.wizard.DefaultWizardModel; |
54 |
import net.sf.juife.wizard.UserInputPage; |
55 |
import net.sf.juife.wizard.WizardPage; |
56 |
|
57 |
import org.jsampler.AudioDeviceModel; |
58 |
import org.jsampler.CC; |
59 |
import org.jsampler.HF; |
60 |
import org.jsampler.MidiDeviceModel; |
61 |
|
62 |
import org.jsampler.event.AudioDeviceListEvent; |
63 |
import org.jsampler.event.AudioDeviceListListener; |
64 |
import org.jsampler.event.MidiDeviceListEvent; |
65 |
import org.jsampler.event.MidiDeviceListListener; |
66 |
|
67 |
import org.jsampler.task.AddChannel; |
68 |
import org.jsampler.task.LoadEngine; |
69 |
import org.jsampler.task.LoadInstrument; |
70 |
import org.jsampler.task.SetChannelAudioOutputDevice; |
71 |
import org.jsampler.task.SetChannelMidiInputChannel; |
72 |
import org.jsampler.task.SetChannelMidiInputDevice; |
73 |
import org.jsampler.task.SetChannelMidiInputPort; |
74 |
|
75 |
import org.linuxsampler.lscp.AudioOutputDevice; |
76 |
import org.linuxsampler.lscp.MidiInputDevice; |
77 |
import org.linuxsampler.lscp.MidiPort; |
78 |
import org.linuxsampler.lscp.SamplerEngine; |
79 |
|
80 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
81 |
|
82 |
|
83 |
/** |
84 |
* |
85 |
* @author Grigor Iliev |
86 |
*/ |
87 |
public class NewChannelWizard extends Wizard { |
88 |
|
89 |
/** Creates a new instance of <code>NewChannelWizard</code>. */ |
90 |
public |
91 |
NewChannelWizard() { |
92 |
super(CC.getMainFrame(), i18n.getLabel("NewChannelWizard.title")); |
93 |
|
94 |
setModel(new NewChannelWizardModel()); |
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
class NewChannelWizardModel extends DefaultWizardModel { |
100 |
private final MidiDeviceWizardPage midiDevicePage = new MidiDeviceWizardPage(); |
101 |
private final MidiPortWizardPage midiPortPage = new MidiPortWizardPage(); |
102 |
private final MidiChannelWizardPage midiChannelPage = new MidiChannelWizardPage(); |
103 |
private final AudioDeviceWizardPage audioDevicePage = new AudioDeviceWizardPage(); |
104 |
private final EngineWizardPage enginePage = new EngineWizardPage(); |
105 |
private final InstrumentWizardPage instrumentPage = new InstrumentWizardPage(); |
106 |
private final ConfirmationWizardPage confirmationPage = new ConfirmationWizardPage(); |
107 |
|
108 |
NewChannelWizardModel() { |
109 |
addPage(midiDevicePage); |
110 |
addPage(midiPortPage); |
111 |
addPage(midiChannelPage); |
112 |
addStep(i18n.getLabel("NewChannelWizard.step1"), 3); |
113 |
|
114 |
addPage(audioDevicePage); |
115 |
addStep(i18n.getLabel("NewChannelWizard.step2")); |
116 |
|
117 |
addPage(enginePage); |
118 |
addStep(i18n.getLabel("NewChannelWizard.step3")); |
119 |
|
120 |
addPage(instrumentPage); |
121 |
addStep(i18n.getLabel("NewChannelWizard.step4")); |
122 |
|
123 |
addPage(confirmationPage); |
124 |
addStep(i18n.getLabel("NewChannelWizard.step5")); |
125 |
|
126 |
setLast(confirmationPage); |
127 |
} |
128 |
|
129 |
/** |
130 |
* Moves to the next page in the wizard. |
131 |
* @return The next page in the wizard. |
132 |
*/ |
133 |
public WizardPage |
134 |
next() { |
135 |
if(getCurrentPage() == midiDevicePage && !midiDevicePage.getCustomSettings()) { |
136 |
super.next(); super.next(); |
137 |
} |
138 |
|
139 |
return super.next(); |
140 |
} |
141 |
|
142 |
/** |
143 |
* Moves to the previous page in the wizard. |
144 |
* @return The previous page in the wizard. |
145 |
* @see #hasPrevious |
146 |
*/ |
147 |
public WizardPage |
148 |
previous() { |
149 |
if(getCurrentPage() == audioDevicePage && !midiDevicePage.getCustomSettings()) { |
150 |
super.previous(); super.previous(); |
151 |
} |
152 |
|
153 |
return super.previous(); |
154 |
} |
155 |
|
156 |
/** |
157 |
* Gets the selected MIDI device. |
158 |
* @return The selected MIDI device or <code>null</code> |
159 |
* if there is no MIDI device selected. |
160 |
*/ |
161 |
public MidiInputDevice |
162 |
getSelectedMidiDevice() { return midiDevicePage.getSelectedDevice(); } |
163 |
|
164 |
/** |
165 |
* Determines whether the user chooses to specify custom MIDI device settings. |
166 |
* @return <code>true</code> if the user chooses to specify custom MIDI device settings, |
167 |
* <code>false</code> otherwise. |
168 |
*/ |
169 |
public boolean |
170 |
getCustomMidiSettings() { return midiDevicePage.getCustomSettings(); } |
171 |
|
172 |
/** |
173 |
* Gets the selected MIDI input port. |
174 |
* @return The selected MIDI input port. |
175 |
*/ |
176 |
public MidiPort |
177 |
getSelectedMidiPort() { return midiPortPage.getSelectedPort(); } |
178 |
|
179 |
/** |
180 |
* Gets the selected MIDI channel. |
181 |
* @return The number of the selected MIDI channel or -1 which means all channels. |
182 |
*/ |
183 |
public int |
184 |
getSelectedMidiChannel() { return midiChannelPage.getSelectedChannel(); } |
185 |
|
186 |
/** |
187 |
* Gets the selected audio device. |
188 |
* @return The selected audio device or <code>null</code> if there is no device selected. |
189 |
*/ |
190 |
public AudioOutputDevice |
191 |
getSelectedAudioDevice() { return audioDevicePage.getSelectedDevice(); } |
192 |
|
193 |
/** |
194 |
* Gets the selected sampler engine to be used. |
195 |
* @return The selected sampler engine to be used. |
196 |
*/ |
197 |
public SamplerEngine |
198 |
getSelectedEngine() { return enginePage.getSelectedEngine(); } |
199 |
|
200 |
/** |
201 |
* Gets the name of the selected instrument file. |
202 |
* @return The name of the selected instrument file. |
203 |
*/ |
204 |
public String |
205 |
getSelectedFile() { return instrumentPage.getSelectedFile(); } |
206 |
|
207 |
/** |
208 |
* Gets the index of the instrument in the instrument file. |
209 |
* @return The index of the instrument in the instrument file. |
210 |
*/ |
211 |
public int |
212 |
getInstrumentIndex() { return instrumentPage.getInstrumentIndex(); } |
213 |
} |
214 |
|
215 |
class MidiDeviceWizardPage extends UserInputPage { |
216 |
private final JLabel lDevice = new JLabel(i18n.getLabel("MidiDeviceWizardPage.lDevice")); |
217 |
private final JComboBox cbDevices = new JComboBox(); |
218 |
private final JButton btnNewDevice = |
219 |
new JButton(i18n.getButtonLabel("MidiDeviceWizardPage.btnNewDevice")); |
220 |
private final JRadioButton rbDefaultSettings = |
221 |
new JRadioButton(i18n.getButtonLabel("MidiDeviceWizardPage.rbDefaultSettings")); |
222 |
private final JRadioButton rbCustomSettings = |
223 |
new JRadioButton(i18n.getButtonLabel("MidiDeviceWizardPage.rbCustomSettings")); |
224 |
|
225 |
MidiDeviceWizardPage() { |
226 |
super(i18n.getLabel("MidiDeviceWizardPage.subtitle")); |
227 |
|
228 |
setMainInstructions(i18n.getLabel("MidiDeviceWizardPage.mainInstructions")); |
229 |
|
230 |
JPanel p = new JPanel(); |
231 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
232 |
|
233 |
p.add(lDevice); |
234 |
|
235 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
236 |
|
237 |
for(MidiDeviceModel m : CC.getSamplerModel().getMidiDeviceModels()) { |
238 |
cbDevices.addItem(m.getDeviceInfo()); |
239 |
} |
240 |
|
241 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
242 |
if(cbDevices.getItemCount() == 0) enableDevComp(false); |
243 |
|
244 |
p.add(cbDevices); |
245 |
|
246 |
CC.getSamplerModel().addMidiDeviceListListener(getHandler()); |
247 |
|
248 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
249 |
p.add(btnNewDevice); |
250 |
p.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
251 |
|
252 |
JPanel mainPane = new JPanel(); |
253 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
254 |
mainPane.add(p); |
255 |
|
256 |
mainPane.add(Box.createRigidArea(new Dimension(0, 6))); |
257 |
|
258 |
rbDefaultSettings.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
259 |
mainPane.add(rbDefaultSettings); |
260 |
rbCustomSettings.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
261 |
mainPane.add(rbCustomSettings); |
262 |
|
263 |
ButtonGroup btnGroup = new ButtonGroup(); |
264 |
btnGroup.add(rbDefaultSettings); |
265 |
btnGroup.add(rbCustomSettings); |
266 |
rbDefaultSettings.setSelected(true); |
267 |
|
268 |
setMainPane(mainPane); |
269 |
|
270 |
btnNewDevice.addActionListener(new ActionListener() { |
271 |
public void |
272 |
actionPerformed(ActionEvent e) { |
273 |
new NewMidiDeviceDlg(getWizardDialog()).setVisible(true); |
274 |
} |
275 |
}); |
276 |
} |
277 |
|
278 |
/** |
279 |
* Gets the selected device. |
280 |
* @return The selected device or <code>null</code> if there is no device selected. |
281 |
*/ |
282 |
public MidiInputDevice |
283 |
getSelectedDevice() { return (MidiInputDevice)cbDevices.getSelectedItem(); } |
284 |
|
285 |
private void |
286 |
enableDevComp(boolean b) { |
287 |
cbDevices.setEnabled(b); |
288 |
rbDefaultSettings.setEnabled(b); |
289 |
rbCustomSettings.setEnabled(b); |
290 |
} |
291 |
|
292 |
/** |
293 |
* Determines whether the user chooses to specify custom device settings. |
294 |
* @return <code>true</code> if the user chooses to specify custom device settings, |
295 |
* <code>false</code> otherwise. |
296 |
*/ |
297 |
public boolean |
298 |
getCustomSettings() { return rbCustomSettings.isSelected(); } |
299 |
|
300 |
private final Handler handler = new Handler(); |
301 |
|
302 |
private Handler |
303 |
getHandler() { return handler; } |
304 |
|
305 |
private class Handler implements MidiDeviceListListener { |
306 |
public void |
307 |
deviceAdded(MidiDeviceListEvent e) { |
308 |
updateDeviceList(e.getMidiDeviceModel().getDeviceInfo()); |
309 |
} |
310 |
|
311 |
public void |
312 |
deviceRemoved(MidiDeviceListEvent e) { updateDeviceList(null); } |
313 |
|
314 |
private void |
315 |
updateDeviceList(MidiInputDevice dev) { |
316 |
cbDevices.removeAllItems(); |
317 |
|
318 |
for(MidiDeviceModel m : CC.getSamplerModel().getMidiDeviceModels()) { |
319 |
cbDevices.addItem(m.getDeviceInfo()); |
320 |
} |
321 |
|
322 |
if(cbDevices.getItemCount() == 0) enableDevComp(false); |
323 |
else { |
324 |
enableDevComp(true); |
325 |
cbDevices.setSelectedItem(dev); |
326 |
} |
327 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
328 |
} |
329 |
} |
330 |
} |
331 |
|
332 |
class MidiPortWizardPage extends UserInputPage { |
333 |
private final JLabel lPort = new JLabel(i18n.getLabel("MidiPortWizardPage.lPort")); |
334 |
private final JComboBox cbPorts = new JComboBox(); |
335 |
|
336 |
MidiPortWizardPage() { |
337 |
super(i18n.getLabel("MidiPortWizardPage.subtitle")); |
338 |
|
339 |
setMainInstructions(i18n.getLabel("MidiPortWizardPage.mainInstructions")); |
340 |
|
341 |
JPanel p = new JPanel(); |
342 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
343 |
|
344 |
p.add(lPort); |
345 |
|
346 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
347 |
|
348 |
cbPorts.setMaximumSize(cbPorts.getPreferredSize()); |
349 |
|
350 |
p.add(cbPorts); |
351 |
|
352 |
setMainPane(p); |
353 |
} |
354 |
|
355 |
public void |
356 |
initPage() { |
357 |
updatePorts(((NewChannelWizardModel)getWizardModel()).getSelectedMidiDevice()); |
358 |
} |
359 |
|
360 |
/** |
361 |
* Gets the selected MIDI input port. |
362 |
* @return The selected MIDI input port. |
363 |
*/ |
364 |
public MidiPort |
365 |
getSelectedPort() { return (MidiPort)cbPorts.getSelectedItem(); } |
366 |
|
367 |
public void |
368 |
updatePorts(MidiInputDevice dev) { |
369 |
Object current = cbPorts.getSelectedItem(); |
370 |
cbPorts.removeAllItems(); |
371 |
|
372 |
if(dev != null) for(MidiPort p : dev.getMidiPorts()) cbPorts.addItem(p); |
373 |
if(current != null) cbPorts.setSelectedItem(current); |
374 |
cbPorts.setEnabled(cbPorts.getItemCount() > 0); |
375 |
cbPorts.setMaximumSize(cbPorts.getPreferredSize()); |
376 |
} |
377 |
} |
378 |
|
379 |
class MidiChannelWizardPage extends UserInputPage { |
380 |
private final JLabel lChannel = new JLabel(i18n.getLabel("MidiChannelWizardPage.lChannel")); |
381 |
private final JComboBox cbChannels = new JComboBox(); |
382 |
|
383 |
MidiChannelWizardPage() { |
384 |
super(i18n.getLabel("MidiChannelWizardPage.subtitle")); |
385 |
|
386 |
setMainInstructions(i18n.getLabel("MidiChannelWizardPage.mainInstructions")); |
387 |
|
388 |
JPanel p = new JPanel(); |
389 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
390 |
|
391 |
p.add(lChannel); |
392 |
|
393 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
394 |
|
395 |
cbChannels.addItem("All"); |
396 |
for(int i = 1; i <= 16; i++) cbChannels.addItem(String.valueOf(i)); |
397 |
cbChannels.setMaximumSize(cbChannels.getPreferredSize()); |
398 |
|
399 |
p.add(cbChannels); |
400 |
|
401 |
setMainPane(p); |
402 |
} |
403 |
|
404 |
/** |
405 |
* Gets the selected MIDI channel. |
406 |
* @return The number of the selected MIDI channel or -1 which means all channels. |
407 |
*/ |
408 |
public int |
409 |
getSelectedChannel() { |
410 |
Object o = cbChannels.getSelectedItem(); |
411 |
if(o == null) return -1; |
412 |
|
413 |
return o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()); |
414 |
} |
415 |
} |
416 |
|
417 |
class AudioDeviceWizardPage extends UserInputPage { |
418 |
private final JLabel lDevice = new JLabel(i18n.getLabel("AudioDeviceWizardPage.lDevice")); |
419 |
private final JComboBox cbDevices = new JComboBox(); |
420 |
private final JButton btnNewDevice = |
421 |
new JButton(i18n.getButtonLabel("AudioDeviceWizardPage.btnNewDevice")); |
422 |
|
423 |
AudioDeviceWizardPage() { |
424 |
super(i18n.getLabel("AudioDeviceWizardPage.subtitle")); |
425 |
|
426 |
setMainInstructions(i18n.getLabel("AudioDeviceWizardPage.mainInstructions")); |
427 |
setAdditionalInstructions ( |
428 |
i18n.getLabel("AudioDeviceWizardPage.additionalInstructions") |
429 |
); |
430 |
|
431 |
JPanel p = new JPanel(); |
432 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
433 |
|
434 |
p.add(lDevice); |
435 |
|
436 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
437 |
|
438 |
for(AudioDeviceModel m : CC.getSamplerModel().getAudioDeviceModels()) { |
439 |
cbDevices.addItem(m.getDeviceInfo()); |
440 |
} |
441 |
|
442 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
443 |
if(cbDevices.getItemCount() == 0) cbDevices.setEnabled(false); |
444 |
|
445 |
p.add(cbDevices); |
446 |
|
447 |
CC.getSamplerModel().addAudioDeviceListListener(getHandler()); |
448 |
|
449 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
450 |
p.add(btnNewDevice); |
451 |
|
452 |
setMainPane(p); |
453 |
|
454 |
btnNewDevice.addActionListener(new ActionListener() { |
455 |
public void |
456 |
actionPerformed(ActionEvent e) { |
457 |
new NewAudioDeviceDlg(getWizardDialog()).setVisible(true); |
458 |
} |
459 |
}); |
460 |
} |
461 |
|
462 |
/** |
463 |
* Gets the selected device. |
464 |
* @return The selected device or <code>null</code> if there is no device selected. |
465 |
*/ |
466 |
public AudioOutputDevice |
467 |
getSelectedDevice() { return (AudioOutputDevice)cbDevices.getSelectedItem(); } |
468 |
|
469 |
private final Handler handler = new Handler(); |
470 |
|
471 |
private Handler |
472 |
getHandler() { return handler; } |
473 |
|
474 |
private class Handler implements AudioDeviceListListener { |
475 |
public void |
476 |
deviceAdded(AudioDeviceListEvent e) { |
477 |
updateDeviceList(e.getAudioDeviceModel().getDeviceInfo()); |
478 |
} |
479 |
|
480 |
public void |
481 |
deviceRemoved(AudioDeviceListEvent e) { updateDeviceList(null); } |
482 |
|
483 |
private void |
484 |
updateDeviceList(AudioOutputDevice dev) { |
485 |
cbDevices.removeAllItems(); |
486 |
|
487 |
for(AudioDeviceModel m : CC.getSamplerModel().getAudioDeviceModels()) { |
488 |
cbDevices.addItem(m.getDeviceInfo()); |
489 |
} |
490 |
|
491 |
if(cbDevices.getItemCount() == 0) cbDevices.setEnabled(false); |
492 |
else { |
493 |
cbDevices.setEnabled(true); |
494 |
cbDevices.setSelectedItem(dev); |
495 |
} |
496 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
497 |
} |
498 |
} |
499 |
} |
500 |
|
501 |
class EngineWizardPage extends UserInputPage { |
502 |
private final JLabel lEngine = new JLabel(i18n.getLabel("EngineWizardPage.lEngine")); |
503 |
private final JComboBox cbEngines = new JComboBox(); |
504 |
|
505 |
EngineWizardPage() { |
506 |
super(i18n.getLabel("EngineWizardPage.subtitle")); |
507 |
|
508 |
setMainInstructions(i18n.getLabel("EngineWizardPage.mainInstructions")); |
509 |
|
510 |
JPanel p = new JPanel(); |
511 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
512 |
|
513 |
p.add(lEngine); |
514 |
|
515 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
516 |
|
517 |
for(Object o : CC.getSamplerModel().getEngines()) { |
518 |
cbEngines.addItem(o); |
519 |
} |
520 |
|
521 |
cbEngines.setMaximumSize(cbEngines.getPreferredSize()); |
522 |
|
523 |
p.add(cbEngines); |
524 |
|
525 |
setMainPane(p); |
526 |
} |
527 |
|
528 |
/** |
529 |
* Gets the selected sampler engine to be used. |
530 |
* @return The selected sampler engine to be used. |
531 |
*/ |
532 |
public SamplerEngine |
533 |
getSelectedEngine() { return (SamplerEngine)cbEngines.getSelectedItem(); } |
534 |
} |
535 |
|
536 |
class InstrumentWizardPage extends UserInputPage { |
537 |
private final JLabel lFilename = new JLabel(i18n.getLabel("InstrumentChooser.lFilename")); |
538 |
private final JLabel lIndex = new JLabel(i18n.getLabel("InstrumentChooser.lIndex")); |
539 |
|
540 |
private final JTextField tfFilename = new JTextField(); |
541 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
542 |
|
543 |
private final JButton btnBrowse = |
544 |
new JButton(i18n.getLabel("InstrumentChooser.btnBrowse")); |
545 |
|
546 |
|
547 |
InstrumentWizardPage() { |
548 |
super(i18n.getLabel("InstrumentWizardPage.subtitle")); |
549 |
|
550 |
setMainInstructions(i18n.getLabel("InstrumentWizardPage.mainInstructions")); |
551 |
|
552 |
JPanel p = new JPanel(); |
553 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
554 |
|
555 |
p.add(lFilename); |
556 |
|
557 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
558 |
|
559 |
tfFilename.setPreferredSize ( |
560 |
new Dimension(200, tfFilename.getPreferredSize().height) |
561 |
); |
562 |
tfFilename.setMaximumSize(tfFilename.getPreferredSize()); |
563 |
p.add(tfFilename); |
564 |
|
565 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
566 |
|
567 |
spinnerIndex.setMaximumSize(spinnerIndex.getPreferredSize()); |
568 |
p.add(spinnerIndex); |
569 |
|
570 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
571 |
|
572 |
p.add(btnBrowse); |
573 |
|
574 |
p.setMaximumSize(p.getPreferredSize()); |
575 |
setMainPane(p); |
576 |
|
577 |
btnBrowse.addActionListener(new ActionListener() { |
578 |
public void |
579 |
actionPerformed(ActionEvent e) { onBrowse(); } |
580 |
}); |
581 |
|
582 |
btnBrowse.requestFocusInWindow(); |
583 |
} |
584 |
|
585 |
public void |
586 |
initPage() { |
587 |
NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel(); |
588 |
if(model.getSelectedAudioDevice() == null) { |
589 |
String s = i18n.getLabel("InstrumentWizardPage.additionalInstructions"); |
590 |
setAdditionalInstructions(s); |
591 |
} else { setAdditionalInstructions(""); } |
592 |
} |
593 |
|
594 |
public boolean |
595 |
mayGoToNext() { |
596 |
NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel(); |
597 |
if(model.getSelectedAudioDevice() == null && getSelectedFile().length() > 0) { |
598 |
String s = i18n.getError("InstrumentWizardPage.selectAODevice!"); |
599 |
HF.showErrorMessage(s, getWizardDialog()); |
600 |
return false; |
601 |
} else { |
602 |
return true; |
603 |
} |
604 |
} |
605 |
|
606 |
/** |
607 |
* Gets the name of the instrument file. |
608 |
* @return The name of the instrument file. |
609 |
*/ |
610 |
public String |
611 |
getSelectedFile() { return tfFilename.getText(); } |
612 |
|
613 |
/** |
614 |
* Gets the index of the instrument in the instrument file. |
615 |
* @return The index of the instrument in the instrument file. |
616 |
*/ |
617 |
public int |
618 |
getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); } |
619 |
|
620 |
private void |
621 |
onBrowse() { |
622 |
JFileChooser fc = new JFileChooser(); |
623 |
int result = fc.showOpenDialog(this); |
624 |
if(result == JFileChooser.APPROVE_OPTION) { |
625 |
tfFilename.setText(fc.getSelectedFile().getPath()); |
626 |
} |
627 |
} |
628 |
} |
629 |
|
630 |
class ConfirmationWizardPage extends WizardPage { |
631 |
private MidiInputDevice midiDev = null; |
632 |
private MidiPort midiPort = null; |
633 |
private int midiChannel = -1; |
634 |
private AudioOutputDevice audioDev = null; |
635 |
private SamplerEngine engine = null; |
636 |
private String instrFile = null; |
637 |
private int instrIndex; |
638 |
|
639 |
private final JLabel lInfo = new JLabel(i18n.getLabel("ConfirmationWizardPage.lInfo")); |
640 |
|
641 |
private final JLabel lMidiDevice = |
642 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiDevice")); |
643 |
private final JLabel lMidiPort = |
644 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiPort")); |
645 |
private final JLabel lMidiChannel = |
646 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiChannel")); |
647 |
private final JLabel lEngine = |
648 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lEngine")); |
649 |
private final JLabel lInstrFile = |
650 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lInstrFile")); |
651 |
private final JLabel lInstrIndex = |
652 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lInstrIndex")); |
653 |
private final JLabel lAudioDevice = |
654 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lAudioDevice")); |
655 |
|
656 |
private final JTextField tfMidiDevice = new EnhancedTextField(); |
657 |
private final JTextField tfMidiPort = new EnhancedTextField(); |
658 |
private final JTextField tfMidiChannel = new EnhancedTextField(); |
659 |
private final JTextField tfEngine = new EnhancedTextField(); |
660 |
private final JTextField tfInstrFile = new EnhancedTextField(); |
661 |
private final JTextField tfInstrIndex = new EnhancedTextField(); |
662 |
private final JTextField tfAudioDevice = new EnhancedTextField(); |
663 |
|
664 |
ConfirmationWizardPage() { |
665 |
super(i18n.getLabel("ConfirmationWizardPage.subtitle"), "", Type.CONFIRMATION_PAGE); |
666 |
|
667 |
GridBagLayout gridbag = new GridBagLayout(); |
668 |
GridBagConstraints c = new GridBagConstraints(); |
669 |
|
670 |
//JPanel mainPane = new JPanel(); |
671 |
|
672 |
setLayout(gridbag); |
673 |
|
674 |
c.fill = GridBagConstraints.NONE; |
675 |
|
676 |
c.gridx = 0; |
677 |
c.gridy = 1; |
678 |
c.anchor = GridBagConstraints.EAST; |
679 |
c.insets = new Insets(3, 3, 3, 3); |
680 |
gridbag.setConstraints(lMidiDevice, c); |
681 |
add(lMidiDevice); |
682 |
|
683 |
c.gridx = 0; |
684 |
c.gridy = 2; |
685 |
gridbag.setConstraints(lMidiPort, c); |
686 |
add(lMidiPort); |
687 |
|
688 |
c.gridx = 0; |
689 |
c.gridy = 3; |
690 |
gridbag.setConstraints(lMidiChannel, c); |
691 |
add(lMidiChannel); |
692 |
|
693 |
c.gridx = 0; |
694 |
c.gridy = 4; |
695 |
gridbag.setConstraints(lEngine, c); |
696 |
add(lEngine); |
697 |
|
698 |
c.gridx = 0; |
699 |
c.gridy = 5; |
700 |
gridbag.setConstraints(lInstrFile, c); |
701 |
add(lInstrFile); |
702 |
|
703 |
c.gridx = 0; |
704 |
c.gridy = 6; |
705 |
gridbag.setConstraints(lInstrIndex, c); |
706 |
add(lInstrIndex); |
707 |
|
708 |
c.gridx = 0; |
709 |
c.gridy = 7; |
710 |
gridbag.setConstraints(lAudioDevice, c); |
711 |
add(lAudioDevice); |
712 |
|
713 |
c.fill = GridBagConstraints.HORIZONTAL; |
714 |
c.gridx = 1; |
715 |
c.gridy = 1; |
716 |
c.weightx = 1.0; |
717 |
c.anchor = GridBagConstraints.WEST; |
718 |
gridbag.setConstraints(tfMidiDevice, c); |
719 |
add(tfMidiDevice); |
720 |
|
721 |
c.gridx = 1; |
722 |
c.gridy = 2; |
723 |
gridbag.setConstraints(tfMidiPort, c); |
724 |
add(tfMidiPort); |
725 |
|
726 |
c.gridx = 1; |
727 |
c.gridy = 3; |
728 |
gridbag.setConstraints(tfMidiChannel, c); |
729 |
add(tfMidiChannel); |
730 |
|
731 |
c.gridx = 1; |
732 |
c.gridy = 4; |
733 |
gridbag.setConstraints(tfEngine, c); |
734 |
add(tfEngine); |
735 |
|
736 |
c.gridx = 1; |
737 |
c.gridy = 5; |
738 |
gridbag.setConstraints(tfInstrFile, c); |
739 |
add(tfInstrFile); |
740 |
|
741 |
c.gridx = 1; |
742 |
c.gridy = 6; |
743 |
gridbag.setConstraints(tfInstrIndex, c); |
744 |
add(tfInstrIndex); |
745 |
|
746 |
c.gridx = 1; |
747 |
c.gridy = 7; |
748 |
gridbag.setConstraints(tfAudioDevice, c); |
749 |
add(tfAudioDevice); |
750 |
|
751 |
lInfo.setFont(lInfo.getFont().deriveFont(java.awt.Font.PLAIN)); |
752 |
|
753 |
c.gridx = 0; |
754 |
c.gridy = 0; |
755 |
c.gridwidth = 2; |
756 |
c.insets = new Insets(12, 3, 17, 3); |
757 |
c.anchor = GridBagConstraints.NORTH; |
758 |
gridbag.setConstraints(lInfo, c); |
759 |
add(lInfo); |
760 |
|
761 |
JPanel p = new JPanel(); |
762 |
p.setOpaque(false); |
763 |
c.gridx = 0; |
764 |
c.gridy = 8; |
765 |
c.weightx = 1.0; |
766 |
c.weighty = 1.0; |
767 |
c.insets = new Insets(0, 0, 0, 0); |
768 |
gridbag.setConstraints(p, c); |
769 |
add(p); |
770 |
|
771 |
} |
772 |
|
773 |
public void |
774 |
initPage() { |
775 |
NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel(); |
776 |
setMidiDevice(model.getSelectedMidiDevice()); |
777 |
|
778 |
|
779 |
if(model.getCustomMidiSettings()) { |
780 |
setMidiPort(model.getSelectedMidiPort()); |
781 |
setMidiChannel(model.getSelectedMidiChannel()); |
782 |
} else { |
783 |
MidiInputDevice mdev = model.getSelectedMidiDevice(); |
784 |
if(mdev == null) setMidiPort(null); |
785 |
else if(mdev.getMidiPorts().length < 1) setMidiPort(null); |
786 |
else setMidiPort(mdev.getMidiPort(0)); |
787 |
|
788 |
setMidiChannel(-1); |
789 |
} |
790 |
|
791 |
setEngine(model.getSelectedEngine()); |
792 |
setAudioDevice(model.getSelectedAudioDevice()); |
793 |
setInstrumentFile(model.getSelectedFile()); |
794 |
setInstrumentIndex(model.getInstrumentIndex()); |
795 |
} |
796 |
|
797 |
/** |
798 |
* Invoked when the user clicks the 'Finish' button |
799 |
* while this page is the current page of the wizard. |
800 |
* @return <code>true</code> |
801 |
*/ |
802 |
public boolean |
803 |
mayFinish() { |
804 |
final AddChannel ac = new AddChannel(); |
805 |
|
806 |
ac.addTaskListener(new TaskListener() { |
807 |
public void |
808 |
taskPerformed(TaskEvent e) { |
809 |
if(ac.doneWithErrors()) return; |
810 |
doIt(ac.getResult()); |
811 |
} |
812 |
}); |
813 |
|
814 |
CC.getTaskQueue().add(ac); |
815 |
|
816 |
return true; |
817 |
} |
818 |
|
819 |
private void |
820 |
doIt(int chn) { |
821 |
if(getEngine() != null) |
822 |
CC.getTaskQueue().add(new LoadEngine(getEngine().getName(), chn)); |
823 |
|
824 |
/*if(getMidiDPort() != null) CC.getTaskQueue().add ( |
825 |
new SetChannelMidiInputPort(chn, getMidiPort().) |
826 |
);*/ |
827 |
|
828 |
MidiInputDevice d = getMidiDevice(); |
829 |
if(d != null) { |
830 |
CC.getTaskQueue().add(new SetChannelMidiInputDevice(chn, d.getDeviceID())); |
831 |
|
832 |
if(getMidiPort() != null) { |
833 |
int port = -1; |
834 |
for(int i = 0; i < d.getMidiPortCount(); i++) { |
835 |
if(d.getMidiPort(i) == getMidiPort()) { |
836 |
port = i; |
837 |
break; |
838 |
} |
839 |
} |
840 |
|
841 |
if(port != -1) CC.getTaskQueue().add ( |
842 |
new SetChannelMidiInputPort(chn, port) |
843 |
); |
844 |
} |
845 |
|
846 |
|
847 |
int mc = (getMidiChannel() == -1 ? -1 : getMidiChannel() - 1); |
848 |
CC.getTaskQueue().add(new SetChannelMidiInputChannel(chn, mc)); |
849 |
} |
850 |
|
851 |
|
852 |
|
853 |
if(getAudioDevice() != null) CC.getTaskQueue().add ( |
854 |
new SetChannelAudioOutputDevice(chn, getAudioDevice().getDeviceID()) |
855 |
); |
856 |
|
857 |
if(getInstrumentFile().length() > 0) CC.getTaskQueue().add ( |
858 |
new LoadInstrument(getInstrumentFile(), getInstrumentIndex(), chn) |
859 |
); |
860 |
} |
861 |
|
862 |
/** |
863 |
* Gets the audio output device to be used by this sampler channel. |
864 |
* @return The audio output device to be used by this sampler channel. |
865 |
*/ |
866 |
public AudioOutputDevice |
867 |
getAudioDevice() { return audioDev; } |
868 |
|
869 |
/** |
870 |
* Sets the audio output device to be used by this sampler channel. |
871 |
* @param dev The audio output device to be used by this sampler channel. |
872 |
*/ |
873 |
public void |
874 |
setAudioDevice(AudioOutputDevice dev) { |
875 |
audioDev = dev; |
876 |
if(dev == null) { |
877 |
tfAudioDevice.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
878 |
} else { |
879 |
tfAudioDevice.setText(dev.getDeviceID() + " (" + dev.getDriverName() + ")"); |
880 |
} |
881 |
} |
882 |
|
883 |
/** |
884 |
* Gets the sampler engine to be used. |
885 |
* @return The sampler engine to be used. |
886 |
*/ |
887 |
public SamplerEngine |
888 |
getEngine() { return engine; } |
889 |
|
890 |
/** |
891 |
* Sets the sampler engine to be used. |
892 |
* @param engine The sampler engine to be used. |
893 |
*/ |
894 |
public void |
895 |
setEngine(SamplerEngine engine) { |
896 |
this.engine = engine; |
897 |
if(engine == null) { |
898 |
tfEngine.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
899 |
} else { |
900 |
tfEngine.setText(engine.getName() + " (" + engine.getDescription() + ")"); |
901 |
} |
902 |
} |
903 |
|
904 |
/** |
905 |
* Gets the name of the instrument file. |
906 |
* @return The name of the instrument file. |
907 |
*/ |
908 |
public String |
909 |
getInstrumentFile() { return instrFile; } |
910 |
|
911 |
/** |
912 |
* Sets the name of the instrument file. |
913 |
* @param file The name of the instrument file. |
914 |
*/ |
915 |
public void |
916 |
setInstrumentFile(String file) { |
917 |
instrFile = file; |
918 |
|
919 |
if(file.length() == 0) { |
920 |
tfInstrFile.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
921 |
} else { |
922 |
tfInstrFile.setText(file); |
923 |
} |
924 |
} |
925 |
|
926 |
/** |
927 |
* Gets the index of the instrument in the instrument file. |
928 |
* @return The index of the instrument in the instrument file. |
929 |
*/ |
930 |
public int |
931 |
getInstrumentIndex() { return instrIndex; } |
932 |
|
933 |
/** |
934 |
* Sets the index of the instrument in the instrument file. |
935 |
* @param idx The index of the instrument in the instrument file. |
936 |
*/ |
937 |
public void |
938 |
setInstrumentIndex(int idx) { |
939 |
instrIndex = idx; |
940 |
tfInstrIndex.setText(String.valueOf(idx)); |
941 |
} |
942 |
|
943 |
/** |
944 |
* Gets the MIDI channel to which this sampler channel will listen to. |
945 |
* @return The MIDI channel to which this sampler channel will listen to |
946 |
* (-1 means all channels). |
947 |
* . |
948 |
*/ |
949 |
public int |
950 |
getMidiChannel() { return midiChannel; } |
951 |
|
952 |
/** |
953 |
* Sets the MIDI channel to which this sampler channel will listen to. |
954 |
* @param chn The MIDI channel to which this sampler channel will listen to |
955 |
* (-1 means all channels). |
956 |
* . |
957 |
*/ |
958 |
public void |
959 |
setMidiChannel(int chn) { |
960 |
midiChannel = chn; |
961 |
tfMidiChannel.setText(chn == -1 ? "All" : String.valueOf(chn)); |
962 |
} |
963 |
|
964 |
/** |
965 |
* Gets the MIDI input device to which this sampler channel will be connected to. |
966 |
* @return The MIDI input device to which this sampler channel will be connected to. |
967 |
*/ |
968 |
public MidiInputDevice |
969 |
getMidiDevice() { return midiDev; } |
970 |
|
971 |
/** |
972 |
* Sets the MIDI input device to which this sampler channel will be connected to. |
973 |
* @param dev The numerical id of the MIDI input device to which |
974 |
* this sampler channel will be connected to. |
975 |
*/ |
976 |
public void |
977 |
setMidiDevice(MidiInputDevice dev) { |
978 |
midiDev = dev; |
979 |
|
980 |
if(dev == null) { |
981 |
tfMidiDevice.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
982 |
} else { |
983 |
tfMidiDevice.setText(dev.getDeviceID() + " (" + dev.getDriverName() + ")"); |
984 |
} |
985 |
} |
986 |
|
987 |
/** |
988 |
* Gets the MIDI input port. |
989 |
* @return The MIDI input port. |
990 |
*/ |
991 |
public MidiPort |
992 |
getMidiPort() { return midiPort; } |
993 |
|
994 |
/** |
995 |
* Sets the MIDI input port. |
996 |
* @param port The MIDI input port. |
997 |
*/ |
998 |
public void |
999 |
setMidiPort(MidiPort port) { |
1000 |
midiPort = port; |
1001 |
|
1002 |
if(port == null) { |
1003 |
tfMidiPort.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
1004 |
} else { |
1005 |
tfMidiPort.setText(port.getName()); |
1006 |
} |
1007 |
} |
1008 |
|
1009 |
private class EnhancedTextField extends JTextField { |
1010 |
EnhancedTextField() { |
1011 |
setEditable(false); |
1012 |
setBorder(BorderFactory.createEmptyBorder()); |
1013 |
} |
1014 |
} |
1015 |
} |