/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/NormalChannelOptionsView.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/NormalChannelOptionsView.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2146 - (show annotations) (download)
Mon Oct 11 09:31:27 2010 UTC (13 years, 6 months ago) by iliev
File size: 20190 byte(s)
* Fantasia: Migrated to substance 6.1
* Fantasia: Some minor GUI enhancements

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2010 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.fantasia;
24
25 import java.awt.BorderLayout;
26 import java.awt.Dimension;
27 import java.awt.Insets;
28
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31
32 import java.util.logging.Level;
33
34 import javax.swing.BorderFactory;
35 import javax.swing.Box;
36 import javax.swing.BoxLayout;
37 import javax.swing.JComboBox;
38 import javax.swing.JComponent;
39 import javax.swing.JLabel;
40 import javax.swing.JPanel;
41 import javax.swing.SwingConstants;
42
43 import org.jsampler.AudioDeviceModel;
44 import org.jsampler.CC;
45 import org.jsampler.MidiDeviceModel;
46 import org.jsampler.MidiInstrumentMap;
47 import org.jsampler.SamplerModel;
48
49 import org.jsampler.event.ListEvent;
50 import org.jsampler.event.ListListener;
51 import org.jsampler.event.MidiDeviceEvent;
52 import org.jsampler.event.MidiDeviceListEvent;
53 import org.jsampler.event.MidiDeviceListListener;
54 import org.jsampler.event.MidiDeviceListener;
55 import org.jsampler.event.SamplerAdapter;
56 import org.jsampler.event.SamplerChannelAdapter;
57 import org.jsampler.event.SamplerChannelEvent;
58 import org.jsampler.event.SamplerEvent;
59 import org.jsampler.event.SamplerListener;
60
61 import org.jsampler.view.fantasia.basic.*;
62 import org.jsampler.view.std.JSChannelOutputRoutingDlg;
63
64 import org.linuxsampler.lscp.AudioOutputDevice;
65 import org.linuxsampler.lscp.MidiInputDevice;
66 import org.linuxsampler.lscp.MidiPort;
67 import org.linuxsampler.lscp.SamplerChannel;
68
69 import org.pushingpixels.substance.api.SubstanceLookAndFeel;
70
71 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
72
73 /**
74 *
75 * @author Grigor Iliev
76 */
77 public class NormalChannelOptionsView extends JPanel implements ChannelOptionsView {
78 private final Channel channel;
79 private MidiDeviceModel midiDevice = null;
80
81 private final JComboBox cbMidiDevice = new FantasiaComboBox();
82 private final JComboBox cbMidiPort = new FantasiaComboBox();
83 private final JComboBox cbMidiChannel = new FantasiaComboBox();
84 private final JComboBox cbInstrumentMap = new FantasiaComboBox();
85 private final JComboBox cbAudioDevice = new FantasiaComboBox();
86
87 private final PixmapButton btnChannelRouting;
88
89 private boolean update = false;
90
91 private final SamplerListener samplerListener;
92 private final MapListListener mapListListener = new MapListListener();
93
94 private class NoMap {
95 public String
96 toString() { return "[None]"; }
97 }
98
99 private NoMap noMap = new NoMap();
100
101 private class DefaultMap {
102 public String
103 toString() { return "[Default]"; }
104 }
105
106 private DefaultMap defaultMap = new DefaultMap();
107
108 /** Creates a new instance of <code>NormalChannelOptionsView</code> */
109 public
110 NormalChannelOptionsView(final Channel channel) {
111 setLayout(new BorderLayout());
112 PixmapPane bgp = new PixmapPane(Res.gfxChannelOptions);
113 bgp.setPixmapInsets(new Insets(1, 1, 1, 1));
114
115 this.channel = channel;
116
117 bgp.setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4));
118 bgp.setLayout(new BoxLayout(bgp, BoxLayout.X_AXIS));
119
120 bgp.setPreferredSize(new Dimension(420, 44));
121 bgp.setMinimumSize(getPreferredSize());
122 bgp.setMaximumSize(getPreferredSize());
123
124 JPanel p = new FantasiaPanel();
125 p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));
126 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
127 JLabel l = new JLabel(Res.gfxMidiInputTitle);
128 l.setAlignmentX(LEFT_ALIGNMENT);
129 p.add(l);
130
131 JPanel p2 = new FantasiaPanel();
132 p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
133 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
134
135 Object o = cbMidiDevice.getRenderer();
136 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);
137
138 cbMidiDevice.setPreferredSize(new Dimension(40, 18));
139 cbMidiDevice.setMinimumSize(cbMidiDevice.getPreferredSize());
140 cbMidiDevice.setMaximumSize(cbMidiDevice.getPreferredSize());
141 p2.add(cbMidiDevice);
142
143 p2.add(Box.createRigidArea(new Dimension(3, 0)));
144
145 o = cbMidiPort.getRenderer();
146 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.LEFT);
147
148 cbMidiPort.addActionListener(new ActionListener() {
149 public void
150 actionPerformed(ActionEvent e) {
151 updateCbMidiPortToolTipText();
152 }
153 });
154
155 cbMidiPort.setPreferredSize(new Dimension(62, 18));
156 cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize());
157 cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize());
158 p2.add(cbMidiPort);
159
160 p2.add(Box.createRigidArea(new Dimension(3, 0)));
161
162 o = cbMidiChannel.getRenderer();
163 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);
164
165 cbMidiChannel.addItem("All");
166 for(int i = 1; i <= 16; i++) cbMidiChannel.addItem("Channel " + String.valueOf(i));
167 cbMidiChannel.setPreferredSize(new Dimension(84, 18));
168 cbMidiChannel.setMinimumSize(cbMidiChannel.getPreferredSize());
169 cbMidiChannel.setMaximumSize(cbMidiChannel.getPreferredSize());
170
171 p2.add(cbMidiChannel);
172 p2.setAlignmentX(LEFT_ALIGNMENT);
173 p2.setOpaque(false);
174 p.add(p2);
175 p.setBackground(new java.awt.Color(0x818181));
176
177 bgp.add(p);
178
179 bgp.add(Box.createRigidArea(new Dimension(4, 0)));
180
181 p = new FantasiaPanel();
182 p.setOpaque(true);
183 p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));
184 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
185 l = new JLabel(Res.gfxInstrumentMapTitle);
186 l.setAlignmentX(LEFT_ALIGNMENT);
187 l.setAlignmentX(LEFT_ALIGNMENT);
188 p.add(l);
189
190 p.add(Box.createRigidArea(new Dimension(0, 3)));
191
192 //o = cbInstrumentMap.getRenderer();
193 //if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);
194
195 cbInstrumentMap.setPreferredSize(new Dimension(122, 18));
196 cbInstrumentMap.setMinimumSize(cbInstrumentMap.getPreferredSize());
197 cbInstrumentMap.setMaximumSize(cbInstrumentMap.getPreferredSize());
198 cbInstrumentMap.setAlignmentX(LEFT_ALIGNMENT);
199 p.add(cbInstrumentMap);
200 p.setBackground(new java.awt.Color(0x818181));
201 bgp.add(p);
202
203 bgp.add(Box.createRigidArea(new Dimension(4, 0)));
204
205 p = new FantasiaPanel();
206 p.setOpaque(true);
207 p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));
208 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
209 l = new JLabel(Res.gfxAudioOutputTitle);
210 l.setAlignmentX(LEFT_ALIGNMENT);
211 p.add(l);
212
213 //p.add(Box.createRigidArea(new Dimension(0, 3)));
214
215 p2 = new FantasiaPanel();
216 p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
217 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
218 p2.setOpaque(false);
219 p2.setAlignmentX(LEFT_ALIGNMENT);
220
221 o = cbAudioDevice.getRenderer();
222 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT);
223
224 cbAudioDevice.setPreferredSize(new Dimension(40, 18));
225 cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize());
226 cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize());
227
228 p2.add(cbAudioDevice);
229 p2.add(Box.createRigidArea(new Dimension(3, 0)));
230 btnChannelRouting = new PixmapButton(Res.gfxBtnCr, Res.gfxBtnCrRO);
231 btnChannelRouting.setPressedIcon(Res.gfxBtnCrRO);
232 btnChannelRouting.setEnabled(false);
233 btnChannelRouting.setToolTipText(i18n.getLabel("ChannelOptions.routing"));
234
235 btnChannelRouting.addActionListener(new ActionListener() {
236 public void
237 actionPerformed(ActionEvent e) {
238 SamplerChannel c = channel.getChannelInfo();
239 new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
240
241 }
242 });
243
244 p2.add(btnChannelRouting);
245
246 p.add(p2);
247 p.setBackground(new java.awt.Color(0x818181));
248 p2 = new FantasiaPanel();
249 p2.setLayout(new java.awt.BorderLayout());
250 p.add(p2);
251 bgp.add(p);
252
253 add(bgp);
254
255 cbMidiDevice.addActionListener(new ActionListener() {
256 public void
257 actionPerformed(ActionEvent e) { setMidiDevice(); }
258 });
259
260 cbMidiPort.addActionListener(new ActionListener() {
261 public void
262 actionPerformed(ActionEvent e) { setMidiPort(); }
263 });
264
265 cbMidiChannel.addActionListener(new ActionListener() {
266 public void
267 actionPerformed(ActionEvent e) { setMidiChannel(); }
268 });
269
270 samplerListener = new SamplerAdapter() {
271 /** Invoked when the default MIDI instrument map is changed. */
272 public void
273 defaultMapChanged(SamplerEvent e) {
274 updateCbInstrumentMapToolTipText();
275
276 }
277 };
278
279 CC.getSamplerModel().addSamplerListener(samplerListener);
280
281 cbInstrumentMap.addItem(noMap);
282 cbInstrumentMap.addItem(defaultMap);
283 for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) {
284 cbInstrumentMap.addItem(map);
285 }
286
287 int map = channel.getModel().getChannelInfo().getMidiInstrumentMapId();
288 cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map));
289 if(cbInstrumentMap.getSelectedItem() == null) {
290 if(map == -1) cbInstrumentMap.setSelectedItem(noMap);
291 else if(map == -2) {
292 cbInstrumentMap.setSelectedItem(defaultMap);
293 }
294 }
295
296 updateCbInstrumentMapToolTipText();
297
298 if(channel.getModel().getChannelInfo().getEngine() == null) {
299 cbInstrumentMap.setEnabled(false);
300 }
301
302 cbInstrumentMap.addActionListener(new ActionListener() {
303 public void
304 actionPerformed(ActionEvent e) { updateInstrumentMap(); }
305 });
306
307 CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
308
309 cbAudioDevice.addActionListener(new ActionListener() {
310 public void
311 actionPerformed(ActionEvent e) { setBackendAudioDevice(); }
312 });
313
314 channel.getModel().addSamplerChannelListener(new SamplerChannelAdapter() {
315 public void
316 channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }
317 });
318
319 CC.getSamplerModel().addMidiDeviceListListener(getHandler());
320 CC.getSamplerModel().addAudioDeviceListListener(getHandler());
321
322 updateMidiDevices();
323 updateAudioDevices();
324 updateChannelProperties();
325 }
326
327 //////////////////////////////////////////////
328 // Implementation of the ChannelOptionsView interface
329 //////////////////////////////////////////////
330
331 public JComponent
332 getComponent() { return this; }
333
334 public void
335 installView() { }
336
337 public void
338 uninstallView() {
339 onDestroy();
340 }
341
342 public void
343 updateChannelInfo() {
344
345 }
346
347 //////////////////////////////////////////////
348
349 /**
350 * Updates the channel settings. This method is invoked when changes to the
351 * channel were made.
352 */
353 private void
354 updateChannelProperties() {
355 SamplerModel sm = CC.getSamplerModel();
356 SamplerChannel sc = channel.getModel().getChannelInfo();
357
358 MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice());
359 AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice());
360
361 if(isUpdate()) CC.getLogger().warning("Unexpected update state!");
362
363 setUpdate(true);
364
365 try {
366 cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());
367
368 cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
369 btnChannelRouting.setEnabled(am != null);
370 } catch(Exception x) {
371 CC.getLogger().log(Level.WARNING, "Unkown error", x);
372 }
373
374 if(sc.getEngine() != null) {
375 cbInstrumentMap.setEnabled(true);
376 int id = sc.getMidiInstrumentMapId();
377 Object o;
378 if(id == -2) o = defaultMap;
379 else if(id == -1) o = noMap;
380 else o = CC.getSamplerModel().getMidiInstrumentMapById(id);
381
382 if(cbInstrumentMap.getSelectedItem() != o) {
383 cbInstrumentMap.setSelectedItem(o);
384 }
385 } else {
386 cbInstrumentMap.setSelectedItem(noMap);
387 cbInstrumentMap.setEnabled(false);
388 }
389
390 setUpdate(false);
391 }
392
393 /**
394 * Updates the MIDI device list.
395 */
396 private void
397 updateMidiDevices() {
398 SamplerModel sm = CC.getSamplerModel();
399 SamplerChannel sc = channel.getModel().getChannelInfo();
400
401 setUpdate(true);
402
403 try {
404 cbMidiDevice.removeAllItems();
405
406 for(MidiDeviceModel m : sm.getMidiDevices())
407 cbMidiDevice.addItem(m.getDeviceInfo());
408
409 MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice());
410 cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());
411 } catch(Exception x) {
412 CC.getLogger().log(Level.WARNING, "Unkown error", x);
413 }
414
415 setUpdate(false);
416 }
417
418
419 private void
420 updateInstrumentMap() {
421 updateCbInstrumentMapToolTipText();
422
423 int id = channel.getModel().getChannelInfo().getMidiInstrumentMapId();
424 Object o = cbInstrumentMap.getSelectedItem();
425 if(o == null && id == -1) return;
426
427 int cbId;
428 if(o == null || o == noMap) cbId = -1;
429 else if(o == defaultMap) cbId = -2;
430 else cbId = ((MidiInstrumentMap)o).getMapId();
431
432 if(cbId == id) return;
433
434 channel.getModel().setBackendMidiInstrumentMap(cbId);
435 }
436
437 private void
438 updateCbMidiPortToolTipText() {
439 if(cbMidiPort.getSelectedItem() == null) {
440 cbMidiPort.setToolTipText(null);
441 return;
442 }
443
444 cbMidiPort.setToolTipText(cbMidiPort.getSelectedItem().toString());
445 }
446
447 private void
448 updateCbInstrumentMapToolTipText() {
449 if(cbInstrumentMap.getSelectedItem() != defaultMap) {
450 cbInstrumentMap.setToolTipText(null);
451 return;
452 }
453
454 MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap();
455 if(m != null) {
456 String s = i18n.getLabel("Channel.ttDefault", m.getName());
457 cbInstrumentMap.setToolTipText(s);
458 } else {
459 cbInstrumentMap.setToolTipText(null);
460 }
461 }
462
463 /**
464 * Updates the audio device list.
465 */
466 private void
467 updateAudioDevices() {
468 SamplerModel sm = CC.getSamplerModel();
469 SamplerChannel sc = channel.getModel().getChannelInfo();
470
471 setUpdate(true);
472
473 try {
474 cbAudioDevice.removeAllItems();
475
476 for(AudioDeviceModel m : sm.getAudioDevices())
477 cbAudioDevice.addItem(m.getDeviceInfo());
478
479 AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice());
480 cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
481 } catch(Exception x) {
482 CC.getLogger().log(Level.WARNING, "Unkown error", x);
483 }
484
485 setUpdate(false);
486 }
487
488 private void
489 setMidiDevice() {
490 MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();
491
492 if(!isUpdate()) {
493 if(mid != null) {
494 channel.getModel().setBackendMidiInputDevice(mid.getDeviceId());
495 }
496
497 return;
498 }
499
500 if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler());
501
502 cbMidiPort.removeAllItems();
503
504 if(mid == null) {
505 midiDevice = null;
506 cbMidiPort.setEnabled(false);
507
508 cbMidiChannel.setSelectedItem(null);
509 cbMidiChannel.setEnabled(false);
510 } else {
511 midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId());
512 if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler());
513
514 cbMidiPort.setEnabled(true);
515
516 MidiPort[] ports = mid.getMidiPorts();
517 for(MidiPort port : ports) cbMidiPort.addItem(port);
518
519 int p = channel.getModel().getChannelInfo().getMidiInputPort();
520 cbMidiPort.setSelectedItem(p >= 0 && p < ports.length ? ports[p] : null);
521
522 cbMidiPort.putClientProperty (
523 SubstanceLookAndFeel.COMBO_POPUP_PROTOTYPE,
524 new FantasiaComboBox.WidestComboPopupPrototype()
525 );
526
527 cbMidiChannel.setEnabled(true);
528 int c = channel.getModel().getChannelInfo().getMidiInputChannel();
529 cbMidiChannel.setSelectedItem(c == -1 ? "All" : "Channel " + (c + 1));
530 }
531 }
532
533 private void
534 setMidiPort() {
535 if(isUpdate()) return;
536
537 channel.getModel().setBackendMidiInputPort(cbMidiPort.getSelectedIndex());
538 }
539
540 private void
541 setMidiChannel() {
542 if(isUpdate()) return;
543
544 Object o = cbMidiChannel.getSelectedItem();
545 if(o == null) return;
546 String s = o.toString();
547
548 int c = s.equals("All") ? -1 : Integer.parseInt(s.substring(8)) - 1;
549
550 channel.getModel().setBackendMidiInputChannel(c);
551 }
552
553 private void
554 setBackendAudioDevice() {
555 if(isUpdate()) return;
556 AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();
557 if(dev != null) channel.getModel().setBackendAudioOutputDevice(dev.getDeviceId());
558 }
559
560 /**
561 * Determines whether the currently processed changes are due to update.
562 * @return <code>true</code> if the currently processed changes are due to update and
563 * <code>false</code> if the currently processed changes are due to user input.
564 */
565 private boolean
566 isUpdate() { return update; }
567
568 /**
569 * Sets whether the currently processed changes are due to update.
570 * @param b Specify <code>true</code> to indicate that the currently
571 * processed changes are due to update; <code>false</code>
572 * indicates that the currently processed changes are due to user input.
573 */
574 private void
575 setUpdate(boolean b) { update = b; }
576
577 protected void
578 onDestroy() {
579 SamplerModel sm = CC.getSamplerModel();
580
581 sm.removeMidiDeviceListListener(getHandler());
582 sm.removeAudioDeviceListListener(getHandler());
583 sm.removeMidiInstrumentMapListListener(mapListListener);
584 sm.removeSamplerListener(samplerListener);
585
586 if(midiDevice != null) {
587 midiDevice.removeMidiDeviceListener(getHandler());
588 }
589 }
590
591 private final Handler handler = new Handler();
592
593 private Handler
594 getHandler() { return handler; }
595
596 private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
597 MidiDeviceListener {
598 /**
599 * Invoked when a new MIDI device is created.
600 * @param e A <code>MidiDeviceListEvent</code>
601 * instance providing the event information.
602 */
603 @Override
604 public void
605 deviceAdded(MidiDeviceListEvent e) {
606 cbMidiDevice.addItem(e.getMidiDeviceModel().getDeviceInfo());
607 }
608
609 /**
610 * Invoked when a MIDI device is removed.
611 * @param e A <code>MidiDeviceListEvent</code>
612 * instance providing the event information.
613 */
614 @Override
615 public void
616 deviceRemoved(MidiDeviceListEvent e) {
617 cbMidiDevice.removeItem(e.getMidiDeviceModel().getDeviceInfo());
618 }
619
620 /**
621 * Invoked when a new audio device is created.
622 * @param e An <code>AudioDeviceListEvent</code>
623 * instance providing the event information.
624 */
625 @Override
626 public void
627 entryAdded(ListEvent<AudioDeviceModel> e) {
628 cbAudioDevice.addItem(e.getEntry().getDeviceInfo());
629 }
630
631 /**
632 * Invoked when an audio device is removed.
633 * @param e An <code>AudioDeviceListEvent</code>
634 * instance providing the event information.
635 */
636 @Override
637 public void
638 entryRemoved(ListEvent<AudioDeviceModel> e) {
639 cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
640 }
641
642 @Override
643 public void
644 settingsChanged(MidiDeviceEvent e) {
645 if(isUpdate()) {
646 CC.getLogger().warning("Invalid update state");
647 return;
648 }
649
650 setUpdate(true);
651 int idx = cbMidiPort.getSelectedIndex();
652 MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
653
654 cbMidiPort.removeAllItems();
655 for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port);
656
657 if(idx >= cbMidiPort.getModel().getSize()) idx = 0;
658
659 setUpdate(false);
660
661 if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx);
662 }
663 }
664
665 private class MapListListener implements ListListener<MidiInstrumentMap> {
666 /** Invoked when a new MIDI instrument map is added to a list. */
667 @Override
668 public void
669 entryAdded(ListEvent<MidiInstrumentMap> e) {
670 cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());
671 boolean b = channel.getModel().getChannelInfo().getEngine() != null;
672 if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);
673 }
674
675 /** Invoked when a new MIDI instrument map is removed from a list. */
676 @Override
677 public void
678 entryRemoved(ListEvent<MidiInstrumentMap> e) {
679 cbInstrumentMap.removeItem(e.getEntry());
680 if(cbInstrumentMap.getItemCount() == 0) { // TODO: ?
681 cbInstrumentMap.setSelectedItem(noMap);
682 cbInstrumentMap.setEnabled(false);
683 }
684 }
685 }
686 }

  ViewVC Help
Powered by ViewVC