/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSNewMidiInstrumentWizard.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSNewMidiInstrumentWizard.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1480 - (show annotations) (download)
Wed Nov 14 21:39:45 2007 UTC (16 years, 5 months ago) by iliev
File size: 25309 byte(s)
* added Windows file path support

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.std;
24
25 import java.awt.BorderLayout;
26 import java.awt.Dimension;
27 import java.awt.GridBagConstraints;
28 import java.awt.GridBagLayout;
29 import java.awt.Insets;
30
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33
34 import javax.swing.Box;
35 import javax.swing.BoxLayout;
36 import javax.swing.ButtonGroup;
37 import javax.swing.ImageIcon;
38 import javax.swing.JButton;
39 import javax.swing.JCheckBox;
40 import javax.swing.JComboBox;
41 import javax.swing.JFileChooser;
42 import javax.swing.JLabel;
43 import javax.swing.JPanel;
44 import javax.swing.JRadioButton;
45 import javax.swing.JSlider;
46 import javax.swing.JSpinner;
47 import javax.swing.JTextField;
48 import javax.swing.SpinnerNumberModel;
49
50 import javax.swing.event.DocumentEvent;
51 import javax.swing.event.DocumentListener;
52
53 import net.sf.juife.Wizard;
54
55 import net.sf.juife.wizard.DefaultWizardModel;
56 import net.sf.juife.wizard.UserInputPage;
57 import net.sf.juife.wizard.WizardPage;
58
59 import org.jsampler.CC;
60 import org.jsampler.Instrument;
61 import org.jsampler.JSPrefs;
62 import org.jsampler.MidiInstrumentMap;
63 import org.jsampler.OrchestraModel;
64
65 import org.linuxsampler.lscp.MidiInstrumentEntry;
66 import org.linuxsampler.lscp.MidiInstrumentInfo;
67 import org.linuxsampler.lscp.SamplerEngine;
68
69 import static org.jsampler.view.std.StdI18n.i18n;
70 import static org.linuxsampler.lscp.Parser.*;
71
72
73 /**
74 * A wizard for mapping new MIDI instrument.
75 * @author Grigor Iliev
76 */
77 public class JSNewMidiInstrumentWizard extends Wizard {
78 /**
79 * Creates a new instance of <code>JSNewMidiInstrumentWizard</code>.
80 */
81 public
82 JSNewMidiInstrumentWizard(ImageIcon iconBrowse) {
83 this(iconBrowse, null);
84 }
85
86 /**
87 * Creates a new instance of <code>JSNewMidiInstrumentWizard</code>.
88 */
89 public
90 JSNewMidiInstrumentWizard(ImageIcon iconBrowse, MidiInstrumentMap defaultMap) {
91 super(CC.getMainFrame(), i18n.getLabel("JSNewMidiInstrumentWizard.title"));
92 setModel(new NewMidiInstrumentWizardModel(iconBrowse, defaultMap));
93 }
94
95 }
96
97 class NewMidiInstrumentWizardModel extends DefaultWizardModel {
98 private final InstrLocationMethodWizardPage instrLocationMethodWizardPage;
99 private final OrchestraSelectWizardPage orchestraSelectWizardPage;
100 private final ManualSelectWizardPage manualSelectWizardPage;
101 private final InstrumentMappingWizardPage instrumentMappingWizardPage;
102
103 private MidiInstrumentMap defaultMap;
104
105 NewMidiInstrumentWizardModel(ImageIcon iconBrowse, MidiInstrumentMap defaultMap) {
106 this.defaultMap = defaultMap;
107 instrLocationMethodWizardPage = new InstrLocationMethodWizardPage();
108 orchestraSelectWizardPage = new OrchestraSelectWizardPage();
109 manualSelectWizardPage = new ManualSelectWizardPage(iconBrowse);
110 instrumentMappingWizardPage = new InstrumentMappingWizardPage(this);
111
112 addPage(instrLocationMethodWizardPage);
113 addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step1"));
114
115 addPage(manualSelectWizardPage);
116 addPage(orchestraSelectWizardPage);
117 addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step2"), 2);
118
119 addPage(instrumentMappingWizardPage);
120 addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step3"));
121 }
122
123 public String
124 getInstrumentName() {
125 if(!instrLocationMethodWizardPage.isOrchestraMethodSelected()) return null;
126 Instrument instr = orchestraSelectWizardPage.getInstrument();
127 if(instr == null) return null;
128 return instr.getName();
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 InstrLocationMethodWizardPage p1 = instrLocationMethodWizardPage;
138 WizardPage p2 = manualSelectWizardPage;
139
140 if(getCurrentPage() == p1 && p1.isOrchestraMethodSelected()) {
141 super.next();
142 } else if(getCurrentPage() == manualSelectWizardPage) {
143 super.next();
144 }
145
146 return super.next();
147 }
148
149 /**
150 * Moves to the previous page in the wizard.
151 * @return The previous page in the wizard.
152 * @see #hasPrevious
153 */
154 public WizardPage
155 previous() {
156 InstrLocationMethodWizardPage p1 = instrLocationMethodWizardPage;
157 WizardPage p2 = instrumentMappingWizardPage;
158
159 if(getCurrentPage() == orchestraSelectWizardPage) {
160 super.previous();
161 } else if(getCurrentPage() == p2 && !p1.isOrchestraMethodSelected()) {
162 super.previous();
163 }
164
165 return super.previous();
166 }
167
168 public void
169 mapInstrument() {
170 MidiInstrumentInfo instr = new MidiInstrumentInfo();
171 if(instrLocationMethodWizardPage.isOrchestraMethodSelected()) {
172 Instrument i = orchestraSelectWizardPage.getInstrument();
173 instr.setFilePath(i.getPath());
174 instr.setInstrumentIndex(i.getInstrumentIndex());
175 instr.setEngine(i.getEngine());
176 instr.setLoadMode(orchestraSelectWizardPage.getLoadMode());
177 } else {
178 instr.setFilePath(manualSelectWizardPage.getSelectedFile());
179 instr.setInstrumentIndex(manualSelectWizardPage.getInstrumentIndex());
180 instr.setEngine(manualSelectWizardPage.getEngine());
181 instr.setLoadMode(manualSelectWizardPage.getLoadMode());
182 }
183
184 int map = instrumentMappingWizardPage.getMapId();
185 int bank = instrumentMappingWizardPage.getMidiBank();
186 int prog = instrumentMappingWizardPage.getMidiProgram();
187
188 instr.setName(instrumentMappingWizardPage.getInstrumentName());
189 instr.setVolume(instrumentMappingWizardPage.getVolume());
190
191 CC.getSamplerModel().mapBackendMidiInstrument(map, bank, prog, instr);
192 }
193
194 public MidiInstrumentMap
195 getDefaultMap() { return defaultMap; }
196
197 public void
198 setDefaultMap(MidiInstrumentMap map) { defaultMap = map; }
199 }
200
201 class InstrLocationMethodWizardPage extends UserInputPage {
202 private final static String INSTR_LOCATION_METHOD = "InstrLocationMethod";
203 private final static String NEW_MIDI_INSTR_WIZARD_SKIP1 = "NewMidiInstrumentWizard.skip1";
204
205 private final JRadioButton rbManual =
206 new JRadioButton(i18n.getLabel("InstrLocationMethodWizardPage.rbManual"));
207
208 private final JRadioButton rbOrchestra =
209 new JRadioButton(i18n.getLabel("InstrLocationMethodWizardPage.rbOrchestra"));
210
211 private final JCheckBox checkSkip =
212 new JCheckBox(i18n.getLabel("InstrLocationMethodWizardPage.checkSkip"));
213
214 InstrLocationMethodWizardPage() {
215 super(i18n.getLabel("InstrLocationMethodWizardPage.subtitle"));
216
217 String s = i18n.getLabel("InstrLocationMethodWizardPage.mainInstructions");
218 setMainInstructions(s);
219
220 JPanel p = new JPanel();
221 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
222
223 ButtonGroup group = new ButtonGroup();
224 group.add(rbManual);
225 group.add(rbOrchestra);
226 rbManual.setSelected(true);
227
228 p.add(rbManual);
229 p.add(rbOrchestra);
230
231 JPanel p2 = new JPanel();
232 p2.setLayout(new BorderLayout());
233 p2.add(p, BorderLayout.NORTH);
234 p2.add(checkSkip, BorderLayout.SOUTH);
235 setMainPane(p2);
236
237 switch(preferences().getIntProperty(INSTR_LOCATION_METHOD)) {
238 case 0:
239 rbManual.setSelected(true);
240 break;
241 case 1:
242 rbOrchestra.setSelected(true);
243 }
244
245 checkSkip.setSelected(preferences().getBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1));
246
247 rbManual.addActionListener(new ActionListener() {
248 public void
249 actionPerformed(ActionEvent e) {
250 if(rbManual.isSelected()) {
251 preferences().setIntProperty(INSTR_LOCATION_METHOD, 0);
252 }
253 }
254 });
255
256 rbOrchestra.addActionListener(new ActionListener() {
257 public void
258 actionPerformed(ActionEvent e) {
259 if(rbOrchestra.isSelected()) {
260 preferences().setIntProperty(INSTR_LOCATION_METHOD, 1);
261 }
262 }
263 });
264
265 checkSkip.addActionListener(new ActionListener() {
266 public void
267 actionPerformed(ActionEvent e) {
268 boolean b = checkSkip.isSelected();
269 preferences().setBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1, b);
270 }
271 });
272 }
273
274 protected JSPrefs
275 preferences() { return CC.getViewConfig().preferences(); }
276
277 /**
278 * Determines whether the user selected an orchestra location method.
279 */
280 public boolean
281 isOrchestraMethodSelected() { return rbOrchestra.isSelected(); }
282 }
283
284 class OrchestraSelectWizardPage extends UserInputPage {
285 private final JLabel lOrchestras =
286 new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lOrchestras"));
287
288 private final JLabel lInstruments =
289 new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lInstruments"));
290
291 private final JLabel lLoadMode =
292 new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lLoadMode"));
293
294 private final JComboBox cbOrchestras = new JComboBox();
295 private final JComboBox cbInstruments = new JComboBox();
296 private final JComboBox cbLoadMode = new JComboBox();
297
298 OrchestraSelectWizardPage() {
299 super(i18n.getLabel("OrchestraSelectWizardPage.subtitle"));
300 setMainInstructions(i18n.getLabel("OrchestraSelectWizardPage.mainInstructions"));
301
302 GridBagLayout gridbag = new GridBagLayout();
303 GridBagConstraints c = new GridBagConstraints();
304
305 JPanel p = new JPanel();
306
307 p.setLayout(gridbag);
308
309 c.fill = GridBagConstraints.NONE;
310
311 c.gridx = 0;
312 c.gridy = 0;
313 c.anchor = GridBagConstraints.EAST;
314 c.insets = new Insets(0, 0, 6, 16);
315 gridbag.setConstraints(lOrchestras, c);
316 p.add(lOrchestras);
317
318 c.gridx = 0;
319 c.gridy = 1;
320 gridbag.setConstraints(lInstruments, c);
321 p.add(lInstruments);
322
323 c.gridx = 0;
324 c.gridy = 2;
325 c.insets = new Insets(12, 0, 6, 16);
326 gridbag.setConstraints(lLoadMode, c);
327 p.add(lLoadMode);
328
329 c.gridx = 1;
330 c.gridy = 0;
331 c.weightx = 1.0;
332 c.insets = new Insets(0, 0, 6, 48);
333 c.fill = GridBagConstraints.HORIZONTAL;
334 c.anchor = GridBagConstraints.NORTH;
335 gridbag.setConstraints(cbOrchestras, c);
336 p.add(cbOrchestras);
337
338 c.gridx = 1;
339 c.gridy = 1;
340 gridbag.setConstraints(cbInstruments, c);
341 p.add(cbInstruments);
342
343 c.gridx = 1;
344 c.gridy = 2;
345 c.insets = new Insets(12, 0, 6, 48);
346 gridbag.setConstraints(cbLoadMode, c);
347 p.add(cbLoadMode);
348
349 JPanel p2 = new JPanel();
350 p2.setOpaque(false);
351 c.gridx = 0;
352 c.gridy = 3;
353 c.fill = GridBagConstraints.VERTICAL;
354 c.weightx = 0.0;
355 c.weighty = 1.0;
356 gridbag.setConstraints(p2, c);
357 p.add(p2);
358
359 setMainPane(p);
360
361 int orchIdx =
362 preferences().getIntProperty("OrchestraSelectWizardPage.OrchestraIndex", 0);
363
364 cbOrchestras.addActionListener(new ActionListener() {
365 public void
366 actionPerformed(ActionEvent e) { orchestraChanged(); }
367 });
368
369 for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) {
370 cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i));
371 }
372
373 if(CC.getOrchestras().getOrchestraCount() > orchIdx) {
374 cbOrchestras.setSelectedIndex(orchIdx);
375 }
376
377 cbInstruments.addActionListener(new ActionListener() {
378 public void
379 actionPerformed(ActionEvent e) { instrumentChanged(); }
380 });
381
382 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT);
383 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND);
384 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD);
385 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT);
386
387 int i = preferences().getIntProperty("std.midiInstrument.loadMode", 0);
388 if(cbLoadMode.getItemCount() > i) cbLoadMode.setSelectedIndex(i);
389
390 cbLoadMode.addActionListener(new ActionListener() {
391 public void
392 actionPerformed(ActionEvent e) {
393 int j = cbLoadMode.getSelectedIndex();
394 if(j < 0) return;
395 preferences().setIntProperty("std.midiInstrument.loadMode", j);
396 }
397 });
398 }
399
400 protected JSPrefs
401 preferences() { return CC.getViewConfig().preferences(); }
402
403 private void
404 orchestraChanged() {
405 OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem();
406 String s = om == null ? null : om.getDescription();
407 if(s != null && s.length() == 0) s = null;
408 cbOrchestras.setToolTipText(s);
409
410 s = "OrchestraSelectWizardPage.OrchestraIndex";
411 int orchIdx = cbOrchestras.getSelectedIndex();
412 if(orchIdx >= 0) preferences().setIntProperty(s, orchIdx);
413
414 cbInstruments.removeAllItems();
415 if(om == null || om.getInstrumentCount() == 0) {
416 cbInstruments.setEnabled(false);
417 return;
418 }
419
420 cbInstruments.setEnabled(true);
421
422 for(int i = 0; i < om.getInstrumentCount(); i++) {
423 cbInstruments.addItem(om.getInstrument(i));
424 }
425 }
426
427 private void
428 instrumentChanged() {
429 Instrument instr = (Instrument)cbInstruments.getSelectedItem();
430 String s = instr == null ? null : instr.getDescription();
431 if(s != null && s.length() == 0) s = null;
432 cbInstruments.setToolTipText(s);
433
434 getWizard().enableNextButton(instr != null);
435 }
436
437 public void
438 postinitPage() {
439 getWizard().enableNextButton(cbInstruments.getSelectedItem() != null);
440 }
441
442 /**
443 * Gets the selected instrument.
444 */
445 public Instrument
446 getInstrument() { return (Instrument)cbInstruments.getSelectedItem(); }
447
448 /**
449 * Gets the selected load mode.
450 */
451 public MidiInstrumentInfo.LoadMode
452 getLoadMode() { return (MidiInstrumentInfo.LoadMode) cbLoadMode.getSelectedItem(); }
453 }
454
455 class ManualSelectWizardPage extends UserInputPage {
456 private final JLabel lFilename =
457 new JLabel(i18n.getLabel("ManualSelectWizardPage.lFilename"));
458
459 private final JLabel lIndex = new JLabel(i18n.getLabel("ManualSelectWizardPage.lIndex"));
460
461 private final JLabel lEngine = new JLabel(i18n.getLabel("ManualSelectWizardPage.lEngine"));
462
463 private final JLabel lLoadMode =
464 new JLabel(i18n.getLabel("ManualSelectWizardPage.lLoadMode"));
465
466 private final JComboBox cbFilename = new JComboBox();
467 private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1));
468
469 private final JButton btnBrowse;
470
471 private final JComboBox cbEngine = new JComboBox();
472 private final JComboBox cbLoadMode = new JComboBox();
473
474 ManualSelectWizardPage(ImageIcon iconBrowse) {
475 super(i18n.getLabel("ManualSelectWizardPage.subtitle"));
476 setMainInstructions(i18n.getLabel("ManualSelectWizardPage.mainInstructions"));
477
478 GridBagLayout gridbag = new GridBagLayout();
479 GridBagConstraints c = new GridBagConstraints();
480
481 JPanel mainPane = new JPanel();
482
483 mainPane.setLayout(gridbag);
484
485 c.fill = GridBagConstraints.NONE;
486
487 c.gridx = 0;
488 c.gridy = 0;
489 c.anchor = GridBagConstraints.EAST;
490 c.insets = new Insets(3, 3, 3, 3);
491 gridbag.setConstraints(lFilename, c);
492 mainPane.add(lFilename);
493
494 c.gridx = 0;
495 c.gridy = 1;
496 gridbag.setConstraints(lIndex, c);
497 mainPane.add(lIndex);
498
499 c.gridx = 0;
500 c.gridy = 2;
501 c.insets = new Insets(12, 3, 3, 3);
502 gridbag.setConstraints(lEngine, c);
503 mainPane.add(lEngine);
504
505 c.gridx = 0;
506 c.gridy = 3;
507 c.insets = new Insets(3, 3, 3, 3);
508 gridbag.setConstraints(lLoadMode, c);
509 mainPane.add(lLoadMode);
510
511 btnBrowse = new JButton(iconBrowse);
512 btnBrowse.setMargin(new Insets(0, 0, 0, 0));
513 btnBrowse.setToolTipText(i18n.getLabel("ManualSelectWizardPage.btnBrowse"));
514 c.gridx = 2;
515 c.gridy = 0;
516 gridbag.setConstraints(btnBrowse, c);
517 mainPane.add(btnBrowse);
518
519 c.fill = GridBagConstraints.HORIZONTAL;
520 c.gridx = 1;
521 c.gridy = 0;
522 c.weightx = 1.0;
523 c.anchor = GridBagConstraints.WEST;
524 gridbag.setConstraints(cbFilename, c);
525 mainPane.add(cbFilename);
526
527 c.gridx = 1;
528 c.gridy = 1;
529 gridbag.setConstraints(spinnerIndex, c);
530 mainPane.add(spinnerIndex);
531
532 c.gridx = 1;
533 c.gridy = 2;
534 c.insets = new Insets(12, 3, 3, 64);
535 gridbag.setConstraints(cbEngine, c);
536 mainPane.add(cbEngine);
537
538 c.gridx = 1;
539 c.gridy = 3;
540 c.insets = new Insets(3, 3, 3, 64);
541 gridbag.setConstraints(cbLoadMode, c);
542 mainPane.add(cbLoadMode);
543
544 JPanel p2 = new JPanel();
545 p2.setOpaque(false);
546 c.gridx = 0;
547 c.gridy = 4;
548 c.fill = GridBagConstraints.VERTICAL;
549 c.weightx = 0.0;
550 c.weighty = 1.0;
551 gridbag.setConstraints(p2, c);
552 mainPane.add(p2);
553
554 setMainPane(mainPane);
555
556 cbFilename.setEditable(true);
557 String[] files = preferences().getStringListProperty("recentInstrumentFiles");
558 for(String s : files) cbFilename.addItem(s);
559 cbFilename.setSelectedItem(null);
560
561 cbFilename.addActionListener(new ActionListener() {
562 public void
563 actionPerformed(ActionEvent e) { updateState(); }
564 });
565
566 btnBrowse.addActionListener(new ActionListener() {
567 public void
568 actionPerformed(ActionEvent e) { onBrowse(); }
569 });
570
571 for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e);
572
573 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT);
574 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND);
575 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD);
576 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT);
577
578 int i = preferences().getIntProperty("std.midiInstrument.loadMode", 0);
579 if(cbLoadMode.getItemCount() > i) cbLoadMode.setSelectedIndex(i);
580
581 cbLoadMode.addActionListener(new ActionListener() {
582 public void
583 actionPerformed(ActionEvent e) {
584 int j = cbLoadMode.getSelectedIndex();
585 if(j < 0) return;
586 preferences().setIntProperty("std.midiInstrument.loadMode", j);
587 }
588 });
589 }
590
591 protected JSPrefs
592 preferences() { return CC.getViewConfig().preferences(); }
593
594 private void
595 onBrowse() {
596 String s = preferences().getStringProperty("lastInstrumentLocation");
597 JFileChooser fc = new JFileChooser(s);
598 int result = fc.showOpenDialog(this);
599 if(result != JFileChooser.APPROVE_OPTION) return;
600
601 String path = fc.getSelectedFile().getAbsolutePath();
602 if(java.io.File.separatorChar == '\\') {
603 path.replace('\\', '/');
604 }
605 cbFilename.setSelectedItem(toEscapedString(path));
606 path = fc.getCurrentDirectory().getAbsolutePath();
607 preferences().setStringProperty("lastInstrumentLocation", path);
608 }
609
610 private void
611 updateState() {
612 boolean b = false;
613 Object o = cbFilename.getSelectedItem();
614 if(o == null) b = false;
615 else b = o.toString().length() > 0;
616 getWizard().enableNextButton(b);
617 }
618
619 public void
620 postinitPage() {
621 updateState();
622 }
623
624 /**
625 * Gets the name of the instrument file.
626 * @return The name of the instrument file.
627 */
628 public String
629 getSelectedFile() { return cbFilename.getSelectedItem().toString(); }
630
631 /**
632 * Gets the index of the instrument in the instrument file.
633 * @return The index of the instrument in the instrument file.
634 */
635 public int
636 getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); }
637
638 /**
639 * Gets the selected engine.
640 */
641 public String
642 getEngine() { return ((SamplerEngine)cbEngine.getSelectedItem()).getName(); }
643
644 /**
645 * Gets the selected load mode.
646 */
647 public MidiInstrumentInfo.LoadMode
648 getLoadMode() { return (MidiInstrumentInfo.LoadMode)cbLoadMode.getSelectedItem(); }
649
650 private final Handler eventHandler = new Handler();
651
652 private Handler
653 getHandler() { return eventHandler; }
654
655 private class Handler implements DocumentListener {
656 // DocumentListener
657 public void
658 insertUpdate(DocumentEvent e) { updateState(); }
659
660 public void
661 removeUpdate(DocumentEvent e) { updateState(); }
662
663 public void
664 changedUpdate(DocumentEvent e) { updateState(); }
665 }
666 }
667
668 class InstrumentMappingWizardPage extends WizardPage {
669 private final JLabel lName = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lName"));
670 private final JLabel lMap = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lMap"));
671 private final JLabel lBank = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lBank"));
672 private final JLabel lProgram =
673 new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lProgram"));
674
675 private final JLabel lVolume =
676 new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lVolume"));
677
678 private final JTextField tfName = new JTextField();
679 private final JComboBox cbMap = new JComboBox();
680 private final JSpinner spinnerBank = new JSpinner(new SpinnerNumberModel(0, 0, 16383, 1));
681 private final JComboBox cbProgram = new JComboBox();
682 private final JSlider slVolume = new JSlider(0, 100, 100);
683
684 private final NewMidiInstrumentWizardModel wizardModel;
685
686 InstrumentMappingWizardPage(NewMidiInstrumentWizardModel wizardModel) {
687 super(i18n.getLabel("InstrumentMappingWizardPage.subtitle"));
688 this.wizardModel = wizardModel;
689
690 setPageType(Type.CONFIRMATION_PAGE);
691
692 GridBagLayout gridbag = new GridBagLayout();
693 GridBagConstraints c = new GridBagConstraints();
694
695 setLayout(gridbag);
696
697 c.fill = GridBagConstraints.NONE;
698
699 c.gridx = 0;
700 c.gridy = 0;
701 c.anchor = GridBagConstraints.EAST;
702 c.insets = new Insets(24, 3, 3, 0);
703 gridbag.setConstraints(lName, c);
704 add(lName);
705
706 c.gridx = 0;
707 c.gridy = 2;
708 c.insets = new Insets(3, 3, 3, 0);
709 gridbag.setConstraints(lMap, c);
710 add(lMap);
711
712 c.gridx = 0;
713 c.gridy = 3;
714 gridbag.setConstraints(lBank, c);
715 add(lBank);
716
717 c.gridx = 0;
718 c.gridy = 4;
719 gridbag.setConstraints(lProgram, c);
720 add(lProgram);
721
722 c.gridx = 0;
723 c.gridy = 1;
724 c.insets = new Insets(3, 3, 24, 0);
725 gridbag.setConstraints(lVolume, c);
726 add(lVolume);
727
728 c.fill = GridBagConstraints.HORIZONTAL;
729 c.gridx = 1;
730 c.gridy = 0;
731 c.weightx = 1.0;
732 c.insets = new Insets(24, 12, 3, 36);
733 c.anchor = GridBagConstraints.WEST;
734 gridbag.setConstraints(tfName, c);
735 add(tfName);
736
737 c.gridx = 1;
738 c.gridy = 2;
739 c.insets = new Insets(3, 12, 3, 36);
740 gridbag.setConstraints(cbMap, c);
741 add(cbMap);
742
743 c.gridx = 1;
744 c.gridy = 3;
745 gridbag.setConstraints(spinnerBank, c);
746 add(spinnerBank);
747
748 c.gridx = 1;
749 c.gridy = 4;
750 gridbag.setConstraints(cbProgram, c);
751 add(cbProgram);
752
753 c.gridx = 1;
754 c.gridy = 1;
755 c.insets = new Insets(3, 12, 24, 36);
756 gridbag.setConstraints(slVolume, c);
757 add(slVolume);
758
759 JPanel p2 = new JPanel();
760 p2.setOpaque(false);
761 c.gridx = 0;
762 c.gridy = 5;
763 c.insets = new Insets(0, 0, 0, 0);
764 c.fill = GridBagConstraints.VERTICAL;
765 c.weightx = 0.0;
766 c.weighty = 1.0;
767 gridbag.setConstraints(p2, c);
768 add(p2);
769
770 cbMap.addActionListener(new ActionListener() {
771 public void
772 actionPerformed(ActionEvent e) { updateState(); }
773 });
774
775 for(MidiInstrumentMap m : CC.getSamplerModel().getMidiInstrumentMaps()) {
776 cbMap.addItem(m);
777 }
778
779 tfName.getDocument().addDocumentListener(getHandler());
780
781 cbMap.setEnabled(cbMap.getItemCount() > 0);
782
783
784 for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i));
785
786 cbMap.addActionListener(new ActionListener() {
787 public void
788 actionPerformed(ActionEvent e) { updateMapping(); }
789 });
790
791 updateMapping();
792 }
793
794 protected JSPrefs
795 preferences() { return CC.getViewConfig().preferences(); }
796
797 private void
798 updateState() {
799 cbMap.setEnabled(cbMap.getItemCount() > 0);
800 boolean b = cbMap.getSelectedItem() != null;
801 spinnerBank.setEnabled(b);
802 cbProgram.setEnabled(b);
803
804 b = tfName.getText().length() > 0 && cbMap.getSelectedItem() != null;
805 b = b && cbProgram.getSelectedItem() != null;
806 if(getWizard() != null) getWizard().enableFinishButton(b);
807 }
808
809 private void
810 updateMapping() {
811 if(cbMap.getSelectedItem() == null) return;
812 MidiInstrumentMap map = (MidiInstrumentMap)cbMap.getSelectedItem();
813 MidiInstrumentEntry entry = map.getAvailableEntry();
814 if(entry == null) return;
815 spinnerBank.setValue(entry.getMidiBank());
816 cbProgram.setSelectedIndex(entry.getMidiProgram());
817 }
818
819 public void
820 postinitPage() {
821 String s = wizardModel.getInstrumentName();
822 if(s != null) tfName.setText(s);
823 if(wizardModel.getDefaultMap() != null) {
824 cbMap.setSelectedItem(wizardModel.getDefaultMap());
825 }
826 updateState();
827 }
828
829 /**
830 * Invoked when the user clicks the 'Finish' button
831 * while this page is the current page of the wizard.
832 * @return <code>true</code>
833 */
834 public boolean
835 mayFinish() {
836 ((NewMidiInstrumentWizardModel)getWizardModel()).mapInstrument();
837 preferences().setIntProperty("lastUsedMidiBank", getMidiBank());
838 return true;
839 }
840
841 /**
842 * Gets the ID of the selected MIDI instrument map.
843 */
844 public int
845 getMapId() { return ((MidiInstrumentMap)cbMap.getSelectedItem()).getMapId(); }
846
847 /**
848 * Gets the selected MIDI bank.
849 */
850 public int
851 getMidiBank() { return Integer.parseInt(spinnerBank.getValue().toString()); }
852
853 /**
854 * Gets the selected MIDI program.
855 */
856 public int
857 getMidiProgram() { return cbProgram.getSelectedIndex(); }
858
859 /**
860 * Gets the chosen name for the new MIDI instrument.
861 * @return The chosen name for the new MIDI instrument.
862 */
863 public String
864 getInstrumentName() { return tfName.getText(); }
865
866 /**
867 * Returns the volume level of the new MIDI instrument.
868 * @return The volume level of the new MIDI instrument.
869 */
870 public float
871 getVolume() {
872 float f = slVolume.getValue();
873 f /= 100;
874 return f;
875 }
876
877 private final Handler eventHandler = new Handler();
878
879 private Handler
880 getHandler() { return eventHandler; }
881
882 private class Handler implements DocumentListener {
883 // DocumentListener
884 public void
885 insertUpdate(DocumentEvent e) { updateState(); }
886
887 public void
888 removeUpdate(DocumentEvent e) { updateState(); }
889
890 public void
891 changedUpdate(DocumentEvent e) { updateState(); }
892 }
893 }

  ViewVC Help
Powered by ViewVC