/[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 842 by iliev, Thu Mar 16 18:08:34 2006 UTC revision 1540 by iliev, Mon Dec 3 23:22:02 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 29  import java.awt.GridBagConstraints; Line 30  import java.awt.GridBagConstraints;
30  import java.awt.GridBagLayout;  import java.awt.GridBagLayout;
31  import java.awt.Insets;  import java.awt.Insets;
32    
33    import java.awt.datatransfer.Transferable;
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;
40    import java.awt.event.MouseEvent;
41    import java.awt.event.MouseMotionAdapter;
42    
43  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
44  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
# Line 41  import java.util.Vector; Line 49  import java.util.Vector;
49    
50  import java.util.logging.Level;  import java.util.logging.Level;
51    
52    import javax.swing.Action;
53    import javax.swing.AbstractAction;
54  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
55  import javax.swing.Box;  import javax.swing.Box;
56  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
57    import javax.swing.JComponent;
58  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
59  import javax.swing.JButton;  import javax.swing.JButton;
60  import javax.swing.JComboBox;  import javax.swing.JComboBox;
# Line 52  import javax.swing.JPanel; Line 63  import javax.swing.JPanel;
63  import javax.swing.JSeparator;  import javax.swing.JSeparator;
64  import javax.swing.JSlider;  import javax.swing.JSlider;
65  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
66    import javax.swing.JToolBar;
67    import javax.swing.TransferHandler;
68    
69  import javax.swing.border.Border;  import javax.swing.border.Border;
70  import javax.swing.border.LineBorder;  import javax.swing.border.LineBorder;
71    import javax.swing.border.TitledBorder;
72    
73  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
74  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
75    
76    import net.sf.juife.InformationDialog;
77  import net.sf.juife.JuifeUtils;  import net.sf.juife.JuifeUtils;
78    
 import org.jsampler.CC;  
79  import org.jsampler.AudioDeviceModel;  import org.jsampler.AudioDeviceModel;
80    import org.jsampler.CC;
81    import org.jsampler.HF;
82    import org.jsampler.OrchestraInstrument;
83  import org.jsampler.MidiDeviceModel;  import org.jsampler.MidiDeviceModel;
84    import org.jsampler.MidiInstrumentMap;
85  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
86  import org.jsampler.SamplerModel;  import org.jsampler.SamplerModel;
87    
88  import org.jsampler.event.AudioDeviceListEvent;  import org.jsampler.event.ListEvent;
89  import org.jsampler.event.AudioDeviceListListener;  import org.jsampler.event.ListListener;
90    import org.jsampler.event.MidiDeviceEvent;
91  import org.jsampler.event.MidiDeviceListEvent;  import org.jsampler.event.MidiDeviceListEvent;
92  import org.jsampler.event.MidiDeviceListListener;  import org.jsampler.event.MidiDeviceListListener;
93    import org.jsampler.event.MidiDeviceListener;
94    import org.jsampler.event.SamplerAdapter;
95  import org.jsampler.event.SamplerChannelAdapter;  import org.jsampler.event.SamplerChannelAdapter;
96  import org.jsampler.event.SamplerChannelEvent;  import org.jsampler.event.SamplerChannelEvent;
97    import org.jsampler.event.SamplerChannelListEvent;
98    import org.jsampler.event.SamplerChannelListListener;
99  import org.jsampler.event.SamplerChannelListener;  import org.jsampler.event.SamplerChannelListener;
100    import org.jsampler.event.SamplerEvent;
101    import org.jsampler.event.SamplerListener;
102    
103    import org.jsampler.view.std.JSChannelOutputRoutingDlg;
104    import org.jsampler.view.std.JSFxSendsPane;
105    import org.jsampler.view.std.JSInstrumentChooser;
106    
107  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
108  import org.linuxsampler.lscp.MidiInputDevice;  import org.linuxsampler.lscp.MidiInputDevice;
# Line 82  import org.linuxsampler.lscp.SamplerChan Line 111  import org.linuxsampler.lscp.SamplerChan
111  import org.linuxsampler.lscp.SamplerEngine;  import org.linuxsampler.lscp.SamplerEngine;
112    
113  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
114    import static org.jsampler.view.classic.ClassicPrefs.preferences;
115    import static org.jsampler.view.std.StdPrefs.*;
116    
117    
118  /**  /**
# Line 89  import static org.jsampler.view.classic. Line 120  import static org.jsampler.view.classic.
120   * @author Grigor Iliev   * @author Grigor Iliev
121   */   */
122  public class Channel extends org.jsampler.view.JSChannel {  public class Channel extends org.jsampler.view.JSChannel {
123            private final static ImageIcon iconEdit;
124            
125          private final static ImageIcon iconMuteOn;          private final static ImageIcon iconMuteOn;
126          private final static ImageIcon iconMuteOff;          private final static ImageIcon iconMuteOff;
127          private final static ImageIcon iconMutedBySolo;          private final static ImageIcon iconMutedBySolo;
# Line 100  public class Channel extends org.jsample Line 133  public class Channel extends org.jsample
133          private final static ImageIcon iconHideProperties;          private final static ImageIcon iconHideProperties;
134                    
135          private static Border borderSelected;          private static Border borderSelected;
136            private static Border borderHighlighted;
137          private static Border borderDeselected;          private static Border borderDeselected;
138                    
139            private static Color chnColor;
140          private static Color borderColor;          private static Color borderColor;
141            private static Color borderHighlightedColor;
142            private static Color chnSelectedColor;
143            private static Color chnHighlightedColor;
144                    
145          private final static Vector<PropertyChangeListener> propertyChangeListeners          private final static Vector<PropertyChangeListener> propertyChangeListeners
146                  = new Vector<PropertyChangeListener>();                  = new Vector<PropertyChangeListener>();
147                    
148          static {          static {
149                    iconEdit = new ImageIcon(Channel.class.getResource("res/icons/edit.png"));
150                    
151                  String path = "org/jsampler/view/classic/res/icons/";                  String path = "org/jsampler/view/classic/res/icons/";
152                  URL url = ClassLoader.getSystemClassLoader().getResource(path + "mute_on.png");                  URL url = ClassLoader.getSystemClassLoader().getResource(path + "mute_on.png");
153                  iconMuteOn = new ImageIcon(url);                  iconMuteOn = new ImageIcon(url);
# Line 127  public class Channel extends org.jsample Line 167  public class Channel extends org.jsample
167                  url = ClassLoader.getSystemClassLoader().getResource(path + "Back16.gif");                  url = ClassLoader.getSystemClassLoader().getResource(path + "Back16.gif");
168                  iconShowProperties = new ImageIcon(url);                  iconShowProperties = new ImageIcon(url);
169                                    
170                  url = ClassLoader.getSystemClassLoader().getResource(path + "Down16.gif");                  iconHideProperties = Res.iconDown16;
                 iconHideProperties = new ImageIcon(url);  
171                                    
172                  if(ClassicPrefs.getCustomChannelBorderColor())                  if(ClassicPrefs.getCustomChannelBorderColor())
173                          setBorderColor(ClassicPrefs.getChannelBorderColor());                          setBorderColor(ClassicPrefs.getChannelBorderColor());
174                  else setBorderColor(ClassicPrefs.getDefaultChannelBorderColor());                  else setBorderColor(ClassicPrefs.getDefaultChannelBorderColor());
175                                    
176                    if(ClassicPrefs.getCustomChannelBorderHlColor())
177                            setBorderHighlightedColor(ClassicPrefs.getChannelBorderHlColor());
178                    else setBorderHighlightedColor(ClassicPrefs.getDefaultChannelBorderHlColor());
179                    
180                  borderSelected = new LineBorder(getBorderColor(), 2, true);                  borderSelected = new LineBorder(getBorderColor(), 2, true);
181                    borderHighlighted = new LineBorder(getBorderHighlightedColor(), 2, true);
182                  borderDeselected = BorderFactory.createEmptyBorder(2, 2, 2, 2);                  borderDeselected = BorderFactory.createEmptyBorder(2, 2, 2, 2);
183                    
184                    chnColor = new JPanel().getBackground();
185                    
186                    if(ClassicPrefs.getCustomSelectedChannelBgColor()) {
187                            chnSelectedColor = ClassicPrefs.getSelectedChannelBgColor();
188                    } else {
189                            int r = chnColor.getRed() - 14 < 0 ? 0 : chnColor.getRed() - 14;
190                            int g = chnColor.getGreen() - 8 < 0 ? 0 : chnColor.getGreen() - 8;
191                            int b = chnColor.getBlue() - 3 < 0 ? 0 : chnColor.getBlue() - 3;
192                    
193                            chnSelectedColor = new Color(r, g, b);
194                    }
195                    
196                    /*r = r + 5 > 255 ? 255 : r + 5;
197                    g = g + 4 > 255 ? 255 : g + 4;
198                    b = b + 1 > 255 ? 255 : b + 1;*/
199                    
200                    chnHighlightedColor = new Color(chnColor.getRGB());
201          }          }
202                    
203          /**          /**
# Line 177  public class Channel extends org.jsample Line 239  public class Channel extends org.jsample
239                  firePropertyChanged("borderColor", oldColor, borderColor);                  firePropertyChanged("borderColor", oldColor, borderColor);
240          }          }
241                    
242            /**
243             * Gets the border color that is used when the mouse pointer is over a channel.
244             * @return The border color that is used when the mouse pointer is over a channel.
245             */
246            public static Color
247            getBorderHighlightedColor() { return borderHighlightedColor; }
248            
249            /**
250             * Sets the border color to be used when the mouse pointer is over a channel.
251             * @param c The border color to be used when the mouse pointer is over a channel.
252             */
253            public static void
254            setBorderHighlightedColor(Color c) {
255                    Color oldColor = borderHighlightedColor;
256                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
257                    
258                    borderHighlightedColor = c;
259                    borderHighlighted = new LineBorder(getBorderHighlightedColor(), 2, true);
260                    firePropertyChanged("borderHighlightedColor", oldColor, borderHighlightedColor);
261            }
262            
263            /**
264             * Gets the background color that is used when a channel is selected.
265             * @return The background color that is used when a channel is selected.
266             */
267            public static Color
268            getSelectedChannelBgColor() { return chnSelectedColor; }
269            
270            /**
271             * Sets the background color that is used when a channel is selected.
272             * @param c The background color to be used when a channel is selected.
273             */
274            public static void
275            setSelectedChannelBgColor(Color c) {
276                    Color oldColor = chnSelectedColor;
277                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
278                    
279                    chnSelectedColor = c;
280                    firePropertyChanged("selectedChannelBgColor", oldColor, chnSelectedColor);
281            }
282            
283            /**
284             * Gets the background color that is used when the mouse pointer is over a channel.
285             * @return The background color that is used when the mouse pointer is over a channel.
286             */
287            public static Color
288            getHighlightedChannelBgColor() { return chnHighlightedColor; }
289            
290            /**
291             * Sets the background color to be used when the mouse pointer is over a channel.
292             * @param c The background color to be used when the mouse pointer is over a channel.
293             */
294            public static void
295            setHighlightedChannelBgColor(Color c) {
296                    Color oldColor = chnHighlightedColor;
297                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
298                    
299                    chnHighlightedColor = c;
300                    firePropertyChanged("highlightedChannelBgColor", oldColor, chnHighlightedColor);
301            }
302            
303          private static void          private static void
304          firePropertyChanged(String propertyName, Object oldValue, Object newValue) {          firePropertyChanged(String propertyName, Object oldValue, Object newValue) {
305                  PropertyChangeEvent e =                  PropertyChangeEvent e =
# Line 188  public class Channel extends org.jsample Line 311  public class Channel extends org.jsample
311                    
312          private final JPanel mainPane = new JPanel();          private final JPanel mainPane = new JPanel();
313          private final ChannelProperties propertiesPane;          private final ChannelProperties propertiesPane;
314          private final JButton btnInstr = new JButton(i18n.getLabel("Channel.btnInstr"));          private final JButton btnInstr = new InstrumentButton(i18n.getLabel("Channel.btnInstr"));
315            private final Action actInstr;
316            private final JButton btnEdit = new JButton(iconEdit);
317          private final JButton btnMute = new JButton();          private final JButton btnMute = new JButton();
318          private final JButton btnSolo = new JButton();          private final JButton btnSolo = new JButton();
319          private final JSlider slVolume = new JSlider(0, 100);          private final JSlider slVolume = new JSlider(0, 100);
320          private final JLabel lVolume = new JLabel();          private final JLabel lVolume = new JLabel();
321            private final JLabel lVolImg = new JLabel(Res.iconVolume16);
322          private final JLabel lStreams = new JLabel("--");          private final JLabel lStreams = new JLabel("--");
323          private final JLabel lVoices = new JLabel("--");          private final JLabel lVoices = new JLabel("--");
324          private final JToggleButton btnProperties = new JToggleButton();          private final JToggleButton btnProperties = new JToggleButton();
325                    
         private final EventHandler eventHandler = new EventHandler();  
           
326          private static int count = 2;          private static int count = 2;
327                    
328          private boolean selected = false;          private boolean selected = false;
329            private boolean mouseOver = false;
330                    
331                    
332          /**          /**
# Line 217  public class Channel extends org.jsample Line 342  public class Channel extends org.jsample
342                  setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));                  setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
343                                    
344                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
345                    addMouseListener(getHandler());
346                    addHierarchyListener(getHandler());
347                                    
348                  JPanel p = new JPanel();                  JPanel p = new JPanel();
349                    p.setOpaque(false);
350                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
351                  p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));                  p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
352                                    
353                  //setToolTipText(" Channel: " + String.valueOf(getChannelID()) + " ");                  setToolTipText(i18n.getLabel("Channel.tt", getModel().getChannelId()));
354                                    
355                  Dimension d = btnInstr.getPreferredSize();                  Dimension d = btnInstr.getPreferredSize();
356                  btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, d.height));                  btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, d.height));
357                  p.add(btnInstr);                  p.add(btnInstr);
358                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  p.add(Box.createRigidArea(new Dimension(6, 0)));
359                                    
360                    btnEdit.setToolTipText(i18n.getLabel("Channel.btnEdit.tt"));
361                    btnEdit.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
362                    p.add(btnEdit);
363                    p.add(Box.createRigidArea(new Dimension(6, 0)));
364                    
365                  lStreams.setHorizontalAlignment(JLabel.CENTER);                  lStreams.setHorizontalAlignment(JLabel.CENTER);
366                  lVoices.setHorizontalAlignment(JLabel.CENTER);                  lVoices.setHorizontalAlignment(JLabel.CENTER);
367                                    
368                  JPanel statPane = new JPanel();                  JPanel statPane = new JPanel();
369                    statPane.setOpaque(false);
370                  statPane.setBorder(BorderFactory.createLoweredBevelBorder());                  statPane.setBorder(BorderFactory.createLoweredBevelBorder());
371                  statPane.setLayout(new BoxLayout(statPane, BoxLayout.X_AXIS));                  statPane.setLayout(new BoxLayout(statPane, BoxLayout.X_AXIS));
372                  statPane.add(Box.createRigidArea(new Dimension(6, 0)));                  statPane.add(Box.createRigidArea(new Dimension(6, 0)));
# Line 254  public class Channel extends org.jsample Line 388  public class Channel extends org.jsample
388                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  p.add(Box.createRigidArea(new Dimension(6, 0)));
389                                    
390                  JPanel volumePane = new JPanel();                  JPanel volumePane = new JPanel();
391                    volumePane.setOpaque(false);
392                  volumePane.setBorder(BorderFactory.createLoweredBevelBorder());                  volumePane.setBorder(BorderFactory.createLoweredBevelBorder());
393                  volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));                  volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));
394                  volumePane.add(Box.createRigidArea(new Dimension(6, 0)));                  volumePane.add(Box.createRigidArea(new Dimension(6, 0)));
395                                    
396                    volumePane.add(lVolImg);
397                    volumePane.add(Box.createRigidArea(new Dimension(1, 0)));
398                    
399                  d = slVolume.getPreferredSize();                  d = slVolume.getPreferredSize();
400                  slVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));                  slVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));
401                    slVolume.setOpaque(false);
402                  volumePane.add(slVolume);                  volumePane.add(slVolume);
403                                    
404                  lVolume.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));                  lVolume.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));
# Line 291  public class Channel extends org.jsample Line 430  public class Channel extends org.jsample
430                  d = getPreferredSize();                  d = getPreferredSize();
431                  setMaximumSize(new Dimension(getMaximumSize().width, d.height));                  setMaximumSize(new Dimension(getMaximumSize().width, d.height));
432                                    
433                    int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
434                    slVolume.setMaximum(i);
435                    String mcv = MAXIMUM_CHANNEL_VOLUME;
436                    preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() {
437                            public void
438                            propertyChange(PropertyChangeEvent e) {
439                                    int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
440                                    slVolume.setMaximum(j);
441                            }
442                    });
443                    
444                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
445                                    
446                  btnInstr.addActionListener(new ActionListener() {                  actInstr = new AbstractAction() {
447                            public void
448                            actionPerformed(ActionEvent e) {
449                                    if(actInstr.isEnabled()) loadInstrument();
450                            }
451                    };
452                    
453                    btnInstr.addActionListener(actInstr);
454                    
455                    btnEdit.addActionListener(new ActionListener() {
456                          public void                          public void
457                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) {
458                                    CC.getSamplerModel().editBackendInstrument(getChannelId());
459                            }
460                  });                  });
461                                    
462                  btnMute.addActionListener(new ActionListener() {                  btnMute.addActionListener(new ActionListener() {
# Line 342  public class Channel extends org.jsample Line 503  public class Channel extends org.jsample
503                  updateChannelInfo();                  updateChannelInfo();
504          }          }
505                    
506            public class InstrumentButton extends JButton {
507                    private boolean dragging = false;
508                    
509                    InstrumentButton(String s) {
510                            super(s);
511                            
512                            setTransferHandler(new TransferHandler("instrument"));
513                            
514                            addMouseListener(new MouseAdapter() {
515                                    public void
516                                    mouseExited(MouseEvent e) {
517                                            if(!dragging) return;
518                                            
519                                            int b1 = e.BUTTON1_DOWN_MASK;
520                                            if((e.getModifiersEx() & b1) != b1) return;
521                                            
522                                            actInstr.setEnabled(false);
523                                            doClick(0);
524                                            actInstr.setEnabled(true);
525                                            
526                                            JComponent c = (JComponent)e.getSource();
527                                            TransferHandler handler = c.getTransferHandler();
528                                            handler.exportAsDrag(c, e, TransferHandler.COPY);
529                                    }
530                                    
531                                    public void
532                                    mouseReleased(MouseEvent e) { dragging = false; }
533                            });
534                            
535                            addMouseMotionListener(new MouseMotionAdapter() {
536                                    public void
537                                    mouseDragged(MouseEvent e) { dragging = true; }
538                            });
539                    }
540                    
541                    public String
542                    getInstrument() {
543                            SamplerChannel sc = Channel.this.getChannelInfo();
544                            
545                            if(sc.getInstrumentName() == null || sc.getInstrumentStatus() < 0)
546                                    return null;
547                            
548                            OrchestraInstrument instr = new OrchestraInstrument();
549                            instr.setName(sc.getInstrumentName());
550                            instr.setInstrumentIndex(sc.getInstrumentIndex());
551                            instr.setFilePath(sc.getInstrumentFile());
552                            return instr.getDnDString();
553                    }
554                    
555                    public void setInstrument(String instr) {
556                            if(!OrchestraInstrument.isDnDString(instr)) return;
557                            
558                            String[] args = instr.split("\n");
559                            if(args.length < 6) return;
560                            
561                            try {
562                                    int idx = Integer.parseInt(args[5]);
563                                    Channel.this.getModel().loadBackendInstrument(args[4], idx);
564                            } catch(Exception x) {
565                                    CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
566                            }
567                    }
568            }
569            
570            private final EventHandler eventHandler = new EventHandler();
571            
572          private EventHandler          private EventHandler
573          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
574                    
575          private class EventHandler implements SamplerChannelListener, PropertyChangeListener {          private class EventHandler extends MouseAdapter implements SamplerChannelListener,
576                                                            PropertyChangeListener, HierarchyListener {
577                  /**                  /**
578                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
579                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 376  public class Channel extends org.jsample Line 604  public class Channel extends org.jsample
604                                    
605                  public void                  public void
606                  propertyChange(PropertyChangeEvent e) {                  propertyChange(PropertyChangeEvent e) {
607                          if(e.getPropertyName() == "borderColor") setSelected(isSelected());                          if (
608                                    e.getPropertyName() == "borderColor" ||
609                                    e.getPropertyName() == "borderHighlightedColor" ||
610                                    e.getPropertyName() == "selectedChannelBgColor" ||
611                                    e.getPropertyName() == "highlightedChannelBgColor"
612                            ) {
613                                    updateColors(isSelected());
614                            }
615                    }
616                    
617                    public void
618                    mouseEntered(MouseEvent e) {
619                            mouseOver = true;
620                            updateColors(isSelected());
621                    }
622                    
623                    public void
624                    mouseExited(MouseEvent e) {
625                            if(getMousePosition(true) != null) return;
626                            
627                            mouseOver = false;
628                            updateColors(isSelected());
629                    }
630                    
631                    
632            
633                    /** Called when the hierarchy has been changed. */
634                    public void
635                    hierarchyChanged(HierarchyEvent e) {
636                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
637                                    if(getMousePosition() == null) mouseExited(null);
638                                    else mouseEntered(null);
639                            }
640                  }                  }
641          }          }
642                    
# Line 394  public class Channel extends org.jsample Line 654  public class Channel extends org.jsample
654           */           */
655          public void          public void
656          setSelected(boolean select) {          setSelected(boolean select) {
657                  if(select)  mainPane.setBorder(borderSelected);                  updateColors(select);
                 else mainPane.setBorder(borderDeselected);  
658                                    
659                  selected = select;                  selected = select;
660          }          }
661                    
662            /**
663             * Updates the channel background and border colors.
664             * @param selected Specifies the selection state of this channel.
665             */
666            private void
667            updateColors(boolean selected) {
668                    if(selected) {
669                            mainPane.setBorder(borderSelected);
670                            mainPane.setBackground(chnSelectedColor);
671                    } else {
672                            if(mouseOver) {
673                                    mainPane.setBorder(borderHighlighted);
674                                    mainPane.setBackground(chnHighlightedColor);
675                            } else {
676                                    mainPane.setBorder(borderDeselected);
677                                    mainPane.setBackground(chnColor);
678                            }
679                    }
680            }
681            
682          /** Hides the channel properties. */          /** Hides the channel properties. */
683          public void          public void
684          collapseChannel() { if(btnProperties.isSelected()) btnProperties.doClick(); }          collapseChannel() { if(btnProperties.isSelected()) btnProperties.doClick(); }
# Line 419  public class Channel extends org.jsample Line 698  public class Channel extends org.jsample
698                  int status = sc.getInstrumentStatus();                  int status = sc.getInstrumentStatus();
699                  if(status >= 0 && status < 100) {                  if(status >= 0 && status < 100) {
700                          btnInstr.setText(i18n.getLabel("Channel.loadingInstrument", status));                          btnInstr.setText(i18n.getLabel("Channel.loadingInstrument", status));
701                    } else if(status == -1) {
702                            btnInstr.setText(i18n.getLabel("Channel.btnInstr"));
703                    } else if(status < -1) {
704                             btnInstr.setText(i18n.getLabel("Channel.errorLoadingInstrument"));
705                  } else {                  } else {
706                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
707                          else btnInstr.setText(i18n.getLabel("Channel.btnInstr"));                          else btnInstr.setText(i18n.getLabel("Channel.btnInstr"));
708                  }                  }
709                                    
710                  updateMute(sc);                  boolean b = status == 100;
711                    if(btnEdit.isEnabled() != b) btnEdit.setEnabled(b);
712                    
713                    updateMuteIcon(sc);
714                                    
715                  if(sc.isSoloChannel()) btnSolo.setIcon(iconSoloOn);                  if(sc.isSoloChannel()) btnSolo.setIcon(iconSoloOn);
716                  else btnSolo.setIcon(iconSoloOff);                  else btnSolo.setIcon(iconSoloOff);
717                                    
718                  slVolume.setValue((int)(sc.getVolume() * 100));                  slVolume.setValue((int)(sc.getVolume() * 100));
719                                    
720                  boolean b = sc.getEngine() != null;                  b = sc.getEngine() != null;
721                  slVolume.setEnabled(b);                  slVolume.setEnabled(b);
722                  btnSolo.setEnabled(b);                  btnSolo.setEnabled(b);
723                  btnMute.setEnabled(b);                  btnMute.setEnabled(b);
# Line 455  public class Channel extends org.jsample Line 741  public class Channel extends org.jsample
741                          else btnMute.setIcon(iconMutedBySolo);                          else btnMute.setIcon(iconMutedBySolo);
742                  } else btnMute.setIcon(iconMuteOn);                  } else btnMute.setIcon(iconMuteOn);
743                                    
744                  getModel().setMute(b);                  getModel().setBackendMute(b);
745          }          }
746                    
747          /** Invoked when the user clicks the solo button. */          /** Invoked when the user clicks the solo button. */
# Line 477  public class Channel extends org.jsample Line 763  public class Channel extends org.jsample
763                                  btnMute.setIcon(iconMutedBySolo);                                  btnMute.setIcon(iconMutedBySolo);
764                  }                  }
765                                    
766                  getModel().setSolo(b);                  getModel().setBackendSolo(b);
767          }          }
768                    
769          /** Invoked when the user changes the volume */          /** Invoked when the user changes the volume */
# Line 498  public class Channel extends org.jsample Line 784  public class Channel extends org.jsample
784                   */                   */
785                  float volume = slVolume.getValue();                  float volume = slVolume.getValue();
786                  volume /= 100;                  volume /= 100;
787                  getModel().setVolume(volume);                  getModel().setBackendVolume(volume);
788          }          }
789                    
790          private void          private void
791          updateVolume() {          updateVolume() {
792                  int volume = slVolume.getValue();                  int volume = slVolume.getValue();
793                  slVolume.setToolTipText(i18n.getLabel("Channel.volume", volume));                  slVolume.setToolTipText(i18n.getLabel("Channel.volume", volume));
794                    lVolImg.setToolTipText(i18n.getLabel("Channel.volume", volume));
795                                    
796                  setVolumeLabel(volume);                  setVolumeLabel(volume);
797                                    
# Line 528  public class Channel extends org.jsample Line 815  public class Channel extends org.jsample
815           * for this channel.           * for this channel.
816           */           */
817          private void          private void
818          updateMute(SamplerChannel channel) {          updateMuteIcon(SamplerChannel channel) {
819                  if(channel.isMutedBySolo()) btnMute.setIcon(iconMutedBySolo);                  if(channel.isMutedBySolo()) btnMute.setIcon(iconMutedBySolo);
820                  else if(channel.isMuted()) btnMute.setIcon(iconMuteOn);                  else if(channel.isMuted()) btnMute.setIcon(iconMuteOn);
821                  else btnMute.setIcon(iconMuteOff);                  else btnMute.setIcon(iconMuteOff);
# Line 567  public class Channel extends org.jsample Line 854  public class Channel extends org.jsample
854                    
855          private void          private void
856          loadInstrument() {          loadInstrument() {
857                  InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());
858                  dlg.setVisible(true);                  dlg.setVisible(true);
859                                    
860                  if(!dlg.isCancelled()) {                  if(dlg.isCancelled()) return;
861                          getModel().loadInstrument(dlg.getFileName(), dlg.getInstrumentIndex());                  
862                    SamplerEngine engine = getChannelInfo().getEngine();
863                    if(dlg.getEngine() != null) {
864                            if(engine == null || !dlg.getEngine().equals(engine.getName()));
865                                    getModel().setBackendEngineType(dlg.getEngine());
866                  }                  }
867                    
868                    int idx = dlg.getInstrumentIndex();
869                    getModel().loadBackendInstrument(dlg.getInstrumentFile(), idx);
870                    
871          }          }
872  }  }
873    
874  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);  
         }  
           
875          private final JLabel lMidiDevice =          private final JLabel lMidiDevice =
876                  new JLabel(i18n.getLabel("ChannelProperties.lMidiDevice"));                  new JLabel(i18n.getLabel("ChannelProperties.lMidiDevice"));
877          private final JLabel lMidiPort =          private final JLabel lMidiPort =
# Line 592  class ChannelProperties extends JPanel { Line 879  class ChannelProperties extends JPanel {
879          private final JLabel lMidiChannel =          private final JLabel lMidiChannel =
880                  new JLabel(i18n.getLabel("ChannelProperties.lMidiChannel"));                  new JLabel(i18n.getLabel("ChannelProperties.lMidiChannel"));
881                    
882            private final JLabel lInstrumentMap =
883                    new JLabel(i18n.getLabel("ChannelProperties.lInstrumentMap"));
884            
885          private final JLabel lAudioDevice =          private final JLabel lAudioDevice =
886                  new JLabel(i18n.getLabel("ChannelProperties.lAudioDevice"));                  new JLabel(i18n.getLabel("ChannelProperties.lAudioDevice"));
887                    
888          private final JComboBox cbEngines = new JComboBox();          private final JComboBox cbEngines = new JComboBox();
889                    
890            private final JComboBox cbInstrumentMap = new JComboBox();
891          private final JComboBox cbMidiDevice = new JComboBox();          private final JComboBox cbMidiDevice = new JComboBox();
892          private final JComboBox cbMidiPort = new JComboBox();          private final JComboBox cbMidiPort = new JComboBox();
893          private final JComboBox cbMidiChannel = new JComboBox();          private final JComboBox cbMidiChannel = new JComboBox();
894          private final JComboBox cbAudioDevice = new JComboBox();          private final JComboBox cbAudioDevice = new JComboBox();
895                    
896          private final JButton btnAudioProps = new JButton(iconAudioProps);          private final JButton btnFxSends = new JButton(Res.iconFxSends22);
897            private final JButton btnAudioProps = new JButton(Res.iconAudioProps16);
898            private InformationDialog fxSendsDlg = null;
899                    
900          private SamplerChannelModel channelModel = null;          private SamplerChannelModel channelModel = null;
901            private MidiDeviceModel midiDevice = null;
902                    
903          private boolean update = false;          private boolean update = false;
904                    
905            private final SamplerListener samplerListener;
906            private final MapListListener mapListListener = new MapListListener();
907            
908            private class NoMap {
909                    public String
910                    toString() { return "[None]"; }
911            }
912            
913            private NoMap noMap = new NoMap();
914            
915            private class DefaultMap {
916                    public String
917                    toString() { return "[Default]"; }
918            }
919            
920            private DefaultMap defaultMap = new DefaultMap();
921            
922          /**          /**
923           * 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
924           * channel model.           * channel model.
# Line 617  class ChannelProperties extends JPanel { Line 928  class ChannelProperties extends JPanel {
928                  channelModel = model;                  channelModel = model;
929                                    
930                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
931                    setOpaque(false);
932                                    
933                  add(new JSeparator());                  add(new JSeparator());
934                                    
935                  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));  
936                                    
937                  JPanel devicesPane = new JPanel();                  JPanel devicesPane = new JPanel();
938                    devicesPane.setOpaque(false);
939                  devicesPane.setLayout(new BoxLayout(devicesPane, BoxLayout.X_AXIS));                  devicesPane.setLayout(new BoxLayout(devicesPane, BoxLayout.X_AXIS));
940                                    
941                  devicesPane.add(Box.createRigidArea(new Dimension(3, 0)));                  devicesPane.add(Box.createRigidArea(new Dimension(3, 0)));
# Line 688  class ChannelProperties extends JPanel { Line 993  class ChannelProperties extends JPanel {
993                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }
994                  });                  });
995                                    
996                    samplerListener = new SamplerAdapter() {
997                            /** Invoked when the default MIDI instrument map is changed. */
998                            public void
999                            defaultMapChanged(SamplerEvent e) {
1000                                    updateCbInstrumentMapToolTipText();
1001                            }
1002                    };
1003                    
1004                    CC.getSamplerModel().addSamplerListener(samplerListener);
1005                    
1006                    cbInstrumentMap.addItem(noMap);
1007                    cbInstrumentMap.addItem(defaultMap);
1008                    for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) {
1009                            cbInstrumentMap.addItem(map);
1010                    }
1011                    
1012                    int map = getModel().getChannelInfo().getMidiInstrumentMapId();
1013                    cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map));
1014                    if(cbInstrumentMap.getSelectedItem() == null) {
1015                            if(map == -1) cbInstrumentMap.setSelectedItem(noMap);
1016                            else if(map == -2) {
1017                                    cbInstrumentMap.setSelectedItem(defaultMap);
1018                            }
1019                    }
1020                    
1021                    updateCbInstrumentMapToolTipText();
1022                    
1023                    if(getModel().getChannelInfo().getEngine() == null) {
1024                            cbInstrumentMap.setEnabled(false);
1025                    }
1026                    
1027                    cbInstrumentMap.addActionListener(new ActionListener() {
1028                            public void
1029                            actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1030                    });
1031                    
1032                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());
1033                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());
1034                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
1035                    CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1036                                    
1037                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));
1038                    btnAudioProps.setEnabled(false);
1039                  btnAudioProps.addActionListener(new ActionListener() {                  btnAudioProps.addActionListener(new ActionListener() {
1040                          public void                          public void
1041                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
1042                                  SamplerChannel c = getModel().getChannelInfo();                                  SamplerChannel c = getModel().getChannelInfo();
1043                                  new ChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);                                  new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
1044                                                    
1045                          }                          }
1046                  });                  });
1047                                    
1048                                    btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelProperties.btnFxSends"));
1049                    btnFxSends.addActionListener(new ActionListener() {
1050                            public void
1051                            actionPerformed(ActionEvent e) {
1052                                    if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
1053                                            fxSendsDlg.toFront();
1054                                            return;
1055                                    }
1056                                    
1057                                    FxSendsPane p = new FxSendsPane(getModel());
1058                                    int id = getModel().getChannelId();
1059                                    fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
1060                                    fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id));
1061                                    fxSendsDlg.setModal(false);
1062                                    fxSendsDlg.showCloseButton(false);
1063                                    fxSendsDlg.setVisible(true);
1064                            }
1065                    });
1066                                    
1067                  updateMidiDevices();                  updateMidiDevices();
1068                  updateAudioDevices();                  updateAudioDevices();
1069                  updateChannelProperties();                  updateChannelProperties();
1070          }          }
1071            
1072            class FxSendsPane extends JSFxSendsPane {
1073                    FxSendsPane(SamplerChannelModel model) {
1074                            super(model);
1075                            
1076                            actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
1077                            actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
1078                    }
1079                    
1080                    protected JToolBar
1081                    createToolBar() {
1082                            JToolBar tb = new JToolBar();
1083                            Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
1084                            tb.setMaximumSize(d);
1085                            tb.setFloatable(false);
1086                            tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
1087                            
1088                            tb.add(new ToolbarButton(actionAddFxSend));
1089                            tb.add(new ToolbarButton(actionRemoveFxSend));
1090                    
1091                            return tb;
1092                    }
1093            }
1094            
1095            private JPanel
1096            createEnginePane() {
1097                    for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngines.addItem(e);
1098                    
1099                    cbEngines.setMaximumSize(cbEngines.getPreferredSize());
1100                    
1101                    JPanel p = new JPanel();
1102                    p.setOpaque(false);
1103                    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
1104                    p.add(cbEngines);
1105                    p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
1106                    
1107                    //enginesPane.add(Box.createGlue());
1108                    JPanel enginesPane = new JPanel();
1109                    enginesPane.setOpaque(false);
1110                    enginesPane.setLayout(new BorderLayout());
1111                    enginesPane.add(p, BorderLayout.SOUTH);
1112                    //enginesPane.add(Box.createRigidArea(new Dimension(0, 3)));
1113                    
1114                    String s = i18n.getLabel("ChannelProperties.enginesPane");
1115                    enginesPane.setBorder(BorderFactory.createTitledBorder(s));
1116                    Dimension d = new Dimension(enginesPane.getPreferredSize().width, Short.MAX_VALUE);
1117                    enginesPane.setMaximumSize(d);
1118                    return enginesPane;
1119            }
1120            
1121          private JPanel          private JPanel
1122          createMidiPane() {          createMidiPane() {
1123                  JPanel midiPane = new JPanel();                  JPanel midiPane = new JPanel();
1124                    midiPane.setOpaque(false);
1125                                    
1126                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
1127                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
1128                                    
1129                  midiPane.setLayout(gridbag);                  midiPane.setLayout(gridbag);
1130                                    
1131                  c.gridx = 0;                  c.gridx = 1;
1132                  c.gridy = 0;                  c.gridy = 0;
1133                  c.insets = new Insets(3, 3, 3, 3);                  c.insets = new Insets(0, 3, 3, 3);
1134                  gridbag.setConstraints(lMidiDevice, c);                  gridbag.setConstraints(lMidiDevice, c);
1135                  midiPane.add(lMidiDevice);                  midiPane.add(lMidiDevice);
1136                                    
                 c.gridx = 1;  
                 c.gridy = 0;  
                 gridbag.setConstraints(cbMidiDevice, c);  
                 midiPane.add(cbMidiDevice);  
                   
1137                  c.gridx = 2;                  c.gridx = 2;
1138                  c.gridy = 0;                  c.gridy = 0;
1139                  gridbag.setConstraints(lMidiPort, c);                  gridbag.setConstraints(lMidiPort, c);
1140                  midiPane.add(lMidiPort);                  midiPane.add(lMidiPort);
1141                                    
1142                  c.gridx = 4;                  c.gridx = 3;
1143                  c.gridy = 0;                  c.gridy = 0;
1144                  gridbag.setConstraints(lMidiChannel, c);                  gridbag.setConstraints(lMidiChannel, c);
1145                  midiPane.add(lMidiChannel);                  midiPane.add(lMidiChannel);
1146                                    
1147                  c.gridx = 5;                  c.gridx = 4;
1148                  c.gridy = 0;                  c.gridy = 0;
1149                  gridbag.setConstraints(cbMidiChannel, c);                  c.insets = new Insets(0, 10, 3, 3);
1150                  midiPane.add(cbMidiChannel);                  gridbag.setConstraints(lInstrumentMap, c);
1151                    midiPane.add(lInstrumentMap);
1152                                    
1153                  c.gridx = 3;                  btnFxSends.setMargin(new Insets(0, 0, 0, 0));
1154                    c.gridx = 0;
1155                  c.gridy = 0;                  c.gridy = 0;
1156                  c.weightx = 1.0;                  c.gridheight = 2;
1157                    c.insets = new Insets(0, 5, 0, 8);
1158                    gridbag.setConstraints(btnFxSends, c);
1159                    midiPane.add(btnFxSends);
1160                    
1161                    c.gridx = 1;
1162                    c.gridy = 1;
1163                    c.gridheight = 1;
1164                    c.insets = new Insets(0, 4, 4, 3);
1165                  c.fill = GridBagConstraints.HORIZONTAL;                  c.fill = GridBagConstraints.HORIZONTAL;
1166                  c.insets = new Insets(3, 3, 3, 3);                  gridbag.setConstraints(cbMidiDevice, c);
1167                    midiPane.add(cbMidiDevice);
1168                    
1169                    c.gridx = 3;
1170                    c.gridy = 1;
1171                    gridbag.setConstraints(cbMidiChannel, c);
1172                    midiPane.add(cbMidiChannel);
1173                    
1174                    c.gridx = 2;
1175                    c.gridy = 1;
1176                  gridbag.setConstraints(cbMidiPort, c);                  gridbag.setConstraints(cbMidiPort, c);
1177                  midiPane.add(cbMidiPort);                  midiPane.add(cbMidiPort);
1178                                    
1179                  String s = i18n.getLabel("ChannelProperties.midiPane");                  c.gridx = 4;
1180                  midiPane.setBorder(BorderFactory.createTitledBorder(s));                  c.gridy = 1;
1181                    c.weightx = 1.0;
1182                    c.insets = new Insets(0, 10, 3, 3);
1183                    gridbag.setConstraints(cbInstrumentMap, c);
1184                    midiPane.add(cbInstrumentMap);
1185                                    
1186                    String s = i18n.getLabel("ChannelProperties.midiPane");
1187                    TitledBorder border = BorderFactory.createTitledBorder(s);
1188                    //border.setTitlePosition(border.TOP);
1189                    midiPane.setBorder(border);
1190                  return midiPane;                  return midiPane;
1191          }          }
1192                    
1193          private JPanel          private JPanel
1194          createAudioPane() {          createAudioPane() {
1195                  JPanel audioPane = new JPanel();                  JPanel audioPane = new JPanel();
1196                    audioPane.setOpaque(false);
1197                                    
1198                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
1199                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
# Line 768  class ChannelProperties extends JPanel { Line 1202  class ChannelProperties extends JPanel {
1202                                    
1203                  c.gridx = 0;                  c.gridx = 0;
1204                  c.gridy = 0;                  c.gridy = 0;
1205                  c.insets = new Insets(3, 3, 3, 3);                  c.insets = new Insets(0, 3, 3, 3);
1206                  gridbag.setConstraints(lAudioDevice, c);                  gridbag.setConstraints(lAudioDevice, c);
1207                  audioPane.add(lAudioDevice);                  audioPane.add(lAudioDevice);
1208                                    
1209                  c.gridx = 1;                  c.gridx = 0;
1210                  c.gridy = 0;                  c.gridy = 1;
1211                    c.fill = GridBagConstraints.HORIZONTAL;
1212                  gridbag.setConstraints(cbAudioDevice, c);                  gridbag.setConstraints(cbAudioDevice, c);
1213                  audioPane.add(cbAudioDevice);                  audioPane.add(cbAudioDevice);
1214                                    
1215                  btnAudioProps.setMargin(new Insets(0, 0, 0, 0));                  btnAudioProps.setMargin(new Insets(0, 0, 0, 0));
1216                  c.gridx = 2;                  c.gridx = 1;
1217                  c.gridy = 0;                  c.gridy = 1;
1218                  c.insets = new Insets(3, 9, 3, 3);                  c.fill = GridBagConstraints.NONE;
1219                  gridbag.setConstraints(btnAudioProps, c);                  gridbag.setConstraints(btnAudioProps, c);
1220                  audioPane.add(btnAudioProps);                  audioPane.add(btnAudioProps);
1221                                    
# Line 799  class ChannelProperties extends JPanel { Line 1234  class ChannelProperties extends JPanel {
1234          public SamplerChannelModel          public SamplerChannelModel
1235          getModel() { return channelModel; }          getModel() { return channelModel; }
1236                    
1237            
1238            private void
1239            updateInstrumentMap() {
1240                    updateCbInstrumentMapToolTipText();
1241                    
1242                    int id = getModel().getChannelInfo().getMidiInstrumentMapId();
1243                    Object o = cbInstrumentMap.getSelectedItem();
1244                    if(o == null && id == -1) return;
1245                    
1246                    int cbId;
1247                    if(o == null || o == noMap) cbId = -1;
1248                    else if(o == defaultMap) cbId = -2;
1249                    else cbId = ((MidiInstrumentMap)o).getMapId();
1250                    
1251                    if(cbId == id) return;
1252                    
1253                    channelModel.setBackendMidiInstrumentMap(cbId);
1254            }
1255            
1256            private void
1257            updateCbInstrumentMapToolTipText() {
1258                    if(cbInstrumentMap.getSelectedItem() != defaultMap) {
1259                            cbInstrumentMap.setToolTipText(null);
1260                            return;
1261                    }
1262                    
1263                    MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap();
1264                    if(m != null) {
1265                            String s = i18n.getLabel("Channel.ttDefault", m.getName());
1266                            cbInstrumentMap.setToolTipText(s);
1267                    } else {
1268                            cbInstrumentMap.setToolTipText(null);
1269                    }
1270            }
1271            
1272          /**          /**
1273           * Updates the channel settings. This method is invoked when changes to the           * Updates the channel settings. This method is invoked when changes to the
1274           * channel were made.           * channel were made.
# Line 808  class ChannelProperties extends JPanel { Line 1278  class ChannelProperties extends JPanel {
1278                  SamplerModel sm = CC.getSamplerModel();                  SamplerModel sm = CC.getSamplerModel();
1279                  SamplerChannel sc = getModel().getChannelInfo();                  SamplerChannel sc = getModel().getChannelInfo();
1280                                    
1281                  MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice());                  MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice());
1282                  AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice());                  AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice());
1283                                    
1284                  if(isUpdate()) CC.getLogger().warning("Unexpected update state!");                  if(isUpdate()) CC.getLogger().warning("Unexpected update state!");
1285                                    
# Line 821  class ChannelProperties extends JPanel { Line 1291  class ChannelProperties extends JPanel {
1291                          cbEngines.setSelectedItem(sc.getEngine());                          cbEngines.setSelectedItem(sc.getEngine());
1292                                                    
1293                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
1294                            btnAudioProps.setEnabled(am != null);
1295                  } catch(Exception x) {                  } catch(Exception x) {
1296                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
1297                  }                  }
1298                                    
1299                    if(sc.getEngine() != null) {
1300                            cbInstrumentMap.setEnabled(true);
1301                            int id = sc.getMidiInstrumentMapId();
1302                            Object o;
1303                            if(id == -2) o = defaultMap;
1304                            else if(id == -1) o = noMap;
1305                            else o = CC.getSamplerModel().getMidiInstrumentMapById(id);
1306                            
1307                            if(cbInstrumentMap.getSelectedItem() != o) {
1308                                    cbInstrumentMap.setSelectedItem(o);
1309                            }
1310                    } else {
1311                            cbInstrumentMap.setSelectedItem(noMap);
1312                            cbInstrumentMap.setEnabled(false);
1313                    }
1314                    
1315                  setUpdate(false);                  setUpdate(false);
1316          }          }
1317                    
# Line 841  class ChannelProperties extends JPanel { Line 1328  class ChannelProperties extends JPanel {
1328                  try {                  try {
1329                          cbMidiDevice.removeAllItems();                          cbMidiDevice.removeAllItems();
1330                                    
1331                          for(MidiDeviceModel m : sm.getMidiDeviceModels())                          for(MidiDeviceModel m : sm.getMidiDevices())
1332                                  cbMidiDevice.addItem(m.getDeviceInfo());                                  cbMidiDevice.addItem(m.getDeviceInfo());
1333                                    
1334                          MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice());                          MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice());
1335                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());
1336                  } catch(Exception x) {                  } catch(Exception x) {
1337                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
# Line 866  class ChannelProperties extends JPanel { Line 1353  class ChannelProperties extends JPanel {
1353                  try {                  try {
1354                          cbAudioDevice.removeAllItems();                          cbAudioDevice.removeAllItems();
1355                                    
1356                          for(AudioDeviceModel m : sm.getAudioDeviceModels())                          for(AudioDeviceModel m : sm.getAudioDevices())
1357                                  cbAudioDevice.addItem(m.getDeviceInfo());                                  cbAudioDevice.addItem(m.getDeviceInfo());
1358                                    
1359                          AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice());                          AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice());
1360                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
1361                  } catch(Exception x) {                  } catch(Exception x) {
1362                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
# Line 883  class ChannelProperties extends JPanel { Line 1370  class ChannelProperties extends JPanel {
1370                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();
1371                                    
1372                  if(!isUpdate()) {                  if(!isUpdate()) {
1373                          if(mid != null) getModel().setMidiInputDevice(mid.getDeviceID());                          if(mid != null) getModel().setBackendMidiInputDevice(mid.getDeviceId());
1374                          return;                          return;
1375                  }                  }
1376                                    
1377                    if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler());
1378                    
1379                  cbMidiPort.removeAllItems();                  cbMidiPort.removeAllItems();
1380                                    
1381                  if(mid == null) {                  if(mid == null) {
1382                            midiDevice = null;
1383                          cbMidiPort.setEnabled(false);                          cbMidiPort.setEnabled(false);
1384                                                    
1385                          cbMidiChannel.setSelectedItem(null);                          cbMidiChannel.setSelectedItem(null);
1386                          cbMidiChannel.setEnabled(false);                          cbMidiChannel.setEnabled(false);
1387                  } else {                  } else {
1388                            midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId());
1389                            if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler());
1390                            
1391                          cbMidiPort.setEnabled(true);                          cbMidiPort.setEnabled(true);
1392                                                    
1393                          MidiPort[] ports = mid.getMidiPorts();                          MidiPort[] ports = mid.getMidiPorts();
# Line 915  class ChannelProperties extends JPanel { Line 1408  class ChannelProperties extends JPanel {
1408          setMidiPort() {          setMidiPort() {
1409                  if(isUpdate()) return;                  if(isUpdate()) return;
1410                                    
1411                  getModel().setMidiInputPort(cbMidiPort.getSelectedIndex());                  getModel().setBackendMidiInputPort(cbMidiPort.getSelectedIndex());
1412          }          }
1413                    
1414          private void          private void
# Line 927  class ChannelProperties extends JPanel { Line 1420  class ChannelProperties extends JPanel {
1420                                    
1421                  int c = o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()) - 1;                  int c = o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()) - 1;
1422                                    
1423                  getModel().setMidiInputChannel(c);                  getModel().setBackendMidiInputChannel(c);
1424          }          }
1425                    
1426          /** Invoked when the user selects an engine. */          /** Invoked when the user selects an engine. */
# Line 936  class ChannelProperties extends JPanel { Line 1429  class ChannelProperties extends JPanel {
1429                  Object oldEngine = getModel().getChannelInfo().getEngine();                  Object oldEngine = getModel().getChannelInfo().getEngine();
1430                  SamplerEngine newEngine = (SamplerEngine)cbEngines.getSelectedItem();                  SamplerEngine newEngine = (SamplerEngine)cbEngines.getSelectedItem();
1431                                    
1432                    if(newEngine == null) cbEngines.setToolTipText(null);
1433                    else cbEngines.setToolTipText(newEngine.getDescription());
1434                    
1435                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }
1436                  else if(newEngine == null) return;                  else if(newEngine == null) return;
1437                                    
1438                  getModel().setEngineType(newEngine.getName());                  getModel().setBackendEngineType(newEngine.getName());
1439                                    
1440          }          }
1441                    
# Line 947  class ChannelProperties extends JPanel { Line 1443  class ChannelProperties extends JPanel {
1443          setAudioDevice() {          setAudioDevice() {
1444                  if(isUpdate()) return;                  if(isUpdate()) return;
1445                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();
1446                  if(dev != null) getModel().setAudioOutputDevice(dev.getDeviceID());                  if(dev != null) getModel().setBackendAudioOutputDevice(dev.getDeviceId());
1447          }          }
1448                    
1449          /**          /**
# Line 972  class ChannelProperties extends JPanel { Line 1468  class ChannelProperties extends JPanel {
1468          private Handler          private Handler
1469          getHandler() { return handler; }          getHandler() { return handler; }
1470                    
1471          private class Handler implements MidiDeviceListListener, AudioDeviceListListener {          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1472                                            SamplerChannelListListener, MidiDeviceListener {
1473                    
1474                  /**                  /**
1475                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1476                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 999  class ChannelProperties extends JPanel { Line 1497  class ChannelProperties extends JPanel {
1497                   * instance providing the event information.                   * instance providing the event information.
1498                   */                   */
1499                  public void                  public void
1500                  deviceAdded(AudioDeviceListEvent e) {                  entryAdded(ListEvent<AudioDeviceModel> e) {
1501                          cbAudioDevice.addItem(e.getAudioDeviceModel().getDeviceInfo());                          cbAudioDevice.addItem(e.getEntry().getDeviceInfo());
1502                  }                  }
1503                    
1504                  /**                  /**
# Line 1009  class ChannelProperties extends JPanel { Line 1507  class ChannelProperties extends JPanel {
1507                   * instance providing the event information.                   * instance providing the event information.
1508                   */                   */
1509                  public void                  public void
1510                  deviceRemoved(AudioDeviceListEvent e) {                  entryRemoved(ListEvent<AudioDeviceModel> e) {
1511                          cbAudioDevice.removeItem(e.getAudioDeviceModel().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1512                    }
1513                    
1514                    /**
1515                     * Invoked when a new sampler channel is created.
1516                     * @param e A <code>SamplerChannelListEvent</code>
1517                     * instance providing the event information.
1518                     */
1519                    public void
1520                    channelAdded(SamplerChannelListEvent e) { }
1521            
1522                    /**
1523                     * Invoked when a sampler channel is removed.
1524                     * @param e A <code>SamplerChannelListEvent</code>
1525                     * instance providing the event information.
1526                     */
1527                    public void
1528                    channelRemoved(SamplerChannelListEvent e) {
1529                            // Some cleanup when the channel is removed.
1530                            if(e.getChannelModel().getChannelId() == channelModel.getChannelId()) {
1531                                    SamplerModel sm = CC.getSamplerModel();
1532                                    
1533                                    sm.removeMidiDeviceListListener(getHandler());
1534                                    sm.removeAudioDeviceListListener(getHandler());
1535                                    sm.removeMidiInstrumentMapListListener(mapListListener);
1536                                    sm.removeSamplerListener(samplerListener);
1537                                    sm.removeSamplerChannelListListener(getHandler());
1538                                    
1539                                    if(midiDevice != null) {
1540                                            midiDevice.removeMidiDeviceListener(getHandler());
1541                                    }
1542                            }
1543                    }
1544                    
1545                    public void
1546                    settingsChanged(MidiDeviceEvent e) {
1547                            if(isUpdate()) {
1548                                    CC.getLogger().warning("Invalid update state");
1549                                    return;
1550                            }
1551                            
1552                            setUpdate(true);
1553                            int idx = cbMidiPort.getSelectedIndex();
1554                            MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
1555                            
1556                            cbMidiPort.removeAllItems();
1557                            for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port);
1558                            
1559                            if(idx >= cbMidiPort.getModel().getSize()) idx = 0;
1560                            
1561                            setUpdate(false);
1562                            
1563                            if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx);
1564                    }
1565            }
1566            
1567            private class MapListListener implements ListListener<MidiInstrumentMap> {
1568                    /** Invoked when a new MIDI instrument map is added to a list. */
1569                    public void
1570                    entryAdded(ListEvent<MidiInstrumentMap> e) {
1571                            cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());
1572                            boolean b = getModel().getChannelInfo().getEngine() != null;
1573                            if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);
1574                    }
1575            
1576                    /** Invoked when a new MIDI instrument map is removed from a list. */
1577                    public void
1578                    entryRemoved(ListEvent<MidiInstrumentMap> e) {
1579                            cbInstrumentMap.removeItem(e.getEntry());
1580                            if(cbInstrumentMap.getItemCount() == 0) {
1581                                    cbInstrumentMap.setSelectedItem(noMap);
1582                                    cbInstrumentMap.setEnabled(false);
1583                            }
1584                  }                  }
1585          }          }
1586  }  }

Legend:
Removed from v.842  
changed lines
  Added in v.1540

  ViewVC Help
Powered by ViewVC