/[svn]/jsampler/trunk/src/org/jsampler/view/classic/NewChannelWizard.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/NewChannelWizard.java

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC