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

Diff of /jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1204 by iliev, Thu May 24 21:43:45 2007 UTC revision 1318 by iliev, Sat Sep 1 13:46:04 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 24  package org.jsampler.view.fantasia; Line 24  package org.jsampler.view.fantasia;
24    
25  import java.awt.Cursor;  import java.awt.Cursor;
26  import java.awt.Dimension;  import java.awt.Dimension;
27    import java.awt.Graphics;
28  import java.awt.Insets;  import java.awt.Insets;
29    
30  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
# Line 31  import java.awt.event.ActionListener; Line 32  import java.awt.event.ActionListener;
32  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
33  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
34    
35    import java.beans.PropertyChangeEvent;
36    import java.beans.PropertyChangeListener;
37    
38  import java.util.logging.Level;  import java.util.logging.Level;
39    
40    import javax.swing.Action;
41  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
42  import javax.swing.Box;  import javax.swing.Box;
43  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
# Line 40  import javax.swing.DefaultListCellRender Line 45  import javax.swing.DefaultListCellRender
45  import javax.swing.JButton;  import javax.swing.JButton;
46  import javax.swing.JComboBox;  import javax.swing.JComboBox;
47  import javax.swing.JLabel;  import javax.swing.JLabel;
48    import javax.swing.JMenuItem;
49  import javax.swing.JPanel;  import javax.swing.JPanel;
50    import javax.swing.JPopupMenu;
51  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
52    import javax.swing.JToolBar;
53  import javax.swing.SwingConstants;  import javax.swing.SwingConstants;
54    
55  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
56  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
57    
58  import net.sf.juife.Dial;  import net.sf.juife.Dial;
59    import net.sf.juife.InformationDialog;
60  import net.sf.juife.JuifeUtils;  import net.sf.juife.JuifeUtils;
61  import net.sf.juife.TitleBar;  import net.sf.juife.TitleBar;
62    
63    import org.jdesktop.swingx.JXCollapsiblePane;
64    
65  import org.jsampler.AudioDeviceModel;  import org.jsampler.AudioDeviceModel;
66  import org.jsampler.CC;  import org.jsampler.CC;
67  import org.jsampler.MidiDeviceModel;  import org.jsampler.MidiDeviceModel;
68    import org.jsampler.MidiInstrumentMap;
69  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
70  import org.jsampler.SamplerModel;  import org.jsampler.SamplerModel;
71    
72  import org.jsampler.event.ListEvent;  import org.jsampler.event.ListEvent;
73  import org.jsampler.event.ListListener;  import org.jsampler.event.ListListener;
74    import org.jsampler.event.MidiDeviceEvent;
75  import org.jsampler.event.MidiDeviceListEvent;  import org.jsampler.event.MidiDeviceListEvent;
76  import org.jsampler.event.MidiDeviceListListener;  import org.jsampler.event.MidiDeviceListListener;
77    import org.jsampler.event.MidiDeviceListener;
78    import org.jsampler.event.SamplerAdapter;
79  import org.jsampler.event.SamplerChannelAdapter;  import org.jsampler.event.SamplerChannelAdapter;
80  import org.jsampler.event.SamplerChannelEvent;  import org.jsampler.event.SamplerChannelEvent;
81    import org.jsampler.event.SamplerChannelListEvent;
82    import org.jsampler.event.SamplerChannelListListener;
83  import org.jsampler.event.SamplerChannelListener;  import org.jsampler.event.SamplerChannelListener;
84    import org.jsampler.event.SamplerEvent;
85    import org.jsampler.event.SamplerListener;
86    
87    import org.jsampler.view.std.JSChannelOutputRoutingDlg;
88    import org.jsampler.view.std.JSFxSendsPane;
89    import org.jsampler.view.std.JSInstrumentChooser;
90    
91    import org.jvnet.lafwidget.animation.FadeConfigurationManager;
92    import org.jvnet.lafwidget.animation.FadeKind;
93    
94    import org.jvnet.substance.SubstanceImageCreator;
95    import org.jvnet.substance.SubstanceLookAndFeel;
96    
97  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
98  import org.linuxsampler.lscp.MidiInputDevice;  import org.linuxsampler.lscp.MidiInputDevice;
# Line 72  import org.linuxsampler.lscp.SamplerChan Line 101  import org.linuxsampler.lscp.SamplerChan
101  import org.linuxsampler.lscp.SamplerEngine;  import org.linuxsampler.lscp.SamplerEngine;
102    
103  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
104    import static org.jsampler.view.fantasia.FantasiaPrefs.*;
105    
106    
107  /**  /**
# Line 79  import static org.jsampler.view.fantasia Line 109  import static org.jsampler.view.fantasia
109   * @author Grigor Iliev   * @author Grigor Iliev
110   */   */
111  public class Channel extends org.jsampler.view.JSChannel {  public class Channel extends org.jsampler.view.JSChannel {
112            private final JXCollapsiblePane mainPane;
113          private final ChannelScreen screen = new ChannelScreen(this);          private final ChannelScreen screen = new ChannelScreen(this);
114          private final ChannelOptions optionsPane = new ChannelOptions(this);          private final ChannelOptions optionsPane = new ChannelOptions(this);
115                    
# Line 99  public class Channel extends org.jsample Line 130  public class Channel extends org.jsample
130           */           */
131          public          public
132          Channel(SamplerChannelModel model) {          Channel(SamplerChannelModel model) {
133                    this(model, null);
134            }
135            
136            /**
137             * Creates a new instance of <code>Channel</code> using the specified
138             * non-<code>null</code> channel model.
139             * @param model The model to be used by this channel.
140             * @param listener A listener which is notified when the newly created
141             * channel is fully expanded on the screen.
142             * @throws IllegalArgumentException If the model is <code>null</code>.
143             */
144            public
145            Channel(SamplerChannelModel model, final ActionListener listener) {
146                  super(model);                  super(model);
147                                    
148                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
149                  JPanel p = new JPanel();                  ChannelPane p = new ChannelPane();
                 p.setName("Channel");  
150                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
151                                    
152                  //p.add(Box.createRigidArea(new Dimension(3, 0)));                  //p.add(Box.createRigidArea(new Dimension(3, 0)));
153                                    
154                  btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT);                  btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT);
155                                    
156                  TitleBar tb = new TitleBar();                  JPanel tb = new JPanel();
157                  tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4));                  tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4));
158                  tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));                  tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));
159                  tb.setOpaque(false);                  tb.setOpaque(false);
# Line 142  public class Channel extends org.jsample Line 185  public class Channel extends org.jsample
185                  p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));                  p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
186                  p2.setAlignmentY(JPanel.TOP_ALIGNMENT);                  p2.setAlignmentY(JPanel.TOP_ALIGNMENT);
187                  p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));                  p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
188                  p2.add(new JLabel(Res.iconMuteTitle));                  p2.add(new JLabel(Res.gfxMuteTitle));
189                  p2.add(btnMute);                  p2.add(btnMute);
190                  p2.add(new JLabel(Res.iconSoloTitle));                  p2.add(new JLabel(Res.gfxSoloTitle));
191                  p2.add(btnSolo);                  p2.add(btnSolo);
192                                    
193                  p.add(p2);                  p.add(p2);
# Line 156  public class Channel extends org.jsample Line 199  public class Channel extends org.jsample
199                  p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));                  p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
200                  p2.setAlignmentY(JPanel.TOP_ALIGNMENT);                  p2.setAlignmentY(JPanel.TOP_ALIGNMENT);
201                  p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));                  p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
202                  JLabel l = new JLabel(Res.iconVolumeTitle);                  JLabel l = new JLabel(Res.gfxVolumeTitle);
203                  l.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  l.setAlignmentX(JPanel.CENTER_ALIGNMENT);
204                  l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));                  l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
205                  p2.add(l);                  p2.add(l);
206                  dialVolume.setDialPixmap(Res.iconVolumeDial, 30, 330);                  dialVolume.setDialPixmap(Res.gfxVolumeDial, 30, 330);
207                  dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT);
208                  p2.add(dialVolume);                  p2.add(dialVolume);
209                  p.add(p2);                  p.add(p2);
# Line 172  public class Channel extends org.jsample Line 215  public class Channel extends org.jsample
215                  p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));                  p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
216                  p2.setAlignmentY(JPanel.TOP_ALIGNMENT);                  p2.setAlignmentY(JPanel.TOP_ALIGNMENT);
217                  p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0));                  p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0));
218                  l = new JLabel(Res.iconOptionsTitle);                  l = new JLabel(Res.gfxOptionsTitle);
219                  l.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  l.setAlignmentX(JPanel.CENTER_ALIGNMENT);
220                  l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));                  l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
221                  p2.add(l);                  p2.add(l);
# Line 191  public class Channel extends org.jsample Line 234  public class Channel extends org.jsample
234    
235                  p.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  p.setAlignmentX(JPanel.CENTER_ALIGNMENT);
236                  optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);
                 add(p);  
                 add(optionsPane);  
237                                    
238                  setOpaque(true);                  mainPane = new JXCollapsiblePane();
239                    mainPane.getContentPane().setLayout (
240                            new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)
241                    );
242                    
243                    mainPane.add(p);
244                    mainPane.add(optionsPane);
245                    
246                    setOpaque(false);
247                                    
248                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
249                                    
250                  updateChannelInfo();                  updateChannelInfo();
251                    
252                    add(mainPane);
253                    
254                    if(listener != null) {
255                            final String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
256                            mainPane.addPropertyChangeListener(s, new PropertyChangeListener() {
257                                    public void
258                                    propertyChange(PropertyChangeEvent e) {
259                                            if(e.getNewValue() == "expanded") {
260                                                    mainPane.removePropertyChangeListener(s, this);
261                                                    listener.actionPerformed(null);
262                                            }
263                                    }
264                            });
265                    }
266                    
267                    mainPane.setAnimated(false);
268                    mainPane.setCollapsed(true);
269                    mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
270                    mainPane.setCollapsed(false);
271                    
272                    preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
273                            public void
274                            propertyChange(PropertyChangeEvent e) {
275                                    mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
276                            }
277                    });
278                    
279                    if(listener != null) {
280                            javax.swing.SwingUtilities.invokeLater(new Runnable() {
281                                    public void
282                                    run() { listener.actionPerformed(null); }
283                            });
284                    }
285          }          }
286                    
287          private JPanel          private JPanel
288          createVSeparator() {          createVSeparator() {
289                  JPanel p = new JPanel();                  PixmapPane p = new PixmapPane(Res.gfxVLine);
                 p.setName("VSeparator");  
                 p.setOpaque(false);  
290                  p.setAlignmentY(JPanel.TOP_ALIGNMENT);                  p.setAlignmentY(JPanel.TOP_ALIGNMENT);
291                  p.setPreferredSize(new Dimension(2, 60));                  p.setPreferredSize(new Dimension(2, 60));
292                  p.setMinimumSize(p.getPreferredSize());                  p.setMinimumSize(p.getPreferredSize());
# Line 233  public class Channel extends org.jsample Line 314  public class Channel extends org.jsample
314                    
315          /** Shows the channel properties. */          /** Shows the channel properties. */
316          public void          public void
317          expandChannel() { if(!btnOptions.isSelected()) btnOptions.doClick(); }          expandChannel() { expandChannel(optionsPane.isAnimated()); }
318            
319            /** Shows the channel properties. */
320            public void
321            expandChannel(boolean animated) {
322                    if(btnOptions.isSelected()) return;
323                    
324                    boolean b = optionsPane.isAnimated();
325                    optionsPane.setAnimated(animated);
326                    btnOptions.doClick();
327                    optionsPane.setAnimated(b);
328            }
329                    
330                    
331          /** Invoked when the user changes the volume */          /** Invoked when the user changes the volume */
# Line 269  public class Channel extends org.jsample Line 361  public class Channel extends org.jsample
361                  screen.updateScreenInfo(sc);                  screen.updateScreenInfo(sc);
362                  updateMuteIcon(sc);                  updateMuteIcon(sc);
363                                    
364                  if(sc.isSoloChannel()) btnSolo.setIcon(Res.iconSoloOn);                  if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn);
365                  else btnSolo.setIcon(Res.iconSoloOff);                  else btnSolo.setIcon(Res.gfxSoloOff);
366                                    
367                  dialVolume.setValue((int)(sc.getVolume() * 100));                  dialVolume.setValue((int)(sc.getVolume() * 100));
368                                    
# Line 288  public class Channel extends org.jsample Line 380  public class Channel extends org.jsample
380           */           */
381          private void          private void
382          updateMuteIcon(SamplerChannel channel) {          updateMuteIcon(SamplerChannel channel) {
383                  if(channel.isMutedBySolo()) btnMute.setIcon(Res.iconMutedBySolo);                  if(channel.isMutedBySolo()) btnMute.setIcon(Res.gfxMutedBySolo);
384                  else if(channel.isMuted()) btnMute.setIcon(Res.iconMuteOn);                  else if(channel.isMuted()) btnMute.setIcon(Res.gfxMuteOn);
385                  else btnMute.setIcon(Res.iconMuteOff);                  else btnMute.setIcon(Res.gfxMuteOff);
386          }          }
387                    
388          private class EnhancedDial extends Dial {          private class EnhancedDial extends Dial {
# Line 357  public class Channel extends org.jsample Line 449  public class Channel extends org.jsample
449          }          }
450                    
451                    
452          private class PowerButton extends PixmapToggleButton implements ActionListener {          private class PowerButton extends PixmapToggleButton
453                            implements ActionListener, PropertyChangeListener {
454                    
455                  PowerButton() {                  PowerButton() {
456                          super(Res.iconPowerOff, Res.iconPowerOn);                          super(Res.gfxPowerOff, Res.gfxPowerOn);
457                                    
458                          setSelected(true);                          setSelected(true);
459                          addActionListener(this);                          addActionListener(this);
# Line 367  public class Channel extends org.jsample Line 461  public class Channel extends org.jsample
461                                    
462                  public void                  public void
463                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
464                          CC.getSamplerModel().removeBackendChannel(getChannelId());                          if(!mainPane.isAnimated()) {
465                                    CC.getSamplerModel().removeBackendChannel(getChannelId());
466                                    return;
467                            }
468                            
469                            String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
470                            mainPane.addPropertyChangeListener(s, this);
471                            mainPane.setCollapsed(true);
472                    }
473                    
474                    public void
475                    propertyChange(PropertyChangeEvent e) {
476                            if(e.getNewValue() == "collapsed") {
477                                    CC.getSamplerModel().removeBackendChannel(getChannelId());
478                            }
479                  }                  }
480                                    
481                  public boolean                  public boolean
# Line 376  public class Channel extends org.jsample Line 484  public class Channel extends org.jsample
484                    
485          private class MuteButton extends PixmapButton implements ActionListener {          private class MuteButton extends PixmapButton implements ActionListener {
486                  MuteButton() {                  MuteButton() {
487                          super(Res.iconMuteOff);                          super(Res.gfxMuteOff);
488                          setDisabledIcon(Res.iconMuteSoloDisabled);                          //setDisabledIcon(Res.gfxMuteSoloDisabled);
489                            setDisabledIcon (
490                                    SubstanceImageCreator.makeTransparent(this, Res.gfxMuteOff, 0.4)
491                            );
492                          addActionListener(this);                          addActionListener(this);
493                  }                  }
494                                    
# Line 394  public class Channel extends org.jsample Line 505  public class Channel extends org.jsample
505                                  b = false;                                  b = false;
506                                  boolean hasSolo = CC.getSamplerModel().hasSoloChannel();                                  boolean hasSolo = CC.getSamplerModel().hasSoloChannel();
507                                                    
508                                  if(sc.isSoloChannel() || !hasSolo) setIcon(Res.iconMuteOff);                                  if(sc.isSoloChannel() || !hasSolo) setIcon(Res.gfxMuteOff);
509                                  else setIcon(Res.iconMutedBySolo);                                  else setIcon(Res.gfxMutedBySolo);
510                          } else setIcon(Res.iconMuteOn);                          } else setIcon(Res.gfxMuteOn);
511                                                    
512                          Channel.this.getModel().setBackendMute(b);                          Channel.this.getModel().setBackendMute(b);
513                  }                  }
# Line 407  public class Channel extends org.jsample Line 518  public class Channel extends org.jsample
518                    
519          private class SoloButton extends PixmapButton implements ActionListener {          private class SoloButton extends PixmapButton implements ActionListener {
520                  SoloButton() {                  SoloButton() {
521                          super(Res.iconSoloOff);                          super(Res.gfxSoloOff);
522                          setDisabledIcon(Res.iconMuteSoloDisabled);                          //setDisabledIcon(Res.gfxMuteSoloDisabled);
523                            setDisabledIcon (
524                                    SubstanceImageCreator.makeTransparent(this, Res.gfxSoloOff, 0.4)
525                            );
526                          addActionListener(this);                          addActionListener(this);
527                  }                  }
528                                    
# Line 422  public class Channel extends org.jsample Line 536  public class Channel extends org.jsample
536                           * leaving the work to the notification mechanism of the LinuxSampler.                           * leaving the work to the notification mechanism of the LinuxSampler.
537                           */                           */
538                          if(b) {                          if(b) {
539                                  setIcon(Res.iconSoloOn);                                  setIcon(Res.gfxSoloOn);
540                                  if(sc.isMutedBySolo()) btnMute.setIcon(Res.iconMuteOff);                                  if(sc.isMutedBySolo()) btnMute.setIcon(Res.gfxMuteOff);
541                          } else {                          } else {
542                                  setIcon(Res.iconSoloOff);                                  setIcon(Res.gfxSoloOff);
543                                  if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1)                                  if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1)
544                                          btnMute.setIcon(Res.iconMutedBySolo);                                          btnMute.setIcon(Res.gfxMutedBySolo);
545                          }                          }
546                                    
547                          Channel.this.getModel().setBackendSolo(b);                          Channel.this.getModel().setBackendSolo(b);
# Line 439  public class Channel extends org.jsample Line 553  public class Channel extends org.jsample
553                    
554          private class OptionsButton extends PixmapToggleButton implements ActionListener {          private class OptionsButton extends PixmapToggleButton implements ActionListener {
555                  OptionsButton() {                  OptionsButton() {
556                          super(Res.iconOptionsOff, Res.iconOptionsOn);                          super(Res.gfxOptionsOff, Res.gfxOptionsOn);
557                          setRolloverIcon(Res.iconOptionsOffRO);                          setRolloverIcon(Res.gfxOptionsOffRO);
558                          this.setRolloverSelectedIcon(Res.iconOptionsOnRO);                          this.setRolloverSelectedIcon(Res.gfxOptionsOnRO);
559                          addActionListener(this);                          addActionListener(this);
560                  }                  }
561                                    
# Line 458  public class Channel extends org.jsample Line 572  public class Channel extends org.jsample
572                                    
573                  private void                  private void
574                  showOptionsPane(boolean show) {                  showOptionsPane(boolean show) {
575                          optionsPane.setVisible(show);                          optionsPane.setCollapsed(!show);
                         MainFrame.repack(CC.getMainFrame());  
576                  }                  }
577                                    
578                  public boolean                  public boolean
# Line 467  public class Channel extends org.jsample Line 580  public class Channel extends org.jsample
580          }          }
581  }  }
582    
583  class ChannelScreen extends JPanel {  class ChannelPane extends PixmapPane {
584            ChannelPane() {
585                    super(Res.gfxChannel);
586                    setPixmapInsets(new Insets(3, 3, 3, 3));
587            }
588    }
589    
590    class ChannelScreen extends PixmapPane {
591          private final Channel channel;          private final Channel channel;
592          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
         private JButton btnReset = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnReset"));  
         private JButton btnDuplicate =  
                 new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnDuplicate"));  
           
         private final JLabel lVolume = new JLabel();  
         private final JLabel lStreams = new JLabel("--");  
         private final JLabel lVoices = new JLabel("--");  
593                    
594          ChannelScreen(Channel channel) {          private final JButton btnFxSends =
595                    new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
596            
597            private final JButton btnEngine
598                    = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine"));
599            
600            private final JPopupMenu menuEngines = new JPopupMenu();
601            
602            private final JLabel lVolume = new Label();
603            private final JLabel lStreams = new Label("--");
604            private final JLabel lVoices = new Label("--");
605            
606            private InformationDialog fxSendsDlg = null;
607            
608            private Dimension dimVolume;
609            
610            class Label extends JLabel {
611                    Label() { this(""); }
612                    
613                    Label(String s) {
614                            super(s);
615                            setFont(Res.fontScreen);
616                            setForeground(new java.awt.Color(0xFFA300));
617                    }
618            }
619            
620            ChannelScreen(final Channel channel) {
621                    super(Res.gfxChannelScreen);
622                    setPixmapInsets(new Insets(6, 6, 6, 6));
623                    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
624                    
625                  this.channel = channel;                  this.channel = channel;
626                                    
627                  setName("ChannelScreen");                  setOpaque(false);
                 setOpaque(true);  
628                                    
629                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
630                                    
                 btnInstr.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));  
631                  btnInstr.setAlignmentX(CENTER_ALIGNMENT);                  btnInstr.setAlignmentX(CENTER_ALIGNMENT);
632                    btnInstr.setRolloverEnabled(false);
633                    btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
634                                    
635                  add(btnInstr);                  add(btnInstr);
636                                    
637                  JPanel p = new JPanel();                  JPanel p = new JPanel();
                 p.setOpaque(false);  
638                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
639                  p.setAlignmentX(CENTER_ALIGNMENT);                  p.setAlignmentX(CENTER_ALIGNMENT);
640                  p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));                  p.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
                 //lVolume.setFont(lVolume.getFont().deriveFont(java.awt.Font.PLAIN));  
641                                    
642                  p.add(btnDuplicate);                  btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt"));
643                    btnFxSends.addActionListener(new ActionListener() {
644                            public void
645                            actionPerformed(ActionEvent e) {
646                                    if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
647                                            fxSendsDlg.toFront();
648                                            return;
649                                    }
650                                    FxSendsPane p = new FxSendsPane(channel.getModel());
651                                    int id = channel.getModel().getChannelId();
652                                    fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
653                                    fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id));
654                                    fxSendsDlg.setModal(false);
655                                    fxSendsDlg.showCloseButton(false);
656                                    fxSendsDlg.setVisible(true);
657                            }
658                    });
659                    
660                    p.add(btnFxSends);
661                                    
662                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  p.add(Box.createRigidArea(new Dimension(6, 0)));
663                                    
664                  p.add(new JLabel("|"));                  btnEngine.setIcon(Res.iconEngine12);
665                    p.add(btnEngine);
666                    //p.add(new Label("|"));
667                                    
668                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  //p.add(Box.createRigidArea(new Dimension(6, 0)));
669                                    
670                  p.add(btnReset);                  //p.add(btnReset);
671                                    
672                  p.add(Box.createGlue());                  p.add(Box.createGlue());
673                                    
674                  p.add(lStreams);                  p.add(lStreams);
675                  p.add(new JLabel("/"));                  p.add(new Label("/"));
676                  p.add(lVoices);                  p.add(lVoices);
677                                    
678                  p.add(Box.createRigidArea(new Dimension(12, 0)));                  p.add(Box.createRigidArea(new Dimension(12, 0)));
679                                    
680                    lVolume.setIcon(Res.iconVolume14);
681                  lVolume.setAlignmentX(RIGHT_ALIGNMENT);                  lVolume.setAlignmentX(RIGHT_ALIGNMENT);
682                    updateVolumeInfo(100);
683                    dimVolume = lVolume.getPreferredSize();
684                  p.add(lVolume);                  p.add(lVolume);
685                  p.setPreferredSize(new Dimension(250, p.getPreferredSize().height));                  p.setPreferredSize(new Dimension(250, p.getPreferredSize().height));
686                  p.setMinimumSize(p.getPreferredSize());                  p.setMinimumSize(p.getPreferredSize());
687                  p.setMaximumSize(p.getPreferredSize());                  p.setMaximumSize(p.getPreferredSize());
688                                    
689                    //btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
690                    p.setOpaque(false);
691                  add(p);                  add(p);
692                                    
693                                    
# Line 529  class ChannelScreen extends JPanel { Line 695  class ChannelScreen extends JPanel {
695                  setMinimumSize(getPreferredSize());                  setMinimumSize(getPreferredSize());
696                  setMaximumSize(getPreferredSize());                  setMaximumSize(getPreferredSize());
697                                    
698                    createEngineMenu();
699                  installListeners();                  installListeners();
700          }          }
701                    
702          private void          private void
703            createEngineMenu() {
704                    for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
705                            JMenuItem mi = new JMenuItem(engine.getDescription());
706                            
707                            mi.addActionListener(new ActionListener() {
708                                    public void
709                                    actionPerformed(ActionEvent e) {
710                                            channel.getModel().setBackendEngineType(engine.getName());
711                                    }
712                            });
713                            
714                            menuEngines.add(mi);
715                    }
716            }
717            
718            private void
719          installListeners() {          installListeners() {
720                  btnInstr.addActionListener(new ActionListener() {                  btnInstr.addActionListener(new ActionListener() {
721                          public void                          public void
722                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) { loadInstrument(); }
723                  });                  });
           
                 btnReset.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { channel.getModel().resetBackendChannel(); }  
                 });  
724                                    
725                  btnDuplicate.addActionListener(new ActionListener() {                  btnEngine.addActionListener(new ActionListener() {
726                          public void                          public void
727                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
728                                  channel.getModel().duplicateBackendChannel();                                  int y = btnEngine.getHeight() + 1;
729                                    menuEngines.show(btnEngine, 0, y);
730                          }                          }
731                  });                  });
732          }          }
733            
734          private void          private void
735          loadInstrument() {          loadInstrument() {
736                  InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());
737                  dlg.setVisible(true);                  dlg.setVisible(true);
738                                    
739                  if(!dlg.isCancelled()) {                  if(!dlg.isCancelled()) {
740                          SamplerChannelModel m = channel.getModel();                          SamplerChannelModel m = channel.getModel();
741                          m.loadBackendInstrument(dlg.getFileName(), dlg.getInstrumentIndex());                          m.loadBackendInstrument(dlg.getInstrumentFile(), dlg.getInstrumentIndex());
742                  }                  }
743          }          }
744                    
# Line 577  class ChannelScreen extends JPanel { Line 756  class ChannelScreen extends JPanel {
756                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
757                  }                  }
758                    
759                                    if(sc.getEngine() != null) {
760                            String s = sc.getEngine().getDescription();
761                            if(!s.equals(btnEngine.getText())) btnEngine.setText(s);
762                    }
763                                    
764          }          }
765                    
766          protected void          protected void
767          updateVolumeInfo(int volume) {          updateVolumeInfo(int volume) {
768                  lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume));                  lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume));
769                    lVolume.setMinimumSize(dimVolume);
770                    lVolume.setPreferredSize(dimVolume);
771                                    
772          }          }
773                    
# Line 615  class ChannelScreen extends JPanel { Line 799  class ChannelScreen extends JPanel {
799                  lVoices.setMaximumSize(d);                  lVoices.setMaximumSize(d);
800          }          }
801                    
802            class FxSendsPane extends JSFxSendsPane {
803                    FxSendsPane(SamplerChannelModel model) {
804                            super(model);
805                            
806                            actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
807                            actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
808                    }
809                    
810                    protected JToolBar
811                    createToolBar() {
812                            JToolBar tb = new JToolBar();
813                            Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
814                            tb.setMaximumSize(d);
815                            tb.setFloatable(false);
816                            tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
817                            
818                            tb.add(new ToolbarButton(actionAddFxSend));
819                            tb.add(new ToolbarButton(actionRemoveFxSend));
820                    
821                            return tb;
822                    }
823            }
824            
825          static class ScreenButton extends JButton {          static class ScreenButton extends JButton {
826                  ScreenButton(String s) {                  ScreenButton(String s) {
827                          super(s);                          super(s);
# Line 622  class ChannelScreen extends JPanel { Line 829  class ChannelScreen extends JPanel {
829                          setFocusPainted(false);                          setFocusPainted(false);
830                          setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));                          setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
831                          setMargin(new Insets(0, 0, 0, 0));                          setMargin(new Insets(0, 0, 0, 0));
832                            
833                            putClientProperty (
834                                    SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE
835                            );
836                            
837                            putClientProperty (
838                                    SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE
839                            );
840                            
841                            putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE);
842                            
843                            FadeConfigurationManager.getInstance().disallowFades(FadeKind.ROLLOVER, this);
844                            
845                          setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));                          setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
846                            setFont(Res.fontScreen);
847                            setForeground(new java.awt.Color(0xFFA300));
848                  }                  }
849          }          }
850  }  }
851    
852  class ChannelOptions extends JPanel {  class ChannelOptions extends JXCollapsiblePane {
853          private final Channel channel;          private final Channel channel;
854            private MidiDeviceModel midiDevice = null;
855            
856            private final JComboBox cbMidiDevice = new FantasiaComboBox();
857            private final JComboBox cbMidiPort = new FantasiaComboBox();
858            private final JComboBox cbMidiChannel = new FantasiaComboBox();
859            private final JComboBox cbInstrumentMap = new FantasiaComboBox();
860            private final JComboBox cbAudioDevice = new FantasiaComboBox();
861                    
862          private final JComboBox cbMidiDevice = new JComboBox();          private final PixmapButton btnChannelRouting;
         private final JComboBox cbMidiPort = new JComboBox();  
         private final JComboBox cbMidiChannel = new JComboBox();  
         private final JComboBox cbEngine = new JComboBox();  
         private final JComboBox cbAudioDevice = new JComboBox();  
863                    
864          private boolean update = false;          private boolean update = false;
865                    
866          ChannelOptions(Channel channel) {          private final SamplerListener samplerListener;
867            private final MapListListener mapListListener = new MapListListener();
868            
869            private class NoMap {
870                    public String
871                    toString() { return "[None]"; }
872            }
873            
874            private NoMap noMap = new NoMap();
875            
876            private class DefaultMap {
877                    public String
878                    toString() { return "[Default]"; }
879            }
880            
881            private DefaultMap defaultMap = new DefaultMap();
882            
883            ChannelOptions(final Channel channel) {
884                    setAnimated(false);
885                    setCollapsed(true);
886                    setAnimated(preferences().getBoolProperty(ANIMATED));
887                    
888                    preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
889                            public void
890                            propertyChange(PropertyChangeEvent e) {
891                                    setAnimated(preferences().getBoolProperty(ANIMATED));
892                            }
893                    });
894                    
895                    PixmapPane bgp = new PixmapPane(Res.gfxChannelOptions);
896                    bgp.setPixmapInsets(new Insets(1, 1, 1, 1));
897                    
898                  this.channel = channel;                  this.channel = channel;
899                                    
900                  setName("ChannelOptions");                  bgp.setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4));
901                  setVisible(false);                  bgp.setLayout(new BoxLayout(bgp, BoxLayout.X_AXIS));
                 setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4));  
                 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));  
902                                    
903                  setPreferredSize(new Dimension(420, 44));                  bgp.setPreferredSize(new Dimension(420, 44));
904                  setMinimumSize(getPreferredSize());                  bgp.setMinimumSize(getPreferredSize());
905                  setMaximumSize(getPreferredSize());                  bgp.setMaximumSize(getPreferredSize());
906                                    
907                  JPanel p = new JPanel();                  JPanel p = new JPanel();
                 p.setOpaque(true);  
908                  p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));                  p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));
909                  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
910                  JLabel l = new JLabel(Res.iconMidiInputTitle);                  JLabel l = new JLabel(Res.gfxMidiInputTitle);
911                  l.setAlignmentX(LEFT_ALIGNMENT);                  l.setAlignmentX(LEFT_ALIGNMENT);
912                  p.add(l);                  p.add(l);
913                                    
# Line 675  class ChannelOptions extends JPanel { Line 928  class ChannelOptions extends JPanel {
928                  o = cbMidiPort.getRenderer();                  o = cbMidiPort.getRenderer();
929                  if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);                  if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);
930                                    
931                  cbMidiPort.setPreferredSize(new Dimension(67, 18));                  cbMidiPort.setPreferredSize(new Dimension(62, 18));
932                  cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize());                  cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize());
933                  cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize());                  cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize());
934                  p2.add(cbMidiPort);                  p2.add(cbMidiPort);
# Line 693  class ChannelOptions extends JPanel { Line 946  class ChannelOptions extends JPanel {
946                                    
947                  p2.add(cbMidiChannel);                  p2.add(cbMidiChannel);
948                  p2.setAlignmentX(LEFT_ALIGNMENT);                  p2.setAlignmentX(LEFT_ALIGNMENT);
949                    p2.setOpaque(false);
950                  p.add(p2);                  p.add(p2);
951                    p.setBackground(new java.awt.Color(0x818181));
952                                    
953                  add(p);                  bgp.add(p);
954                                    
955                  add(Box.createRigidArea(new Dimension(4, 0)));                  bgp.add(Box.createRigidArea(new Dimension(4, 0)));
956                                    
957                  p = new JPanel();                  p = new JPanel();
958                  p.setOpaque(true);                  p.setOpaque(true);
959                  p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));                  p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));
960                  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
961                  l = new JLabel(Res.iconEngineTitle);                  l = new JLabel(Res.gfxInstrumentMapTitle);
962                  l.setAlignmentX(LEFT_ALIGNMENT);                  l.setAlignmentX(LEFT_ALIGNMENT);
963                  l.setAlignmentX(LEFT_ALIGNMENT);                  l.setAlignmentX(LEFT_ALIGNMENT);
964                  p.add(l);                  p.add(l);
965                                    
966                  p.add(Box.createRigidArea(new Dimension(0, 3)));                  p.add(Box.createRigidArea(new Dimension(0, 3)));
967                                    
968                  o = cbEngine.getRenderer();                  //o = cbInstrumentMap.getRenderer();
969                  if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);                  //if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);
970                                    
971                  for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e);                  cbInstrumentMap.setPreferredSize(new Dimension(126, 18));
972                  cbEngine.setPreferredSize(new Dimension(125, 18));                  cbInstrumentMap.setMinimumSize(cbInstrumentMap.getPreferredSize());
973                  cbEngine.setMinimumSize(cbEngine.getPreferredSize());                  cbInstrumentMap.setMaximumSize(cbInstrumentMap.getPreferredSize());
974                  cbEngine.setMaximumSize(cbEngine.getPreferredSize());                  cbInstrumentMap.setAlignmentX(LEFT_ALIGNMENT);
975                  cbEngine.setAlignmentX(LEFT_ALIGNMENT);                  p.add(cbInstrumentMap);
976                  p.add(cbEngine);                  p.setBackground(new java.awt.Color(0x818181));
977                    bgp.add(p);
978                                    
979                  add(p);                  bgp.add(Box.createRigidArea(new Dimension(4, 0)));
                   
                 add(Box.createRigidArea(new Dimension(4, 0)));  
980                                    
981                  p = new JPanel();                  p = new JPanel();
982                  p.setOpaque(true);                  p.setOpaque(true);
983                  p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));                  p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));
984                  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
985                  l = new JLabel(Res.iconAudioOutputTitle);                  l = new JLabel(Res.gfxAudioOutputTitle);
                 l.setAlignmentX(LEFT_ALIGNMENT);  
986                  l.setAlignmentX(LEFT_ALIGNMENT);                  l.setAlignmentX(LEFT_ALIGNMENT);
987                  p.add(l);                  p.add(l);
988                                    
989                  p.add(Box.createRigidArea(new Dimension(0, 3)));                  //p.add(Box.createRigidArea(new Dimension(0, 3)));
990                    
991                    p2 = new JPanel();
992                    p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
993                    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
994                    p2.setOpaque(false);
995                    p2.setAlignmentX(LEFT_ALIGNMENT);
996                                    
997                  o = cbAudioDevice.getRenderer();                  o = cbAudioDevice.getRenderer();
998                  if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT);                  if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT);
999                                    
1000                  cbAudioDevice.setPreferredSize(new Dimension(61, 18));                  cbAudioDevice.setPreferredSize(new Dimension(40, 18));
1001                  cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize());                  cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize());
1002                  cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize());                  cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize());
                 cbAudioDevice.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(cbAudioDevice);  
1003                                    
1004                  add(p);                  p2.add(cbAudioDevice);
1005                    p2.add(Box.createRigidArea(new Dimension(3, 0)));
1006                    btnChannelRouting = new PixmapButton(Res.gfxBtnCr, Res.gfxBtnCrRO);
1007                    btnChannelRouting.setPressedIcon(Res.gfxBtnCrRO);
1008                    btnChannelRouting.setEnabled(false);
1009                    btnChannelRouting.setToolTipText(i18n.getLabel("ChannelOptions.routing"));
1010                    
1011                    btnChannelRouting.addActionListener(new ActionListener() {
1012                            public void
1013                            actionPerformed(ActionEvent e) {
1014                                    SamplerChannel c = channel.getChannelInfo();
1015                                    new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
1016                            
1017                            }
1018                    });
1019                    
1020                    p2.add(btnChannelRouting);
1021                    
1022                    p.add(p2);
1023                    p.setBackground(new java.awt.Color(0x818181));
1024                    p2 = new JPanel();
1025                    p2.setLayout(new java.awt.BorderLayout());
1026                    p.add(p2);
1027                    bgp.add(p);
1028                    
1029                    setContentPane(bgp);
1030                                    
1031                  cbMidiDevice.addActionListener(new ActionListener() {                  cbMidiDevice.addActionListener(new ActionListener() {
1032                          public void                          public void
# Line 761  class ChannelOptions extends JPanel { Line 1043  class ChannelOptions extends JPanel {
1043                          actionPerformed(ActionEvent e) { setMidiChannel(); }                          actionPerformed(ActionEvent e) { setMidiChannel(); }
1044                  });                  });
1045                                    
1046                  cbEngine.addActionListener(new ActionListener() {                  samplerListener = new SamplerAdapter() {
1047                            /** Invoked when the default MIDI instrument map is changed. */
1048                          public void                          public void
1049                          actionPerformed(ActionEvent e) { setEngineType(); }                          defaultMapChanged(SamplerEvent e) {
1050                                    updateCbInstrumentMapToolTipText();
1051                                    
1052                            }
1053                    };
1054                    
1055                    CC.getSamplerModel().addSamplerListener(samplerListener);
1056                    
1057                    cbInstrumentMap.addItem(noMap);
1058                    cbInstrumentMap.addItem(defaultMap);
1059                    for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) {
1060                            cbInstrumentMap.addItem(map);
1061                    }
1062                    
1063                    int map = channel.getModel().getChannelInfo().getMidiInstrumentMapId();
1064                    cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map));
1065                    if(cbInstrumentMap.getSelectedItem() == null) {
1066                            if(map == -1) cbInstrumentMap.setSelectedItem(noMap);
1067                            else if(map == -2) {
1068                                    cbInstrumentMap.setSelectedItem(defaultMap);
1069                            }
1070                    }
1071                    
1072                    updateCbInstrumentMapToolTipText();
1073                    
1074                    if(channel.getModel().getChannelInfo().getEngine() == null) {
1075                            cbInstrumentMap.setEnabled(false);
1076                    }
1077                    
1078                    cbInstrumentMap.addActionListener(new ActionListener() {
1079                            public void
1080                            actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1081                  });                  });
1082                                    
1083                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
1084                    CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1085                    
1086                  cbAudioDevice.addActionListener(new ActionListener() {                  cbAudioDevice.addActionListener(new ActionListener() {
1087                          public void                          public void
1088                          actionPerformed(ActionEvent e) { setBackendAudioDevice(); }                          actionPerformed(ActionEvent e) { setBackendAudioDevice(); }
# Line 803  class ChannelOptions extends JPanel { Line 1120  class ChannelOptions extends JPanel {
1120                  try {                  try {
1121                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());
1122                                                    
                         cbEngine.setSelectedItem(sc.getEngine());  
                           
1123                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
1124                            btnChannelRouting.setEnabled(am != null);
1125                  } catch(Exception x) {                  } catch(Exception x) {
1126                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
1127                  }                  }
1128                                    
1129                    if(sc.getEngine() != null) {
1130                            cbInstrumentMap.setEnabled(true);
1131                            int id = sc.getMidiInstrumentMapId();
1132                            Object o;
1133                            if(id == -2) o = defaultMap;
1134                            else if(id == -1) o = noMap;
1135                            else o = CC.getSamplerModel().getMidiInstrumentMapById(id);
1136                            
1137                            if(cbInstrumentMap.getSelectedItem() != o) {
1138                                    cbInstrumentMap.setSelectedItem(o);
1139                            }
1140                    } else {
1141                            cbInstrumentMap.setSelectedItem(noMap);
1142                            cbInstrumentMap.setEnabled(false);
1143                    }
1144                    
1145                  setUpdate(false);                  setUpdate(false);
1146          }          }
1147                    
# Line 838  class ChannelOptions extends JPanel { Line 1170  class ChannelOptions extends JPanel {
1170                  setUpdate(false);                  setUpdate(false);
1171          }          }
1172                    
1173            
1174            private void
1175            updateInstrumentMap() {
1176                    updateCbInstrumentMapToolTipText();
1177                    
1178                    int id = channel.getModel().getChannelInfo().getMidiInstrumentMapId();
1179                    Object o = cbInstrumentMap.getSelectedItem();
1180                    if(o == null && id == -1) return;
1181                    
1182                    int cbId;
1183                    if(o == null || o == noMap) cbId = -1;
1184                    else if(o == defaultMap) cbId = -2;
1185                    else cbId = ((MidiInstrumentMap)o).getMapId();
1186                    
1187                    if(cbId == id) return;
1188                    
1189                    channel.getModel().setBackendMidiInstrumentMap(cbId);
1190            }
1191            
1192            private void
1193            updateCbInstrumentMapToolTipText() {
1194                    if(cbInstrumentMap.getSelectedItem() != defaultMap) {
1195                            cbInstrumentMap.setToolTipText(null);
1196                            return;
1197                    }
1198                    
1199                    MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap();
1200                    if(m != null) {
1201                            String s = i18n.getLabel("Channel.ttDefault", m.getName());
1202                            cbInstrumentMap.setToolTipText(s);
1203                    } else {
1204                            cbInstrumentMap.setToolTipText(null);
1205                    }
1206            }
1207            
1208          /**          /**
1209           * Updates the audio device list.           * Updates the audio device list.
1210           */           */
# Line 875  class ChannelOptions extends JPanel { Line 1242  class ChannelOptions extends JPanel {
1242                          return;                          return;
1243                  }                  }
1244                                    
1245                    if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler());
1246                    
1247                  cbMidiPort.removeAllItems();                  cbMidiPort.removeAllItems();
1248                                    
1249                  if(mid == null) {                  if(mid == null) {
1250                            midiDevice = null;
1251                          cbMidiPort.setEnabled(false);                          cbMidiPort.setEnabled(false);
1252                                                    
1253                          cbMidiChannel.setSelectedItem(null);                          cbMidiChannel.setSelectedItem(null);
1254                          cbMidiChannel.setEnabled(false);                          cbMidiChannel.setEnabled(false);
1255                  } else {                  } else {
1256                            midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId());
1257                            if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler());
1258                            
1259                          cbMidiPort.setEnabled(true);                          cbMidiPort.setEnabled(true);
1260                                                    
1261                          MidiPort[] ports = mid.getMidiPorts();                          MidiPort[] ports = mid.getMidiPorts();
# Line 917  class ChannelOptions extends JPanel { Line 1290  class ChannelOptions extends JPanel {
1290                  channel.getModel().setBackendMidiInputChannel(c);                  channel.getModel().setBackendMidiInputChannel(c);
1291          }          }
1292                    
         /** Invoked when the user selects an engine. */  
         private void  
         setEngineType() {  
                 Object oldEngine = channel.getModel().getChannelInfo().getEngine();  
                 SamplerEngine newEngine = (SamplerEngine)cbEngine.getSelectedItem();  
                   
                 if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }  
                 else if(newEngine == null) return;  
                   
                 channel.getModel().setBackendEngineType(newEngine.getName());  
                   
         }  
           
1293          private void          private void
1294          setBackendAudioDevice() {          setBackendAudioDevice() {
1295                  if(isUpdate()) return;                  if(isUpdate()) return;
# Line 959  class ChannelOptions extends JPanel { Line 1319  class ChannelOptions extends JPanel {
1319          private Handler          private Handler
1320          getHandler() { return handler; }          getHandler() { return handler; }
1321                    
1322          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel> {          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1323                                            SamplerChannelListListener, MidiDeviceListener {
1324                  /**                  /**
1325                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1326                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 999  class ChannelOptions extends JPanel { Line 1360  class ChannelOptions extends JPanel {
1360                  entryRemoved(ListEvent<AudioDeviceModel> e) {                  entryRemoved(ListEvent<AudioDeviceModel> e) {
1361                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1362                  }                  }
1363                    
1364                    /**
1365                     * Invoked when a new sampler channel is created.
1366                     * @param e A <code>SamplerChannelListEvent</code>
1367                     * instance providing the event information.
1368                     */
1369                    public void
1370                    channelAdded(SamplerChannelListEvent e) { }
1371            
1372                    /**
1373                     * Invoked when a sampler channel is removed.
1374                     * @param e A <code>SamplerChannelListEvent</code>
1375                     * instance providing the event information.
1376                     */
1377                    public void
1378                    channelRemoved(SamplerChannelListEvent e) {
1379                            // Some cleanup when the channel is removed.
1380                            if(e.getChannelModel().getChannelId() == channel.getChannelId()) {
1381                                    SamplerModel sm = CC.getSamplerModel();
1382                                    
1383                                    sm.removeMidiDeviceListListener(getHandler());
1384                                    sm.removeAudioDeviceListListener(getHandler());
1385                                    sm.removeMidiInstrumentMapListListener(mapListListener);
1386                                    sm.removeSamplerListener(samplerListener);
1387                                    sm.removeSamplerChannelListListener(getHandler());
1388                                    
1389                                    if(midiDevice != null) {
1390                                            midiDevice.removeMidiDeviceListener(getHandler());
1391                                    }
1392                            }
1393                    }
1394                    
1395                    public void
1396                    settingsChanged(MidiDeviceEvent e) {
1397                            if(isUpdate()) {
1398                                    CC.getLogger().warning("Invalid update state");
1399                                    return;
1400                            }
1401                            
1402                            setUpdate(true);
1403                            int idx = cbMidiPort.getSelectedIndex();
1404                            MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
1405                            
1406                            cbMidiPort.removeAllItems();
1407                            for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port);
1408                            
1409                            if(idx >= cbMidiPort.getModel().getSize()) idx = 0;
1410                            
1411                            setUpdate(false);
1412                            
1413                            if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx);
1414                    }
1415            }
1416            
1417            private class MapListListener implements ListListener<MidiInstrumentMap> {
1418                    /** Invoked when a new MIDI instrument map is added to a list. */
1419                    public void
1420                    entryAdded(ListEvent<MidiInstrumentMap> e) {
1421                            cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());
1422                            boolean b = channel.getModel().getChannelInfo().getEngine() != null;
1423                            if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);
1424                    }
1425            
1426                    /** Invoked when a new MIDI instrument map is removed from a list. */
1427                    public void
1428                    entryRemoved(ListEvent<MidiInstrumentMap> e) {
1429                            cbInstrumentMap.removeItem(e.getEntry());
1430                            if(cbInstrumentMap.getItemCount() == 0) { // TODO: ?
1431                                    cbInstrumentMap.setSelectedItem(noMap);
1432                                    cbInstrumentMap.setEnabled(false);
1433                            }
1434                    }
1435          }          }
1436  }  }

Legend:
Removed from v.1204  
changed lines
  Added in v.1318

  ViewVC Help
Powered by ViewVC