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

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

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

revision 911 by iliev, Mon Aug 7 18:25:58 2006 UTC revision 1143 by iliev, Mon Apr 2 21:18:31 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 Grigor Kirilov Iliev   *   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 22  Line 22 
22    
23  package org.jsampler.view.classic;  package org.jsampler.view.classic;
24    
25    import java.awt.BorderLayout;
26  import java.awt.Color;  import java.awt.Color;
27  import java.awt.Cursor;  import java.awt.Cursor;
28  import java.awt.Dimension;  import java.awt.Dimension;
# Line 33  import java.awt.datatransfer.Transferabl Line 34  import java.awt.datatransfer.Transferabl
34    
35  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
36  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
37    import java.awt.event.HierarchyEvent;
38    import java.awt.event.HierarchyListener;
39  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
40  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
41  import java.awt.event.MouseMotionAdapter;  import java.awt.event.MouseMotionAdapter;
# Line 64  import javax.swing.TransferHandler; Line 67  import javax.swing.TransferHandler;
67    
68  import javax.swing.border.Border;  import javax.swing.border.Border;
69  import javax.swing.border.LineBorder;  import javax.swing.border.LineBorder;
70    import javax.swing.border.TitledBorder;
71    
72  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
73  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
74    
75    import net.sf.juife.InformationDialog;
76  import net.sf.juife.JuifeUtils;  import net.sf.juife.JuifeUtils;
77    
78  import org.jsampler.AudioDeviceModel;  import org.jsampler.AudioDeviceModel;
# Line 75  import org.jsampler.CC; Line 80  import org.jsampler.CC;
80  import org.jsampler.HF;  import org.jsampler.HF;
81  import org.jsampler.Instrument;  import org.jsampler.Instrument;
82  import org.jsampler.MidiDeviceModel;  import org.jsampler.MidiDeviceModel;
83    import org.jsampler.MidiInstrumentMap;
84  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
85  import org.jsampler.SamplerModel;  import org.jsampler.SamplerModel;
86    
87  import org.jsampler.event.AudioDeviceListEvent;  import org.jsampler.event.ListEvent;
88  import org.jsampler.event.AudioDeviceListListener;  import org.jsampler.event.ListListener;
89  import org.jsampler.event.MidiDeviceListEvent;  import org.jsampler.event.MidiDeviceListEvent;
90  import org.jsampler.event.MidiDeviceListListener;  import org.jsampler.event.MidiDeviceListListener;
91    import org.jsampler.event.SamplerAdapter;
92  import org.jsampler.event.SamplerChannelAdapter;  import org.jsampler.event.SamplerChannelAdapter;
93  import org.jsampler.event.SamplerChannelEvent;  import org.jsampler.event.SamplerChannelEvent;
94  import org.jsampler.event.SamplerChannelListEvent;  import org.jsampler.event.SamplerChannelListEvent;
95  import org.jsampler.event.SamplerChannelListListener;  import org.jsampler.event.SamplerChannelListListener;
96  import org.jsampler.event.SamplerChannelListener;  import org.jsampler.event.SamplerChannelListener;
97    import org.jsampler.event.SamplerEvent;
98    
99  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
100  import org.linuxsampler.lscp.MidiInputDevice;  import org.linuxsampler.lscp.MidiInputDevice;
# Line 113  public class Channel extends org.jsample Line 121  public class Channel extends org.jsample
121          private final static ImageIcon iconHideProperties;          private final static ImageIcon iconHideProperties;
122                    
123          private static Border borderSelected;          private static Border borderSelected;
124            private static Border borderHighlighted;
125          private static Border borderDeselected;          private static Border borderDeselected;
126                    
127            private static Color chnColor;
128          private static Color borderColor;          private static Color borderColor;
129            private static Color borderHighlightedColor;
130            private static Color chnSelectedColor;
131            private static Color chnHighlightedColor;
132                    
133          private final static Vector<PropertyChangeListener> propertyChangeListeners          private final static Vector<PropertyChangeListener> propertyChangeListeners
134                  = new Vector<PropertyChangeListener>();                  = new Vector<PropertyChangeListener>();
# Line 146  public class Channel extends org.jsample Line 159  public class Channel extends org.jsample
159                          setBorderColor(ClassicPrefs.getChannelBorderColor());                          setBorderColor(ClassicPrefs.getChannelBorderColor());
160                  else setBorderColor(ClassicPrefs.getDefaultChannelBorderColor());                  else setBorderColor(ClassicPrefs.getDefaultChannelBorderColor());
161                                    
162                    if(ClassicPrefs.getCustomChannelBorderHlColor())
163                            setBorderHighlightedColor(ClassicPrefs.getChannelBorderHlColor());
164                    else setBorderHighlightedColor(ClassicPrefs.getDefaultChannelBorderHlColor());
165                    
166                  borderSelected = new LineBorder(getBorderColor(), 2, true);                  borderSelected = new LineBorder(getBorderColor(), 2, true);
167                    borderHighlighted = new LineBorder(getBorderHighlightedColor(), 2, true);
168                  borderDeselected = BorderFactory.createEmptyBorder(2, 2, 2, 2);                  borderDeselected = BorderFactory.createEmptyBorder(2, 2, 2, 2);
169                    
170                    chnColor = new JPanel().getBackground();
171                    
172                    if(ClassicPrefs.getCustomSelectedChannelBgColor()) {
173                            chnSelectedColor = ClassicPrefs.getSelectedChannelBgColor();
174                    } else {
175                            int r = chnColor.getRed() - 14 < 0 ? 0 : chnColor.getRed() - 14;
176                            int g = chnColor.getGreen() - 8 < 0 ? 0 : chnColor.getGreen() - 8;
177                            int b = chnColor.getBlue() - 3 < 0 ? 0 : chnColor.getBlue() - 3;
178                    
179                            chnSelectedColor = new Color(r, g, b);
180                    }
181                    
182                    /*r = r + 5 > 255 ? 255 : r + 5;
183                    g = g + 4 > 255 ? 255 : g + 4;
184                    b = b + 1 > 255 ? 255 : b + 1;*/
185                    
186                    chnHighlightedColor = new Color(chnColor.getRGB());
187          }          }
188                    
189          /**          /**
# Line 189  public class Channel extends org.jsample Line 225  public class Channel extends org.jsample
225                  firePropertyChanged("borderColor", oldColor, borderColor);                  firePropertyChanged("borderColor", oldColor, borderColor);
226          }          }
227                    
228            /**
229             * Gets the border color that is used when the mouse pointer is over a channel.
230             * @return The border color that is used when the mouse pointer is over a channel.
231             */
232            public static Color
233            getBorderHighlightedColor() { return borderHighlightedColor; }
234            
235            /**
236             * Sets the border color to be used when the mouse pointer is over a channel.
237             * @param c The border color to be used when the mouse pointer is over a channel.
238             */
239            public static void
240            setBorderHighlightedColor(Color c) {
241                    Color oldColor = borderHighlightedColor;
242                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
243                    
244                    borderHighlightedColor = c;
245                    borderHighlighted = new LineBorder(getBorderHighlightedColor(), 2, true);
246                    firePropertyChanged("borderHighlightedColor", oldColor, borderHighlightedColor);
247            }
248            
249            /**
250             * Gets the background color that is used when a channel is selected.
251             * @return The background color that is used when a channel is selected.
252             */
253            public static Color
254            getSelectedChannelBgColor() { return chnSelectedColor; }
255            
256            /**
257             * Sets the background color that is used when a channel is selected.
258             * @param c The background color to be used when a channel is selected.
259             */
260            public static void
261            setSelectedChannelBgColor(Color c) {
262                    Color oldColor = chnSelectedColor;
263                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
264                    
265                    chnSelectedColor = c;
266                    firePropertyChanged("selectedChannelBgColor", oldColor, chnSelectedColor);
267            }
268            
269            /**
270             * Gets the background color that is used when the mouse pointer is over a channel.
271             * @return The background color that is used when the mouse pointer is over a channel.
272             */
273            public static Color
274            getHighlightedChannelBgColor() { return chnHighlightedColor; }
275            
276            /**
277             * Sets the background color to be used when the mouse pointer is over a channel.
278             * @param c The background color to be used when the mouse pointer is over a channel.
279             */
280            public static void
281            setHighlightedChannelBgColor(Color c) {
282                    Color oldColor = chnHighlightedColor;
283                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
284                    
285                    chnHighlightedColor = c;
286                    firePropertyChanged("highlightedChannelBgColor", oldColor, chnHighlightedColor);
287            }
288            
289          private static void          private static void
290          firePropertyChanged(String propertyName, Object oldValue, Object newValue) {          firePropertyChanged(String propertyName, Object oldValue, Object newValue) {
291                  PropertyChangeEvent e =                  PropertyChangeEvent e =
# Line 206  public class Channel extends org.jsample Line 303  public class Channel extends org.jsample
303          private final JButton btnSolo = new JButton();          private final JButton btnSolo = new JButton();
304          private final JSlider slVolume = new JSlider(0, 100);          private final JSlider slVolume = new JSlider(0, 100);
305          private final JLabel lVolume = new JLabel();          private final JLabel lVolume = new JLabel();
306            private final JLabel lVolImg = new JLabel(Res.iconVolume16);
307          private final JLabel lStreams = new JLabel("--");          private final JLabel lStreams = new JLabel("--");
308          private final JLabel lVoices = new JLabel("--");          private final JLabel lVoices = new JLabel("--");
309          private final JToggleButton btnProperties = new JToggleButton();          private final JToggleButton btnProperties = new JToggleButton();
# Line 213  public class Channel extends org.jsample Line 311  public class Channel extends org.jsample
311          private static int count = 2;          private static int count = 2;
312                    
313          private boolean selected = false;          private boolean selected = false;
314            private boolean mouseOver = false;
315                    
316                    
317          /**          /**
# Line 228  public class Channel extends org.jsample Line 327  public class Channel extends org.jsample
327                  setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));                  setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
328                                    
329                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
330                    addMouseListener(getHandler());
331                                    
332                  JPanel p = new JPanel();                  JPanel p = new JPanel();
333                    p.setOpaque(false);
334                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
335                  p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));                  p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
336                                    
337                  //setToolTipText(" Channel: " + String.valueOf(getChannelID()) + " ");                  setToolTipText(i18n.getLabel("Channel.tt", getModel().getChannelId()));
338                                    
339                  Dimension d = btnInstr.getPreferredSize();                  Dimension d = btnInstr.getPreferredSize();
340                  btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, d.height));                  btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, d.height));
# Line 244  public class Channel extends org.jsample Line 345  public class Channel extends org.jsample
345                  lVoices.setHorizontalAlignment(JLabel.CENTER);                  lVoices.setHorizontalAlignment(JLabel.CENTER);
346                                    
347                  JPanel statPane = new JPanel();                  JPanel statPane = new JPanel();
348                    statPane.setOpaque(false);
349                  statPane.setBorder(BorderFactory.createLoweredBevelBorder());                  statPane.setBorder(BorderFactory.createLoweredBevelBorder());
350                  statPane.setLayout(new BoxLayout(statPane, BoxLayout.X_AXIS));                  statPane.setLayout(new BoxLayout(statPane, BoxLayout.X_AXIS));
351                  statPane.add(Box.createRigidArea(new Dimension(6, 0)));                  statPane.add(Box.createRigidArea(new Dimension(6, 0)));
# Line 265  public class Channel extends org.jsample Line 367  public class Channel extends org.jsample
367                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  p.add(Box.createRigidArea(new Dimension(6, 0)));
368                                    
369                  JPanel volumePane = new JPanel();                  JPanel volumePane = new JPanel();
370                    volumePane.setOpaque(false);
371                  volumePane.setBorder(BorderFactory.createLoweredBevelBorder());                  volumePane.setBorder(BorderFactory.createLoweredBevelBorder());
372                  volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));                  volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));
373                  volumePane.add(Box.createRigidArea(new Dimension(6, 0)));                  volumePane.add(Box.createRigidArea(new Dimension(6, 0)));
374                                    
375                    volumePane.add(lVolImg);
376                    volumePane.add(Box.createRigidArea(new Dimension(1, 0)));
377                    
378                  d = slVolume.getPreferredSize();                  d = slVolume.getPreferredSize();
379                  slVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));                  slVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));
380                    slVolume.setOpaque(false);
381                  volumePane.add(slVolume);                  volumePane.add(slVolume);
382                                    
383                  lVolume.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));                  lVolume.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));
# Line 414  public class Channel extends org.jsample Line 521  public class Channel extends org.jsample
521                                                    
522                          try {                          try {
523                                  int idx = Integer.parseInt(args[5]);                                  int idx = Integer.parseInt(args[5]);
524                                  Channel.this.getModel().loadInstrument(args[4], idx);                                  Channel.this.getModel().loadBackendInstrument(args[4], idx);
525                          } catch(Exception x) {                          } catch(Exception x) {
526                                  CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);                                  CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
527                          }                          }
# Line 426  public class Channel extends org.jsample Line 533  public class Channel extends org.jsample
533          private EventHandler          private EventHandler
534          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
535                    
536          private class EventHandler implements SamplerChannelListener, PropertyChangeListener {          private class EventHandler extends MouseAdapter implements SamplerChannelListener,
537                                                            PropertyChangeListener, HierarchyListener {
538                  /**                  /**
539                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
540                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 457  public class Channel extends org.jsample Line 565  public class Channel extends org.jsample
565                                    
566                  public void                  public void
567                  propertyChange(PropertyChangeEvent e) {                  propertyChange(PropertyChangeEvent e) {
568                          if(e.getPropertyName() == "borderColor") setSelected(isSelected());                          if (
569                                    e.getPropertyName() == "borderColor" ||
570                                    e.getPropertyName() == "borderHighlightedColor" ||
571                                    e.getPropertyName() == "selectedChannelBgColor" ||
572                                    e.getPropertyName() == "highlightedChannelBgColor"
573                            ) {
574                                    updateColors(isSelected());
575                            }
576                    }
577                    
578                    public void
579                    mouseEntered(MouseEvent e) {
580                            mouseOver = true;
581                            updateColors(isSelected());
582                    }
583                    
584                    public void
585                    mouseExited(MouseEvent e) {
586                            if(getMousePosition(true) != null) return;
587                            
588                            mouseOver = false;
589                            updateColors(isSelected());
590                    }
591                    
592                    
593            
594                    /** Called when the hierarchy has been changed. */
595                    public void
596                    hierarchyChanged(HierarchyEvent e) {
597                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
598                                    if(getMousePosition() == null) mouseExited(null);
599                                    else mouseEntered(null);
600                            }
601                  }                  }
602          }          }
603                    
# Line 475  public class Channel extends org.jsample Line 615  public class Channel extends org.jsample
615           */           */
616          public void          public void
617          setSelected(boolean select) {          setSelected(boolean select) {
618                  if(select)  mainPane.setBorder(borderSelected);                  updateColors(select);
                 else mainPane.setBorder(borderDeselected);  
619                                    
620                  selected = select;                  selected = select;
621          }          }
622                    
623            /**
624             * Updates the channel background and border colors.
625             * @param selected Specifies the selection state of this channel.
626             */
627            private void
628            updateColors(boolean selected) {
629                    if(selected) {
630                            mainPane.setBorder(borderSelected);
631                            mainPane.setBackground(chnSelectedColor);
632                    } else {
633                            if(mouseOver) {
634                                    mainPane.setBorder(borderHighlighted);
635                                    mainPane.setBackground(chnHighlightedColor);
636                            } else {
637                                    mainPane.setBorder(borderDeselected);
638                                    mainPane.setBackground(chnColor);
639                            }
640                    }
641            }
642            
643          /** Hides the channel properties. */          /** Hides the channel properties. */
644          public void          public void
645          collapseChannel() { if(btnProperties.isSelected()) btnProperties.doClick(); }          collapseChannel() { if(btnProperties.isSelected()) btnProperties.doClick(); }
# Line 540  public class Channel extends org.jsample Line 699  public class Channel extends org.jsample
699                          else btnMute.setIcon(iconMutedBySolo);                          else btnMute.setIcon(iconMutedBySolo);
700                  } else btnMute.setIcon(iconMuteOn);                  } else btnMute.setIcon(iconMuteOn);
701                                    
702                  getModel().setMute(b);                  getModel().setBackendMute(b);
703          }          }
704                    
705          /** Invoked when the user clicks the solo button. */          /** Invoked when the user clicks the solo button. */
# Line 562  public class Channel extends org.jsample Line 721  public class Channel extends org.jsample
721                                  btnMute.setIcon(iconMutedBySolo);                                  btnMute.setIcon(iconMutedBySolo);
722                  }                  }
723                                    
724                  getModel().setSolo(b);                  getModel().setBackendSolo(b);
725          }          }
726                    
727          /** Invoked when the user changes the volume */          /** Invoked when the user changes the volume */
# Line 583  public class Channel extends org.jsample Line 742  public class Channel extends org.jsample
742                   */                   */
743                  float volume = slVolume.getValue();                  float volume = slVolume.getValue();
744                  volume /= 100;                  volume /= 100;
745                  getModel().setVolume(volume);                  getModel().setBackendVolume(volume);
746          }          }
747                    
748          private void          private void
749          updateVolume() {          updateVolume() {
750                  int volume = slVolume.getValue();                  int volume = slVolume.getValue();
751                  slVolume.setToolTipText(i18n.getLabel("Channel.volume", volume));                  slVolume.setToolTipText(i18n.getLabel("Channel.volume", volume));
752                    lVolImg.setToolTipText(i18n.getLabel("Channel.volume", volume));
753                                    
754                  setVolumeLabel(volume);                  setVolumeLabel(volume);
755                                    
# Line 656  public class Channel extends org.jsample Line 816  public class Channel extends org.jsample
816                  dlg.setVisible(true);                  dlg.setVisible(true);
817                                    
818                  if(!dlg.isCancelled()) {                  if(!dlg.isCancelled()) {
819                          getModel().loadInstrument(dlg.getFileName(), dlg.getInstrumentIndex());                          int idx = dlg.getInstrumentIndex();
820                            getModel().loadBackendInstrument(dlg.getFileName(), idx);
821                  }                  }
822          }          }
823  }  }
824    
825  class ChannelProperties extends JPanel {  class ChannelProperties extends JPanel {
         private final static ImageIcon iconAudioProps;  
           
         static {  
                 String path = "org/jsampler/view/classic/res/icons/";  
                 URL url = ClassLoader.getSystemClassLoader().getResource(path + "Import16.gif");  
                 iconAudioProps = new ImageIcon(url);  
         }  
           
826          private final JLabel lMidiDevice =          private final JLabel lMidiDevice =
827                  new JLabel(i18n.getLabel("ChannelProperties.lMidiDevice"));                  new JLabel(i18n.getLabel("ChannelProperties.lMidiDevice"));
828          private final JLabel lMidiPort =          private final JLabel lMidiPort =
# Line 677  class ChannelProperties extends JPanel { Line 830  class ChannelProperties extends JPanel {
830          private final JLabel lMidiChannel =          private final JLabel lMidiChannel =
831                  new JLabel(i18n.getLabel("ChannelProperties.lMidiChannel"));                  new JLabel(i18n.getLabel("ChannelProperties.lMidiChannel"));
832                    
833            private final JLabel lInstrumentMap =
834                    new JLabel(i18n.getLabel("ChannelProperties.lInstrumentMap"));
835            
836          private final JLabel lAudioDevice =          private final JLabel lAudioDevice =
837                  new JLabel(i18n.getLabel("ChannelProperties.lAudioDevice"));                  new JLabel(i18n.getLabel("ChannelProperties.lAudioDevice"));
838                    
839          private final JComboBox cbEngines = new JComboBox();          private final JComboBox cbEngines = new JComboBox();
840                    
841            private final JComboBox cbInstrumentMap = new JComboBox();
842          private final JComboBox cbMidiDevice = new JComboBox();          private final JComboBox cbMidiDevice = new JComboBox();
843          private final JComboBox cbMidiPort = new JComboBox();          private final JComboBox cbMidiPort = new JComboBox();
844          private final JComboBox cbMidiChannel = new JComboBox();          private final JComboBox cbMidiChannel = new JComboBox();
845          private final JComboBox cbAudioDevice = new JComboBox();          private final JComboBox cbAudioDevice = new JComboBox();
846                    
847          private final JButton btnAudioProps = new JButton(iconAudioProps);          private final JButton btnFxSends = new JButton(Res.iconFxSends22);
848            private final JButton btnAudioProps = new JButton(Res.iconAudioProps16);
849            private InformationDialog fxSendsDlg = null;
850                    
851          private SamplerChannelModel channelModel = null;          private SamplerChannelModel channelModel = null;
852                    
853          private boolean update = false;          private boolean update = false;
854                    
855            private class NoMap {
856                    public String
857                    toString() { return "[None]"; }
858            }
859            
860            private NoMap noMap = new NoMap();
861            
862            private class DefaultMap {
863                    public String
864                    toString() { return "[Default]"; }
865            }
866            
867            private DefaultMap defaultMap = new DefaultMap();
868            
869          /**          /**
870           * Creates a new instance of <code>ChannelProperties</code> using the specified non-null           * Creates a new instance of <code>ChannelProperties</code> using the specified non-null
871           * channel model.           * channel model.
# Line 702  class ChannelProperties extends JPanel { Line 875  class ChannelProperties extends JPanel {
875                  channelModel = model;                  channelModel = model;
876                                    
877                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
878                    setOpaque(false);
879                                    
880                  add(new JSeparator());                  add(new JSeparator());
881                                    
882                  JPanel enginesPane = new JPanel();                  JPanel enginesPane = createEnginePane();                
                   
                 for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngines.addItem(e);  
                   
                 //cbEngines.setMaximumSize(cbEngines.getPreferredSize());  
                   
                 enginesPane.add(cbEngines);  
                 String s = i18n.getLabel("ChannelProperties.enginesPane");  
                 enginesPane.setBorder(BorderFactory.createTitledBorder(s));  
883                                    
884                  JPanel devicesPane = new JPanel();                  JPanel devicesPane = new JPanel();
885                    devicesPane.setOpaque(false);
886                  devicesPane.setLayout(new BoxLayout(devicesPane, BoxLayout.X_AXIS));                  devicesPane.setLayout(new BoxLayout(devicesPane, BoxLayout.X_AXIS));
887                                    
888                  devicesPane.add(Box.createRigidArea(new Dimension(3, 0)));                  devicesPane.add(Box.createRigidArea(new Dimension(3, 0)));
# Line 773  class ChannelProperties extends JPanel { Line 940  class ChannelProperties extends JPanel {
940                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }
941                  });                  });
942                                    
943                    CC.getSamplerModel().addSamplerListener(new SamplerAdapter() {
944                            /** Invoked when the default MIDI instrument map is changed. */
945                            public void
946                            defaultMapChanged(SamplerEvent e) {
947                                    updateCbInstrumentMapToolTipText();
948                                    
949                            }
950                    });
951                    
952                    cbInstrumentMap.addItem(noMap);
953                    cbInstrumentMap.addItem(defaultMap);
954                    for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) {
955                            cbInstrumentMap.addItem(map);
956                    }
957                    
958                    int map = getModel().getChannelInfo().getMidiInstrumentMapId();
959                    cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map));
960                    if(cbInstrumentMap.getSelectedItem() == null) {
961                            if(map == -1) cbInstrumentMap.setSelectedItem(noMap);
962                            else if(map == -2) {
963                                    cbInstrumentMap.setSelectedItem(defaultMap);
964                            }
965                    }
966                    
967                    updateCbInstrumentMapToolTipText();
968                    
969                    if(getModel().getChannelInfo().getEngine() == null) {
970                            cbInstrumentMap.setEnabled(false);
971                    }
972                    
973                    cbInstrumentMap.addActionListener(new ActionListener() {
974                            public void
975                            actionPerformed(ActionEvent e) { updateInstrumentMap(); }
976                    });
977                    
978                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());
979                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());
980                  CC.getSamplerModel().addSamplerChannelListListener(getHandler());                  CC.getSamplerModel().addSamplerChannelListListener(getHandler());
981                                    
982                    CC.getSamplerModel().addMidiInstrumentMapListListener(new MapListListener());
983                    
984                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));
985                  btnAudioProps.addActionListener(new ActionListener() {                  btnAudioProps.addActionListener(new ActionListener() {
986                          public void                          public void
# Line 787  class ChannelProperties extends JPanel { Line 991  class ChannelProperties extends JPanel {
991                          }                          }
992                  });                  });
993                                    
994                    btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelProperties.btnFxSends"));
995                    btnFxSends.addActionListener(new ActionListener() {
996                            public void
997                            actionPerformed(ActionEvent e) {
998                                    if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
999                                            fxSendsDlg.toFront();
1000                                            return;
1001                                    }
1002                                    
1003                                    FxSendsPane p = new FxSendsPane(getModel());
1004                                    int id = getModel().getChannelId();
1005                                    fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
1006                                    fxSendsDlg.setTitle(i18n.getLabel("FxSendsPane.title", id));
1007                                    fxSendsDlg.setModal(false);
1008                                    fxSendsDlg.showCloseButton(false);
1009                                    fxSendsDlg.setVisible(true);
1010                            }
1011                    });
1012                    
1013                  updateMidiDevices();                  updateMidiDevices();
1014                  updateAudioDevices();                  updateAudioDevices();
1015                  updateChannelProperties();                  updateChannelProperties();
1016          }          }
1017            
1018            private JPanel
1019            createEnginePane() {
1020                    for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngines.addItem(e);
1021                    
1022                    cbEngines.setMaximumSize(cbEngines.getPreferredSize());
1023                    
1024                    JPanel p = new JPanel();
1025                    p.setOpaque(false);
1026                    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
1027                    p.add(cbEngines);
1028                    p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
1029                    
1030                    //enginesPane.add(Box.createGlue());
1031                    JPanel enginesPane = new JPanel();
1032                    enginesPane.setOpaque(false);
1033                    enginesPane.setLayout(new BorderLayout());
1034                    enginesPane.add(p, BorderLayout.SOUTH);
1035                    //enginesPane.add(Box.createRigidArea(new Dimension(0, 3)));
1036                    
1037                    String s = i18n.getLabel("ChannelProperties.enginesPane");
1038                    enginesPane.setBorder(BorderFactory.createTitledBorder(s));
1039                    Dimension d = new Dimension(enginesPane.getPreferredSize().width, Short.MAX_VALUE);
1040                    enginesPane.setMaximumSize(d);
1041                    return enginesPane;
1042            }
1043            
1044          private JPanel          private JPanel
1045          createMidiPane() {          createMidiPane() {
1046                  JPanel midiPane = new JPanel();                  JPanel midiPane = new JPanel();
1047                    midiPane.setOpaque(false);
1048                                    
1049                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
1050                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
1051                                    
1052                  midiPane.setLayout(gridbag);                  midiPane.setLayout(gridbag);
1053                                    
1054                  c.gridx = 0;                  c.gridx = 1;
1055                  c.gridy = 0;                  c.gridy = 0;
1056                  c.insets = new Insets(3, 3, 3, 3);                  c.insets = new Insets(0, 3, 3, 3);
1057                  gridbag.setConstraints(lMidiDevice, c);                  gridbag.setConstraints(lMidiDevice, c);
1058                  midiPane.add(lMidiDevice);                  midiPane.add(lMidiDevice);
1059                                    
                 c.gridx = 1;  
                 c.gridy = 0;  
                 gridbag.setConstraints(cbMidiDevice, c);  
                 midiPane.add(cbMidiDevice);  
                   
1060                  c.gridx = 2;                  c.gridx = 2;
1061                  c.gridy = 0;                  c.gridy = 0;
1062                  gridbag.setConstraints(lMidiPort, c);                  gridbag.setConstraints(lMidiPort, c);
1063                  midiPane.add(lMidiPort);                  midiPane.add(lMidiPort);
1064                                    
1065                  c.gridx = 4;                  c.gridx = 3;
1066                  c.gridy = 0;                  c.gridy = 0;
1067                  gridbag.setConstraints(lMidiChannel, c);                  gridbag.setConstraints(lMidiChannel, c);
1068                  midiPane.add(lMidiChannel);                  midiPane.add(lMidiChannel);
1069                                    
1070                  c.gridx = 5;                  c.gridx = 4;
1071                  c.gridy = 0;                  c.gridy = 0;
1072                  gridbag.setConstraints(cbMidiChannel, c);                  c.insets = new Insets(0, 10, 3, 3);
1073                  midiPane.add(cbMidiChannel);                  gridbag.setConstraints(lInstrumentMap, c);
1074                    midiPane.add(lInstrumentMap);
1075                                    
1076                  c.gridx = 3;                  btnFxSends.setMargin(new Insets(0, 0, 0, 0));
1077                    c.gridx = 0;
1078                  c.gridy = 0;                  c.gridy = 0;
1079                  c.weightx = 1.0;                  c.gridheight = 2;
1080                    c.insets = new Insets(0, 5, 0, 8);
1081                    gridbag.setConstraints(btnFxSends, c);
1082                    midiPane.add(btnFxSends);
1083                    
1084                    c.gridx = 1;
1085                    c.gridy = 1;
1086                    c.gridheight = 1;
1087                    c.insets = new Insets(0, 4, 4, 3);
1088                  c.fill = GridBagConstraints.HORIZONTAL;                  c.fill = GridBagConstraints.HORIZONTAL;
1089                  c.insets = new Insets(3, 3, 3, 3);                  gridbag.setConstraints(cbMidiDevice, c);
1090                    midiPane.add(cbMidiDevice);
1091                    
1092                    c.gridx = 3;
1093                    c.gridy = 1;
1094                    gridbag.setConstraints(cbMidiChannel, c);
1095                    midiPane.add(cbMidiChannel);
1096                    
1097                    c.gridx = 2;
1098                    c.gridy = 1;
1099                  gridbag.setConstraints(cbMidiPort, c);                  gridbag.setConstraints(cbMidiPort, c);
1100                  midiPane.add(cbMidiPort);                  midiPane.add(cbMidiPort);
1101                                    
1102                  String s = i18n.getLabel("ChannelProperties.midiPane");                  c.gridx = 4;
1103                  midiPane.setBorder(BorderFactory.createTitledBorder(s));                  c.gridy = 1;
1104                    c.weightx = 1.0;
1105                    c.insets = new Insets(0, 10, 3, 3);
1106                    gridbag.setConstraints(cbInstrumentMap, c);
1107                    midiPane.add(cbInstrumentMap);
1108                                    
1109                    String s = i18n.getLabel("ChannelProperties.midiPane");
1110                    TitledBorder border = BorderFactory.createTitledBorder(s);
1111                    //border.setTitlePosition(border.TOP);
1112                    midiPane.setBorder(border);
1113                  return midiPane;                  return midiPane;
1114          }          }
1115                    
1116          private JPanel          private JPanel
1117          createAudioPane() {          createAudioPane() {
1118                  JPanel audioPane = new JPanel();                  JPanel audioPane = new JPanel();
1119                    audioPane.setOpaque(false);
1120                                    
1121                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
1122                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
# Line 852  class ChannelProperties extends JPanel { Line 1125  class ChannelProperties extends JPanel {
1125                                    
1126                  c.gridx = 0;                  c.gridx = 0;
1127                  c.gridy = 0;                  c.gridy = 0;
1128                  c.insets = new Insets(3, 3, 3, 3);                  c.insets = new Insets(0, 3, 3, 3);
1129                  gridbag.setConstraints(lAudioDevice, c);                  gridbag.setConstraints(lAudioDevice, c);
1130                  audioPane.add(lAudioDevice);                  audioPane.add(lAudioDevice);
1131                                    
1132                  c.gridx = 1;                  c.gridx = 0;
1133                  c.gridy = 0;                  c.gridy = 1;
1134                    c.fill = GridBagConstraints.HORIZONTAL;
1135                  gridbag.setConstraints(cbAudioDevice, c);                  gridbag.setConstraints(cbAudioDevice, c);
1136                  audioPane.add(cbAudioDevice);                  audioPane.add(cbAudioDevice);
1137                                    
1138                  btnAudioProps.setMargin(new Insets(0, 0, 0, 0));                  btnAudioProps.setMargin(new Insets(0, 0, 0, 0));
1139                  c.gridx = 2;                  c.gridx = 1;
1140                  c.gridy = 0;                  c.gridy = 1;
1141                  c.insets = new Insets(3, 9, 3, 3);                  c.fill = GridBagConstraints.NONE;
1142                  gridbag.setConstraints(btnAudioProps, c);                  gridbag.setConstraints(btnAudioProps, c);
1143                  audioPane.add(btnAudioProps);                  audioPane.add(btnAudioProps);
1144                                    
# Line 883  class ChannelProperties extends JPanel { Line 1157  class ChannelProperties extends JPanel {
1157          public SamplerChannelModel          public SamplerChannelModel
1158          getModel() { return channelModel; }          getModel() { return channelModel; }
1159                    
1160            
1161            private void
1162            updateInstrumentMap() {
1163                    updateCbInstrumentMapToolTipText();
1164                    
1165                    int id = getModel().getChannelInfo().getMidiInstrumentMapId();
1166                    Object o = cbInstrumentMap.getSelectedItem();
1167                    if(o == null && id == -1) return;
1168                    
1169                    int cbId;
1170                    if(o == null || o == noMap) cbId = -1;
1171                    else if(o == defaultMap) cbId = -2;
1172                    else cbId = ((MidiInstrumentMap)o).getMapId();
1173                    
1174                    if(cbId == id) return;
1175                    
1176                    channelModel.setBackendMidiInstrumentMap(cbId);
1177            }
1178            
1179            private void
1180            updateCbInstrumentMapToolTipText() {
1181                    if(cbInstrumentMap.getSelectedItem() != defaultMap) {
1182                            cbInstrumentMap.setToolTipText(null);
1183                            return;
1184                    }
1185                    
1186                    MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap();
1187                    if(m != null) {
1188                            String s = i18n.getLabel("Channel.ttDefault", m.getName());
1189                            cbInstrumentMap.setToolTipText(s);
1190                    } else {
1191                            cbInstrumentMap.setToolTipText(null);
1192                    }
1193            }
1194            
1195          /**          /**
1196           * Updates the channel settings. This method is invoked when changes to the           * Updates the channel settings. This method is invoked when changes to the
1197           * channel were made.           * channel were made.
# Line 909  class ChannelProperties extends JPanel { Line 1218  class ChannelProperties extends JPanel {
1218                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
1219                  }                  }
1220                                    
1221                    if(sc.getEngine() != null) {
1222                            if(cbInstrumentMap.getItemCount() > 0) cbInstrumentMap.setEnabled(true);
1223                    } else {
1224                            cbInstrumentMap.setSelectedItem(noMap);
1225                            cbInstrumentMap.setEnabled(false);
1226                    }
1227                    
1228                  setUpdate(false);                  setUpdate(false);
1229          }          }
1230                    
# Line 967  class ChannelProperties extends JPanel { Line 1283  class ChannelProperties extends JPanel {
1283                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();
1284                                    
1285                  if(!isUpdate()) {                  if(!isUpdate()) {
1286                          if(mid != null) getModel().setMidiInputDevice(mid.getDeviceID());                          if(mid != null) getModel().setBackendMidiInputDevice(mid.getDeviceId());
1287                          return;                          return;
1288                  }                  }
1289                                    
# Line 999  class ChannelProperties extends JPanel { Line 1315  class ChannelProperties extends JPanel {
1315          setMidiPort() {          setMidiPort() {
1316                  if(isUpdate()) return;                  if(isUpdate()) return;
1317                                    
1318                  getModel().setMidiInputPort(cbMidiPort.getSelectedIndex());                  getModel().setBackendMidiInputPort(cbMidiPort.getSelectedIndex());
1319          }          }
1320                    
1321          private void          private void
# Line 1011  class ChannelProperties extends JPanel { Line 1327  class ChannelProperties extends JPanel {
1327                                    
1328                  int c = o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()) - 1;                  int c = o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()) - 1;
1329                                    
1330                  getModel().setMidiInputChannel(c);                  getModel().setBackendMidiInputChannel(c);
1331          }          }
1332                    
1333          /** Invoked when the user selects an engine. */          /** Invoked when the user selects an engine. */
# Line 1023  class ChannelProperties extends JPanel { Line 1339  class ChannelProperties extends JPanel {
1339                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }
1340                  else if(newEngine == null) return;                  else if(newEngine == null) return;
1341                                    
1342                  getModel().setEngineType(newEngine.getName());                  getModel().setBackendEngineType(newEngine.getName());
1343                                    
1344          }          }
1345                    
# Line 1031  class ChannelProperties extends JPanel { Line 1347  class ChannelProperties extends JPanel {
1347          setAudioDevice() {          setAudioDevice() {
1348                  if(isUpdate()) return;                  if(isUpdate()) return;
1349                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();
1350                  if(dev != null) getModel().setAudioOutputDevice(dev.getDeviceID());                  if(dev != null) getModel().setBackendAudioOutputDevice(dev.getDeviceId());
1351          }          }
1352                    
1353          /**          /**
# Line 1057  class ChannelProperties extends JPanel { Line 1373  class ChannelProperties extends JPanel {
1373          getHandler() { return handler; }          getHandler() { return handler; }
1374                    
1375          private class Handler implements MidiDeviceListListener,          private class Handler implements MidiDeviceListListener,
1376                                  AudioDeviceListListener, SamplerChannelListListener {                                  ListListener<AudioDeviceModel>, SamplerChannelListListener {
1377                                    
1378                  /**                  /**
1379                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
# Line 1085  class ChannelProperties extends JPanel { Line 1401  class ChannelProperties extends JPanel {
1401                   * instance providing the event information.                   * instance providing the event information.
1402                   */                   */
1403                  public void                  public void
1404                  deviceAdded(AudioDeviceListEvent e) {                  entryAdded(ListEvent<AudioDeviceModel> e) {
1405                          cbAudioDevice.addItem(e.getAudioDeviceModel().getDeviceInfo());                          cbAudioDevice.addItem(e.getEntry().getDeviceInfo());
1406                  }                  }
1407                    
1408                  /**                  /**
# Line 1095  class ChannelProperties extends JPanel { Line 1411  class ChannelProperties extends JPanel {
1411                   * instance providing the event information.                   * instance providing the event information.
1412                   */                   */
1413                  public void                  public void
1414                  deviceRemoved(AudioDeviceListEvent e) {                  entryRemoved(ListEvent<AudioDeviceModel> e) {
1415                          cbAudioDevice.removeItem(e.getAudioDeviceModel().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1416                  }                  }
1417                                    
1418                  /**                  /**
# Line 1115  class ChannelProperties extends JPanel { Line 1431  class ChannelProperties extends JPanel {
1431                  public void                  public void
1432                  channelRemoved(SamplerChannelListEvent e) {                  channelRemoved(SamplerChannelListEvent e) {
1433                          // Some cleanup when the channel is removed.                          // Some cleanup when the channel is removed.
1434                          if(e.getChannelModel().getChannelID() == channelModel.getChannelID()) {                          if(e.getChannelModel().getChannelId() == channelModel.getChannelId()) {
1435                                  CC.getSamplerModel().removeMidiDeviceListListener(getHandler());                                  CC.getSamplerModel().removeMidiDeviceListListener(getHandler());
1436                                  CC.getSamplerModel().removeAudioDeviceListListener(getHandler());                                  CC.getSamplerModel().removeAudioDeviceListListener(getHandler());
1437                          }                          }
1438                  }                  }
1439          }          }
1440            
1441            private class MapListListener implements ListListener<MidiInstrumentMap> {
1442                    /** Invoked when a new MIDI instrument map is added to a list. */
1443                    public void
1444                    entryAdded(ListEvent<MidiInstrumentMap> e) {
1445                            //cbInstrumentMap.addItem(e.getEntry());
1446                            cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());
1447                            boolean b = getModel().getChannelInfo().getEngine() != null;
1448                            if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);
1449                    }
1450            
1451                    /** Invoked when a new MIDI instrument map is removed from a list. */
1452                    public void
1453                    entryRemoved(ListEvent<MidiInstrumentMap> e) {
1454                            cbInstrumentMap.removeItem(e.getEntry());
1455                            if(cbInstrumentMap.getItemCount() == 0) {
1456                                    cbInstrumentMap.setSelectedItem(noMap);
1457                                    cbInstrumentMap.setEnabled(false);
1458                            }
1459                    }
1460            }
1461  }  }

Legend:
Removed from v.911  
changed lines
  Added in v.1143

  ViewVC Help
Powered by ViewVC