/[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 1352 - (show annotations) (download)
Sun Sep 16 23:24:15 2007 UTC (16 years, 7 months ago) by iliev
File size: 28539 byte(s)
* instruments db: slashes-in-names are now escaped with \x2f
* some bugfixes

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

  ViewVC Help
Powered by ViewVC