/[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 787 by iliev, Mon Oct 10 16:03:12 2005 UTC revision 1343 by iliev, Tue Sep 11 15:38:28 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;
28  import java.awt.Dimension;  import java.awt.Dimension;
29  import java.awt.GridBagConstraints;  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;
44    import java.beans.PropertyChangeListener;
45    
46  import java.net.URL;  import java.net.URL;
47    
48    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 46  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;
70    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.Instrument;
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 80  import static org.jsampler.view.classic. Line 118  import static org.jsampler.view.classic.
118   * @author Grigor Iliev   * @author Grigor Iliev
119   */   */
120  public class Channel extends org.jsampler.view.JSChannel {  public class Channel extends org.jsampler.view.JSChannel {
121            private final static ImageIcon iconEdit;
122            
123          private final static ImageIcon iconMuteOn;          private final static ImageIcon iconMuteOn;
124          private final static ImageIcon iconMuteOff;          private final static ImageIcon iconMuteOff;
125          private final static ImageIcon iconMutedBySolo;          private final static ImageIcon iconMutedBySolo;
# Line 90  public class Channel extends org.jsample Line 130  public class Channel extends org.jsample
130          private final static ImageIcon iconShowProperties;          private final static ImageIcon iconShowProperties;
131          private final static ImageIcon iconHideProperties;          private final static ImageIcon iconHideProperties;
132                    
133            private static Border borderSelected;
134            private static Border borderHighlighted;
135            private static Border borderDeselected;
136            
137            private static Color chnColor;
138            private static Color borderColor;
139            private static Color borderHighlightedColor;
140            private static Color chnSelectedColor;
141            private static Color chnHighlightedColor;
142            
143            private final static Vector<PropertyChangeListener> propertyChangeListeners
144                    = new Vector<PropertyChangeListener>();
145            
146          static {          static {
147                    iconEdit = new ImageIcon(Channel.class.getResource("res/icons/edit.png"));
148                    
149                  String path = "org/jsampler/view/classic/res/icons/";                  String path = "org/jsampler/view/classic/res/icons/";
150                  URL url = ClassLoader.getSystemClassLoader().getResource(path + "mute_on.png");                  URL url = ClassLoader.getSystemClassLoader().getResource(path + "mute_on.png");
151                  iconMuteOn = new ImageIcon(url);                  iconMuteOn = new ImageIcon(url);
# Line 110  public class Channel extends org.jsample Line 165  public class Channel extends org.jsample
165                  url = ClassLoader.getSystemClassLoader().getResource(path + "Back16.gif");                  url = ClassLoader.getSystemClassLoader().getResource(path + "Back16.gif");
166                  iconShowProperties = new ImageIcon(url);                  iconShowProperties = new ImageIcon(url);
167                                    
168                  url = ClassLoader.getSystemClassLoader().getResource(path + "Down16.gif");                  iconHideProperties = Res.iconDown16;
169                  iconHideProperties = new ImageIcon(url);                  
170                    if(ClassicPrefs.getCustomChannelBorderColor())
171                            setBorderColor(ClassicPrefs.getChannelBorderColor());
172                    else setBorderColor(ClassicPrefs.getDefaultChannelBorderColor());
173                    
174                    if(ClassicPrefs.getCustomChannelBorderHlColor())
175                            setBorderHighlightedColor(ClassicPrefs.getChannelBorderHlColor());
176                    else setBorderHighlightedColor(ClassicPrefs.getDefaultChannelBorderHlColor());
177                    
178                    borderSelected = new LineBorder(getBorderColor(), 2, true);
179                    borderHighlighted = new LineBorder(getBorderHighlightedColor(), 2, true);
180                    borderDeselected = BorderFactory.createEmptyBorder(2, 2, 2, 2);
181                    
182                    chnColor = new JPanel().getBackground();
183                    
184                    if(ClassicPrefs.getCustomSelectedChannelBgColor()) {
185                            chnSelectedColor = ClassicPrefs.getSelectedChannelBgColor();
186                    } else {
187                            int r = chnColor.getRed() - 14 < 0 ? 0 : chnColor.getRed() - 14;
188                            int g = chnColor.getGreen() - 8 < 0 ? 0 : chnColor.getGreen() - 8;
189                            int b = chnColor.getBlue() - 3 < 0 ? 0 : chnColor.getBlue() - 3;
190                    
191                            chnSelectedColor = new Color(r, g, b);
192                    }
193                    
194                    /*r = r + 5 > 255 ? 255 : r + 5;
195                    g = g + 4 > 255 ? 255 : g + 4;
196                    b = b + 1 > 255 ? 255 : b + 1;*/
197                    
198                    chnHighlightedColor = new Color(chnColor.getRGB());
199            }
200            
201            /**
202             * Registers the specified listener for receiving property change events.
203             * @param l The <code>PropertyChangeListener</code> to register.
204             */
205            public void
206            addPropertyChangeListener(PropertyChangeListener l) {
207                    propertyChangeListeners.add(l);
208            }
209            
210            /**
211             * Removes the specified listener.
212             * @param l The <code>PropertyChangeListener</code> to remove.
213             */
214            public void
215            removePropertyChangeListener(PropertyChangeListener l) {
216                    propertyChangeListeners.remove(l);
217            }
218            
219            /**
220             * Gets the border color that is used when the channel is selected.
221             * @return The border color that is used when the channel is selected.
222             */
223            public static Color
224            getBorderColor() { return borderColor; }
225            
226            /**
227             * Sets the border color to be used when the channel is selected.
228             * @param c The border color to be used when the channel is selected.
229             */
230            public static void
231            setBorderColor(Color c) {
232                    if(borderColor != null && borderColor.getRGB() == c.getRGB()) return;
233                    
234                    Color oldColor = borderColor;
235                    borderColor = c;
236                    borderSelected = new LineBorder(getBorderColor(), 2, true);
237                    firePropertyChanged("borderColor", oldColor, borderColor);
238            }
239            
240            /**
241             * Gets the border color that is used when the mouse pointer is over a channel.
242             * @return The border color that is used when the mouse pointer is over a channel.
243             */
244            public static Color
245            getBorderHighlightedColor() { return borderHighlightedColor; }
246            
247            /**
248             * Sets the border color to be used when the mouse pointer is over a channel.
249             * @param c The border color to be used when the mouse pointer is over a channel.
250             */
251            public static void
252            setBorderHighlightedColor(Color c) {
253                    Color oldColor = borderHighlightedColor;
254                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
255                    
256                    borderHighlightedColor = c;
257                    borderHighlighted = new LineBorder(getBorderHighlightedColor(), 2, true);
258                    firePropertyChanged("borderHighlightedColor", oldColor, borderHighlightedColor);
259            }
260            
261            /**
262             * Gets the background color that is used when a channel is selected.
263             * @return The background color that is used when a channel is selected.
264             */
265            public static Color
266            getSelectedChannelBgColor() { return chnSelectedColor; }
267            
268            /**
269             * Sets the background color that is used when a channel is selected.
270             * @param c The background color to be used when a channel is selected.
271             */
272            public static void
273            setSelectedChannelBgColor(Color c) {
274                    Color oldColor = chnSelectedColor;
275                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
276                    
277                    chnSelectedColor = c;
278                    firePropertyChanged("selectedChannelBgColor", oldColor, chnSelectedColor);
279            }
280            
281            /**
282             * Gets the background color that is used when the mouse pointer is over a channel.
283             * @return The background color that is used when the mouse pointer is over a channel.
284             */
285            public static Color
286            getHighlightedChannelBgColor() { return chnHighlightedColor; }
287            
288            /**
289             * Sets the background color to be used when the mouse pointer is over a channel.
290             * @param c The background color to be used when the mouse pointer is over a channel.
291             */
292            public static void
293            setHighlightedChannelBgColor(Color c) {
294                    Color oldColor = chnHighlightedColor;
295                    if(oldColor != null && oldColor.getRGB() == c.getRGB()) return;
296                    
297                    chnHighlightedColor = c;
298                    firePropertyChanged("highlightedChannelBgColor", oldColor, chnHighlightedColor);
299            }
300            
301            private static void
302            firePropertyChanged(String propertyName, Object oldValue, Object newValue) {
303                    PropertyChangeEvent e =
304                            new PropertyChangeEvent(Channel.class, propertyName, oldValue, newValue);
305                    
306                    for(PropertyChangeListener l : propertyChangeListeners) l.propertyChange(e);
307          }          }
308                    
309                    
310          private final JPanel mainPane = new JPanel();          private final JPanel mainPane = new JPanel();
311          private final ChannelProperties propertiesPane;          private final ChannelProperties propertiesPane;
312          private final JButton btnInstr = new JButton(i18n.getLabel("Channel.btnInstr"));          private final JButton btnInstr = new InstrumentButton(i18n.getLabel("Channel.btnInstr"));
313            private final Action actInstr;
314            private final JButton btnEdit = new JButton(iconEdit);
315          private final JButton btnMute = new JButton();          private final JButton btnMute = new JButton();
316          private final JButton btnSolo = new JButton();          private final JButton btnSolo = new JButton();
317          private final JSlider slVolume = new JSlider(0, 100);          private final JSlider slVolume = new JSlider(0, 100);
318          private final JLabel lVolume = new JLabel();          private final JLabel lVolume = new JLabel();
319            private final JLabel lVolImg = new JLabel(Res.iconVolume16);
320          private final JLabel lStreams = new JLabel("--");          private final JLabel lStreams = new JLabel("--");
321          private final JLabel lVoices = new JLabel("--");          private final JLabel lVoices = new JLabel("--");
322          private final JToggleButton btnProperties = new JToggleButton();          private final JToggleButton btnProperties = new JToggleButton();
323                    
         private final EventHandler eventHandler = new EventHandler();  
           
324          private static int count = 2;          private static int count = 2;
325                    
326          private boolean selected = false;          private boolean selected = false;
327            private boolean mouseOver = false;
328                    
329                    
330          /**          /**
# Line 146  public class Channel extends org.jsample Line 340  public class Channel extends org.jsample
340                  setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));                  setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
341                                    
342                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
343                    addMouseListener(getHandler());
344                    addHierarchyListener(getHandler());
345                                    
346                  JPanel p = new JPanel();                  JPanel p = new JPanel();
347                    p.setOpaque(false);
348                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
349                  p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));                  p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
350                                    
351                  //setToolTipText(" Channel: " + String.valueOf(getChannelID()) + " ");                  setToolTipText(i18n.getLabel("Channel.tt", getModel().getChannelId()));
352                                    
353                  Dimension d = btnInstr.getPreferredSize();                  Dimension d = btnInstr.getPreferredSize();
354                  btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, d.height));                  btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, d.height));
355                  p.add(btnInstr);                  p.add(btnInstr);
356                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  p.add(Box.createRigidArea(new Dimension(6, 0)));
357                                    
358                    btnEdit.setToolTipText(i18n.getLabel("Channel.btnEdit.tt"));
359                    btnEdit.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
360                    p.add(btnEdit);
361                    p.add(Box.createRigidArea(new Dimension(6, 0)));
362                    
363                  lStreams.setHorizontalAlignment(JLabel.CENTER);                  lStreams.setHorizontalAlignment(JLabel.CENTER);
364                  lVoices.setHorizontalAlignment(JLabel.CENTER);                  lVoices.setHorizontalAlignment(JLabel.CENTER);
365                                    
366                  JPanel statPane = new JPanel();                  JPanel statPane = new JPanel();
367                    statPane.setOpaque(false);
368                  statPane.setBorder(BorderFactory.createLoweredBevelBorder());                  statPane.setBorder(BorderFactory.createLoweredBevelBorder());
369                  statPane.setLayout(new BoxLayout(statPane, BoxLayout.X_AXIS));                  statPane.setLayout(new BoxLayout(statPane, BoxLayout.X_AXIS));
370                  statPane.add(Box.createRigidArea(new Dimension(6, 0)));                  statPane.add(Box.createRigidArea(new Dimension(6, 0)));
# Line 183  public class Channel extends org.jsample Line 386  public class Channel extends org.jsample
386                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  p.add(Box.createRigidArea(new Dimension(6, 0)));
387                                    
388                  JPanel volumePane = new JPanel();                  JPanel volumePane = new JPanel();
389                    volumePane.setOpaque(false);
390                  volumePane.setBorder(BorderFactory.createLoweredBevelBorder());                  volumePane.setBorder(BorderFactory.createLoweredBevelBorder());
391                  volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));                  volumePane.setLayout(new BoxLayout(volumePane, BoxLayout.X_AXIS));
392                  volumePane.add(Box.createRigidArea(new Dimension(6, 0)));                  volumePane.add(Box.createRigidArea(new Dimension(6, 0)));
393                                    
394                    volumePane.add(lVolImg);
395                    volumePane.add(Box.createRigidArea(new Dimension(1, 0)));
396                    
397                  d = slVolume.getPreferredSize();                  d = slVolume.getPreferredSize();
398                  slVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));                  slVolume.setMaximumSize(new Dimension(d.width > 300 ? d.width : 300, d.height));
399                    slVolume.setOpaque(false);
400                  volumePane.add(slVolume);                  volumePane.add(slVolume);
401                                    
402                  lVolume.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));                  lVolume.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));
# Line 220  public class Channel extends org.jsample Line 428  public class Channel extends org.jsample
428                  d = getPreferredSize();                  d = getPreferredSize();
429                  setMaximumSize(new Dimension(getMaximumSize().width, d.height));                  setMaximumSize(new Dimension(getMaximumSize().width, d.height));
430                                    
431                  getModel().addSamplerChannelListener(eventHandler);                  getModel().addSamplerChannelListener(getHandler());
432                    
433                    actInstr = new AbstractAction() {
434                            public void
435                            actionPerformed(ActionEvent e) {
436                                    if(actInstr.isEnabled()) loadInstrument();
437                            }
438                    };
439                                    
440                  btnInstr.addActionListener(new ActionListener() {                  btnInstr.addActionListener(actInstr);
441                    
442                    btnEdit.addActionListener(new ActionListener() {
443                          public void                          public void
444                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) {
445                                    CC.getSamplerModel().editBackendInstrument(getChannelId());
446                            }
447                  });                  });
448                                    
449                  btnMute.addActionListener(new ActionListener() {                  btnMute.addActionListener(new ActionListener() {
# Line 246  public class Channel extends org.jsample Line 465  public class Channel extends org.jsample
465                          public void                          public void
466                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
467                                  showProperties(btnProperties.isSelected());                                  showProperties(btnProperties.isSelected());
468                                    
469                                    String s;
470                                    if(btnProperties.isSelected()) {
471                                            s = i18n.getButtonLabel("Channel.ttHideProps");
472                                    } else {
473                                            s = i18n.getButtonLabel("Channel.ttShowProps");
474                                    }
475                                    
476                                    btnProperties.setToolTipText(s);
477                          }                          }
478                  });                  });
479                                    
480                    btnProperties.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
481                    
482                    String s;
483                    if(btnProperties.isSelected()) s = i18n.getButtonLabel("Channel.ttHideProps");
484                    else s = i18n.getButtonLabel("Channel.ttShowProps");
485                    
486                    btnProperties.setToolTipText(s);
487                    
488                    addPropertyChangeListener(getHandler());
489                    
490                  updateChannelInfo();                  updateChannelInfo();
491          }          }
492                    
493          private class EventHandler implements SamplerChannelListener {          public class InstrumentButton extends JButton {
494                    private boolean dragging = false;
495                    
496                    InstrumentButton(String s) {
497                            super(s);
498                            
499                            setTransferHandler(new TransferHandler("instrument"));
500                            
501                            addMouseListener(new MouseAdapter() {
502                                    public void
503                                    mouseExited(MouseEvent e) {
504                                            if(!dragging) return;
505                                            
506                                            int b1 = e.BUTTON1_DOWN_MASK;
507                                            if((e.getModifiersEx() & b1) != b1) return;
508                                            
509                                            actInstr.setEnabled(false);
510                                            doClick(0);
511                                            actInstr.setEnabled(true);
512                                            
513                                            JComponent c = (JComponent)e.getSource();
514                                            TransferHandler handler = c.getTransferHandler();
515                                            handler.exportAsDrag(c, e, TransferHandler.COPY);
516                                    }
517                                    
518                                    public void
519                                    mouseReleased(MouseEvent e) { dragging = false; }
520                            });
521                            
522                            addMouseMotionListener(new MouseMotionAdapter() {
523                                    public void
524                                    mouseDragged(MouseEvent e) { dragging = true; }
525                            });
526                    }
527                    
528                    public String
529                    getInstrument() {
530                            SamplerChannel sc = Channel.this.getChannelInfo();
531                            
532                            if(sc.getInstrumentName() == null || sc.getInstrumentStatus() < 0)
533                                    return null;
534                            
535                            Instrument instr = new Instrument();
536                            instr.setName(sc.getInstrumentName());
537                            instr.setInstrumentIndex(sc.getInstrumentIndex());
538                            instr.setPath(sc.getInstrumentFile());
539                            return instr.getDnDString();
540                    }
541                    
542                    public void setInstrument(String instr) {
543                            if(!Instrument.isDnDString(instr)) return;
544                            
545                            String[] args = instr.split("\n");
546                            if(args.length < 6) return;
547                            
548                            try {
549                                    int idx = Integer.parseInt(args[5]);
550                                    Channel.this.getModel().loadBackendInstrument(args[4], idx);
551                            } catch(Exception x) {
552                                    CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
553                            }
554                    }
555            }
556            
557            private final EventHandler eventHandler = new EventHandler();
558            
559            private EventHandler
560            getHandler() { return eventHandler; }
561            
562            private class EventHandler extends MouseAdapter implements SamplerChannelListener,
563                                                            PropertyChangeListener, HierarchyListener {
564                  /**                  /**
565                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
566                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 280  public class Channel extends org.jsample Line 588  public class Channel extends org.jsample
588                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
589                          updateVoiceCount(getModel().getVoiceCount());                          updateVoiceCount(getModel().getVoiceCount());
590                  }                  }
591                    
592                    public void
593                    propertyChange(PropertyChangeEvent e) {
594                            if (
595                                    e.getPropertyName() == "borderColor" ||
596                                    e.getPropertyName() == "borderHighlightedColor" ||
597                                    e.getPropertyName() == "selectedChannelBgColor" ||
598                                    e.getPropertyName() == "highlightedChannelBgColor"
599                            ) {
600                                    updateColors(isSelected());
601                            }
602                    }
603                    
604                    public void
605                    mouseEntered(MouseEvent e) {
606                            mouseOver = true;
607                            updateColors(isSelected());
608                    }
609                    
610                    public void
611                    mouseExited(MouseEvent e) {
612                            if(getMousePosition(true) != null) return;
613                            
614                            mouseOver = false;
615                            updateColors(isSelected());
616                    }
617                    
618                    
619            
620                    /** Called when the hierarchy has been changed. */
621                    public void
622                    hierarchyChanged(HierarchyEvent e) {
623                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
624                                    if(getMousePosition() == null) mouseExited(null);
625                                    else mouseEntered(null);
626                            }
627                    }
628          }          }
629                    
630          /**          /**
# Line 296  public class Channel extends org.jsample Line 641  public class Channel extends org.jsample
641           */           */
642          public void          public void
643          setSelected(boolean select) {          setSelected(boolean select) {
644                  if(select)                  updateColors(select);
                         mainPane.setBorder(BorderFactory.createLineBorder(java.awt.Color.WHITE, 3));  
                 else mainPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));  
645                                    
646                  selected = select;                  selected = select;
647          }          }
648                    
649            /**
650             * Updates the channel background and border colors.
651             * @param selected Specifies the selection state of this channel.
652             */
653            private void
654            updateColors(boolean selected) {
655                    if(selected) {
656                            mainPane.setBorder(borderSelected);
657                            mainPane.setBackground(chnSelectedColor);
658                    } else {
659                            if(mouseOver) {
660                                    mainPane.setBorder(borderHighlighted);
661                                    mainPane.setBackground(chnHighlightedColor);
662                            } else {
663                                    mainPane.setBorder(borderDeselected);
664                                    mainPane.setBackground(chnColor);
665                            }
666                    }
667            }
668            
669          /** Hides the channel properties. */          /** Hides the channel properties. */
670          public void          public void
671          collapseChannel() { if(btnProperties.isSelected()) btnProperties.doClick(); }          collapseChannel() { if(btnProperties.isSelected()) btnProperties.doClick(); }
# Line 322  public class Channel extends org.jsample Line 685  public class Channel extends org.jsample
685                  int status = sc.getInstrumentStatus();                  int status = sc.getInstrumentStatus();
686                  if(status >= 0 && status < 100) {                  if(status >= 0 && status < 100) {
687                          btnInstr.setText(i18n.getLabel("Channel.loadingInstrument", status));                          btnInstr.setText(i18n.getLabel("Channel.loadingInstrument", status));
688                    } else if(status == -1) {
689                            btnInstr.setText(i18n.getLabel("Channel.btnInstr"));
690                    } else if(status < -1) {
691                             btnInstr.setText(i18n.getLabel("Channel.errorLoadingInstrument"));
692                  } else {                  } else {
693                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
694                          else btnInstr.setText(i18n.getLabel("Channel.btnInstr"));                          else btnInstr.setText(i18n.getLabel("Channel.btnInstr"));
695                  }                  }
696                                    
697                  updateMute(sc);                  updateMuteIcon(sc);
698                                    
699                  if(sc.isSoloChannel()) btnSolo.setIcon(iconSoloOn);                  if(sc.isSoloChannel()) btnSolo.setIcon(iconSoloOn);
700                  else btnSolo.setIcon(iconSoloOff);                  else btnSolo.setIcon(iconSoloOff);
# Line 358  public class Channel extends org.jsample Line 725  public class Channel extends org.jsample
725                          else btnMute.setIcon(iconMutedBySolo);                          else btnMute.setIcon(iconMutedBySolo);
726                  } else btnMute.setIcon(iconMuteOn);                  } else btnMute.setIcon(iconMuteOn);
727                                    
728                  getModel().setMute(b);                  getModel().setBackendMute(b);
729          }          }
730                    
731          /** Invoked when the user clicks the solo button. */          /** Invoked when the user clicks the solo button. */
# Line 380  public class Channel extends org.jsample Line 747  public class Channel extends org.jsample
747                                  btnMute.setIcon(iconMutedBySolo);                                  btnMute.setIcon(iconMutedBySolo);
748                  }                  }
749                                    
750                  getModel().setSolo(b);                  getModel().setBackendSolo(b);
751          }          }
752                    
753          /** Invoked when the user changes the volume */          /** Invoked when the user changes the volume */
# Line 401  public class Channel extends org.jsample Line 768  public class Channel extends org.jsample
768                   */                   */
769                  float volume = slVolume.getValue();                  float volume = slVolume.getValue();
770                  volume /= 100;                  volume /= 100;
771                  getModel().setVolume(volume);                  getModel().setBackendVolume(volume);
772          }          }
773                    
774          private void          private void
775          updateVolume() {          updateVolume() {
776                  int volume = slVolume.getValue();                  int volume = slVolume.getValue();
777                  slVolume.setToolTipText(i18n.getLabel("Channel.volume", volume));                  slVolume.setToolTipText(i18n.getLabel("Channel.volume", volume));
778                    lVolImg.setToolTipText(i18n.getLabel("Channel.volume", volume));
779                                    
780                  setVolumeLabel(volume);                  setVolumeLabel(volume);
781                                    
# Line 431  public class Channel extends org.jsample Line 799  public class Channel extends org.jsample
799           * for this channel.           * for this channel.
800           */           */
801          private void          private void
802          updateMute(SamplerChannel channel) {          updateMuteIcon(SamplerChannel channel) {
803                  if(channel.isMutedBySolo()) btnMute.setIcon(iconMutedBySolo);                  if(channel.isMutedBySolo()) btnMute.setIcon(iconMutedBySolo);
804                  else if(channel.isMuted()) btnMute.setIcon(iconMuteOn);                  else if(channel.isMuted()) btnMute.setIcon(iconMuteOn);
805                  else btnMute.setIcon(iconMuteOff);                  else btnMute.setIcon(iconMuteOff);
# Line 470  public class Channel extends org.jsample Line 838  public class Channel extends org.jsample
838                    
839          private void          private void
840          loadInstrument() {          loadInstrument() {
841                  InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());
842                  dlg.setVisible(true);                  dlg.setVisible(true);
843                                    
844                  if(!dlg.isCancelled()) {                  if(dlg.isCancelled()) return;
845                          getModel().loadInstrument(dlg.getFileName(), dlg.getInstrumentIndex());                  
846                    SamplerEngine engine = getChannelInfo().getEngine();
847                    if(dlg.getEngine() != null) {
848                            if(engine == null || !dlg.getEngine().equals(engine.getName()));
849                                    getModel().setBackendEngineType(dlg.getEngine());
850                  }                  }
851                    
852                    int idx = dlg.getInstrumentIndex();
853                    getModel().loadBackendInstrument(dlg.getInstrumentFile(), idx);
854                    
855          }          }
856  }  }
857    
858  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);  
         }  
           
859          private final JLabel lMidiDevice =          private final JLabel lMidiDevice =
860                  new JLabel(i18n.getLabel("ChannelProperties.lMidiDevice"));                  new JLabel(i18n.getLabel("ChannelProperties.lMidiDevice"));
861          private final JLabel lMidiPort =          private final JLabel lMidiPort =
# Line 495  class ChannelProperties extends JPanel { Line 863  class ChannelProperties extends JPanel {
863          private final JLabel lMidiChannel =          private final JLabel lMidiChannel =
864                  new JLabel(i18n.getLabel("ChannelProperties.lMidiChannel"));                  new JLabel(i18n.getLabel("ChannelProperties.lMidiChannel"));
865                    
866            private final JLabel lInstrumentMap =
867                    new JLabel(i18n.getLabel("ChannelProperties.lInstrumentMap"));
868            
869          private final JLabel lAudioDevice =          private final JLabel lAudioDevice =
870                  new JLabel(i18n.getLabel("ChannelProperties.lAudioDevice"));                  new JLabel(i18n.getLabel("ChannelProperties.lAudioDevice"));
871                    
872          private final JComboBox cbEngines = new JComboBox();          private final JComboBox cbEngines = new JComboBox();
873                    
874            private final JComboBox cbInstrumentMap = new JComboBox();
875          private final JComboBox cbMidiDevice = new JComboBox();          private final JComboBox cbMidiDevice = new JComboBox();
876          private final JComboBox cbMidiPort = new JComboBox();          private final JComboBox cbMidiPort = new JComboBox();
877          private final JComboBox cbMidiChannel = new JComboBox();          private final JComboBox cbMidiChannel = new JComboBox();
878          private final JComboBox cbAudioDevice = new JComboBox();          private final JComboBox cbAudioDevice = new JComboBox();
879                    
880          private final JButton btnAudioProps = new JButton(iconAudioProps);          private final JButton btnFxSends = new JButton(Res.iconFxSends22);
881            private final JButton btnAudioProps = new JButton(Res.iconAudioProps16);
882            private InformationDialog fxSendsDlg = null;
883                    
884          private SamplerChannelModel channelModel = null;          private SamplerChannelModel channelModel = null;
885            private MidiDeviceModel midiDevice = null;
886                    
887          private boolean update = false;          private boolean update = false;
888                    
889            private final SamplerListener samplerListener;
890            private final MapListListener mapListListener = new MapListListener();
891            
892            private class NoMap {
893                    public String
894                    toString() { return "[None]"; }
895            }
896            
897            private NoMap noMap = new NoMap();
898            
899            private class DefaultMap {
900                    public String
901                    toString() { return "[Default]"; }
902            }
903            
904            private DefaultMap defaultMap = new DefaultMap();
905            
906          /**          /**
907           * 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
908           * channel model.           * channel model.
# Line 520  class ChannelProperties extends JPanel { Line 912  class ChannelProperties extends JPanel {
912                  channelModel = model;                  channelModel = model;
913                                    
914                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
915                    setOpaque(false);
916                                    
917                  add(new JSeparator());                  add(new JSeparator());
918                                    
919                  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));  
920                                    
921                  JPanel devicesPane = new JPanel();                  JPanel devicesPane = new JPanel();
922                    devicesPane.setOpaque(false);
923                  devicesPane.setLayout(new BoxLayout(devicesPane, BoxLayout.X_AXIS));                  devicesPane.setLayout(new BoxLayout(devicesPane, BoxLayout.X_AXIS));
924                                    
925                  devicesPane.add(Box.createRigidArea(new Dimension(3, 0)));                  devicesPane.add(Box.createRigidArea(new Dimension(3, 0)));
# Line 591  class ChannelProperties extends JPanel { Line 977  class ChannelProperties extends JPanel {
977                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }
978                  });                  });
979                                    
980                    samplerListener = new SamplerAdapter() {
981                            /** Invoked when the default MIDI instrument map is changed. */
982                            public void
983                            defaultMapChanged(SamplerEvent e) {
984                                    updateCbInstrumentMapToolTipText();
985                            }
986                    };
987                    
988                    CC.getSamplerModel().addSamplerListener(samplerListener);
989                    
990                    cbInstrumentMap.addItem(noMap);
991                    cbInstrumentMap.addItem(defaultMap);
992                    for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) {
993                            cbInstrumentMap.addItem(map);
994                    }
995                    
996                    int map = getModel().getChannelInfo().getMidiInstrumentMapId();
997                    cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map));
998                    if(cbInstrumentMap.getSelectedItem() == null) {
999                            if(map == -1) cbInstrumentMap.setSelectedItem(noMap);
1000                            else if(map == -2) {
1001                                    cbInstrumentMap.setSelectedItem(defaultMap);
1002                            }
1003                    }
1004                    
1005                    updateCbInstrumentMapToolTipText();
1006                    
1007                    if(getModel().getChannelInfo().getEngine() == null) {
1008                            cbInstrumentMap.setEnabled(false);
1009                    }
1010                    
1011                    cbInstrumentMap.addActionListener(new ActionListener() {
1012                            public void
1013                            actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1014                    });
1015                    
1016                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());
1017                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());
1018                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
1019                    CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1020                                    
1021                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));
1022                    btnAudioProps.setEnabled(false);
1023                  btnAudioProps.addActionListener(new ActionListener() {                  btnAudioProps.addActionListener(new ActionListener() {
1024                          public void                          public void
1025                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
1026                                  SamplerChannel c = getModel().getChannelInfo();                                  SamplerChannel c = getModel().getChannelInfo();
1027                                  new ChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);                                  new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
1028                                                    
1029                          }                          }
1030                  });                  });
1031                                    
1032                                    btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelProperties.btnFxSends"));
1033                    btnFxSends.addActionListener(new ActionListener() {
1034                            public void
1035                            actionPerformed(ActionEvent e) {
1036                                    if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
1037                                            fxSendsDlg.toFront();
1038                                            return;
1039                                    }
1040                                    
1041                                    FxSendsPane p = new FxSendsPane(getModel());
1042                                    int id = getModel().getChannelId();
1043                                    fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
1044                                    fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id));
1045                                    fxSendsDlg.setModal(false);
1046                                    fxSendsDlg.showCloseButton(false);
1047                                    fxSendsDlg.setVisible(true);
1048                            }
1049                    });
1050                                    
1051                  updateMidiDevices();                  updateMidiDevices();
1052                  updateAudioDevices();                  updateAudioDevices();
1053                  updateChannelProperties();                  updateChannelProperties();
1054          }          }
1055            
1056            class FxSendsPane extends JSFxSendsPane {
1057                    FxSendsPane(SamplerChannelModel model) {
1058                            super(model);
1059                            
1060                            actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
1061                            actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
1062                    }
1063                    
1064                    protected JToolBar
1065                    createToolBar() {
1066                            JToolBar tb = new JToolBar();
1067                            Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
1068                            tb.setMaximumSize(d);
1069                            tb.setFloatable(false);
1070                            tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
1071                            
1072                            tb.add(new ToolbarButton(actionAddFxSend));
1073                            tb.add(new ToolbarButton(actionRemoveFxSend));
1074                    
1075                            return tb;
1076                    }
1077            }
1078            
1079            private JPanel
1080            createEnginePane() {
1081                    for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngines.addItem(e);
1082                    
1083                    cbEngines.setMaximumSize(cbEngines.getPreferredSize());
1084                    
1085                    JPanel p = new JPanel();
1086                    p.setOpaque(false);
1087                    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
1088                    p.add(cbEngines);
1089                    p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
1090                    
1091                    //enginesPane.add(Box.createGlue());
1092                    JPanel enginesPane = new JPanel();
1093                    enginesPane.setOpaque(false);
1094                    enginesPane.setLayout(new BorderLayout());
1095                    enginesPane.add(p, BorderLayout.SOUTH);
1096                    //enginesPane.add(Box.createRigidArea(new Dimension(0, 3)));
1097                    
1098                    String s = i18n.getLabel("ChannelProperties.enginesPane");
1099                    enginesPane.setBorder(BorderFactory.createTitledBorder(s));
1100                    Dimension d = new Dimension(enginesPane.getPreferredSize().width, Short.MAX_VALUE);
1101                    enginesPane.setMaximumSize(d);
1102                    return enginesPane;
1103            }
1104            
1105          private JPanel          private JPanel
1106          createMidiPane() {          createMidiPane() {
1107                  JPanel midiPane = new JPanel();                  JPanel midiPane = new JPanel();
1108                    midiPane.setOpaque(false);
1109                                    
1110                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
1111                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
1112                                    
1113                  midiPane.setLayout(gridbag);                  midiPane.setLayout(gridbag);
1114                                    
1115                  c.gridx = 0;                  c.gridx = 1;
1116                  c.gridy = 0;                  c.gridy = 0;
1117                  c.insets = new Insets(3, 3, 3, 3);                  c.insets = new Insets(0, 3, 3, 3);
1118                  gridbag.setConstraints(lMidiDevice, c);                  gridbag.setConstraints(lMidiDevice, c);
1119                  midiPane.add(lMidiDevice);                  midiPane.add(lMidiDevice);
1120                                    
                 c.gridx = 1;  
                 c.gridy = 0;  
                 gridbag.setConstraints(cbMidiDevice, c);  
                 midiPane.add(cbMidiDevice);  
                   
1121                  c.gridx = 2;                  c.gridx = 2;
1122                  c.gridy = 0;                  c.gridy = 0;
1123                  gridbag.setConstraints(lMidiPort, c);                  gridbag.setConstraints(lMidiPort, c);
1124                  midiPane.add(lMidiPort);                  midiPane.add(lMidiPort);
1125                                    
1126                  c.gridx = 4;                  c.gridx = 3;
1127                  c.gridy = 0;                  c.gridy = 0;
1128                  gridbag.setConstraints(lMidiChannel, c);                  gridbag.setConstraints(lMidiChannel, c);
1129                  midiPane.add(lMidiChannel);                  midiPane.add(lMidiChannel);
1130                                    
1131                  c.gridx = 5;                  c.gridx = 4;
1132                  c.gridy = 0;                  c.gridy = 0;
1133                  gridbag.setConstraints(cbMidiChannel, c);                  c.insets = new Insets(0, 10, 3, 3);
1134                  midiPane.add(cbMidiChannel);                  gridbag.setConstraints(lInstrumentMap, c);
1135                    midiPane.add(lInstrumentMap);
1136                                    
1137                  c.gridx = 3;                  btnFxSends.setMargin(new Insets(0, 0, 0, 0));
1138                    c.gridx = 0;
1139                  c.gridy = 0;                  c.gridy = 0;
1140                  c.weightx = 1.0;                  c.gridheight = 2;
1141                    c.insets = new Insets(0, 5, 0, 8);
1142                    gridbag.setConstraints(btnFxSends, c);
1143                    midiPane.add(btnFxSends);
1144                    
1145                    c.gridx = 1;
1146                    c.gridy = 1;
1147                    c.gridheight = 1;
1148                    c.insets = new Insets(0, 4, 4, 3);
1149                  c.fill = GridBagConstraints.HORIZONTAL;                  c.fill = GridBagConstraints.HORIZONTAL;
1150                  c.insets = new Insets(3, 3, 3, 3);                  gridbag.setConstraints(cbMidiDevice, c);
1151                    midiPane.add(cbMidiDevice);
1152                    
1153                    c.gridx = 3;
1154                    c.gridy = 1;
1155                    gridbag.setConstraints(cbMidiChannel, c);
1156                    midiPane.add(cbMidiChannel);
1157                    
1158                    c.gridx = 2;
1159                    c.gridy = 1;
1160                  gridbag.setConstraints(cbMidiPort, c);                  gridbag.setConstraints(cbMidiPort, c);
1161                  midiPane.add(cbMidiPort);                  midiPane.add(cbMidiPort);
1162                                    
1163                  String s = i18n.getLabel("ChannelProperties.midiPane");                  c.gridx = 4;
1164                  midiPane.setBorder(BorderFactory.createTitledBorder(s));                  c.gridy = 1;
1165                    c.weightx = 1.0;
1166                    c.insets = new Insets(0, 10, 3, 3);
1167                    gridbag.setConstraints(cbInstrumentMap, c);
1168                    midiPane.add(cbInstrumentMap);
1169                                    
1170                    String s = i18n.getLabel("ChannelProperties.midiPane");
1171                    TitledBorder border = BorderFactory.createTitledBorder(s);
1172                    //border.setTitlePosition(border.TOP);
1173                    midiPane.setBorder(border);
1174                  return midiPane;                  return midiPane;
1175          }          }
1176                    
1177          private JPanel          private JPanel
1178          createAudioPane() {          createAudioPane() {
1179                  JPanel audioPane = new JPanel();                  JPanel audioPane = new JPanel();
1180                    audioPane.setOpaque(false);
1181                                    
1182                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
1183                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
# Line 671  class ChannelProperties extends JPanel { Line 1186  class ChannelProperties extends JPanel {
1186                                    
1187                  c.gridx = 0;                  c.gridx = 0;
1188                  c.gridy = 0;                  c.gridy = 0;
1189                  c.insets = new Insets(3, 3, 3, 3);                  c.insets = new Insets(0, 3, 3, 3);
1190                  gridbag.setConstraints(lAudioDevice, c);                  gridbag.setConstraints(lAudioDevice, c);
1191                  audioPane.add(lAudioDevice);                  audioPane.add(lAudioDevice);
1192                                    
1193                  c.gridx = 1;                  c.gridx = 0;
1194                  c.gridy = 0;                  c.gridy = 1;
1195                    c.fill = GridBagConstraints.HORIZONTAL;
1196                  gridbag.setConstraints(cbAudioDevice, c);                  gridbag.setConstraints(cbAudioDevice, c);
1197                  audioPane.add(cbAudioDevice);                  audioPane.add(cbAudioDevice);
1198                                    
1199                  btnAudioProps.setMargin(new Insets(0, 0, 0, 0));                  btnAudioProps.setMargin(new Insets(0, 0, 0, 0));
1200                  c.gridx = 2;                  c.gridx = 1;
1201                  c.gridy = 0;                  c.gridy = 1;
1202                  c.insets = new Insets(3, 9, 3, 3);                  c.fill = GridBagConstraints.NONE;
1203                  gridbag.setConstraints(btnAudioProps, c);                  gridbag.setConstraints(btnAudioProps, c);
1204                  audioPane.add(btnAudioProps);                  audioPane.add(btnAudioProps);
1205                                    
# Line 702  class ChannelProperties extends JPanel { Line 1218  class ChannelProperties extends JPanel {
1218          public SamplerChannelModel          public SamplerChannelModel
1219          getModel() { return channelModel; }          getModel() { return channelModel; }
1220                    
1221            
1222            private void
1223            updateInstrumentMap() {
1224                    updateCbInstrumentMapToolTipText();
1225                    
1226                    int id = getModel().getChannelInfo().getMidiInstrumentMapId();
1227                    Object o = cbInstrumentMap.getSelectedItem();
1228                    if(o == null && id == -1) return;
1229                    
1230                    int cbId;
1231                    if(o == null || o == noMap) cbId = -1;
1232                    else if(o == defaultMap) cbId = -2;
1233                    else cbId = ((MidiInstrumentMap)o).getMapId();
1234                    
1235                    if(cbId == id) return;
1236                    
1237                    channelModel.setBackendMidiInstrumentMap(cbId);
1238            }
1239            
1240            private void
1241            updateCbInstrumentMapToolTipText() {
1242                    if(cbInstrumentMap.getSelectedItem() != defaultMap) {
1243                            cbInstrumentMap.setToolTipText(null);
1244                            return;
1245                    }
1246                    
1247                    MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap();
1248                    if(m != null) {
1249                            String s = i18n.getLabel("Channel.ttDefault", m.getName());
1250                            cbInstrumentMap.setToolTipText(s);
1251                    } else {
1252                            cbInstrumentMap.setToolTipText(null);
1253                    }
1254            }
1255            
1256          /**          /**
1257           * Updates the channel settings. This method is invoked when changes to the           * Updates the channel settings. This method is invoked when changes to the
1258           * channel were made.           * channel were made.
# Line 711  class ChannelProperties extends JPanel { Line 1262  class ChannelProperties extends JPanel {
1262                  SamplerModel sm = CC.getSamplerModel();                  SamplerModel sm = CC.getSamplerModel();
1263                  SamplerChannel sc = getModel().getChannelInfo();                  SamplerChannel sc = getModel().getChannelInfo();
1264                                    
1265                  MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice());                  MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice());
1266                  AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice());                  AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice());
1267                                    
1268                  if(isUpdate()) CC.getLogger().warning("Unexpected update state!");                  if(isUpdate()) CC.getLogger().warning("Unexpected update state!");
1269                                    
# Line 724  class ChannelProperties extends JPanel { Line 1275  class ChannelProperties extends JPanel {
1275                          cbEngines.setSelectedItem(sc.getEngine());                          cbEngines.setSelectedItem(sc.getEngine());
1276                                                    
1277                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
1278                            btnAudioProps.setEnabled(am != null);
1279                  } catch(Exception x) {                  } catch(Exception x) {
1280                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
1281                  }                  }
1282                                    
1283                    if(sc.getEngine() != null) {
1284                            cbInstrumentMap.setEnabled(true);
1285                            int id = sc.getMidiInstrumentMapId();
1286                            Object o;
1287                            if(id == -2) o = defaultMap;
1288                            else if(id == -1) o = noMap;
1289                            else o = CC.getSamplerModel().getMidiInstrumentMapById(id);
1290                            
1291                            if(cbInstrumentMap.getSelectedItem() != o) {
1292                                    cbInstrumentMap.setSelectedItem(o);
1293                            }
1294                    } else {
1295                            cbInstrumentMap.setSelectedItem(noMap);
1296                            cbInstrumentMap.setEnabled(false);
1297                    }
1298                    
1299                  setUpdate(false);                  setUpdate(false);
1300          }          }
1301                    
# Line 744  class ChannelProperties extends JPanel { Line 1312  class ChannelProperties extends JPanel {
1312                  try {                  try {
1313                          cbMidiDevice.removeAllItems();                          cbMidiDevice.removeAllItems();
1314                                    
1315                          for(MidiDeviceModel m : sm.getMidiDeviceModels())                          for(MidiDeviceModel m : sm.getMidiDevices())
1316                                  cbMidiDevice.addItem(m.getDeviceInfo());                                  cbMidiDevice.addItem(m.getDeviceInfo());
1317                                    
1318                          MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice());                          MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice());
1319                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());
1320                  } catch(Exception x) {                  } catch(Exception x) {
1321                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
# Line 769  class ChannelProperties extends JPanel { Line 1337  class ChannelProperties extends JPanel {
1337                  try {                  try {
1338                          cbAudioDevice.removeAllItems();                          cbAudioDevice.removeAllItems();
1339                                    
1340                          for(AudioDeviceModel m : sm.getAudioDeviceModels())                          for(AudioDeviceModel m : sm.getAudioDevices())
1341                                  cbAudioDevice.addItem(m.getDeviceInfo());                                  cbAudioDevice.addItem(m.getDeviceInfo());
1342                                    
1343                          AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice());                          AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice());
1344                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
1345                  } catch(Exception x) {                  } catch(Exception x) {
1346                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
# Line 786  class ChannelProperties extends JPanel { Line 1354  class ChannelProperties extends JPanel {
1354                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();
1355                                    
1356                  if(!isUpdate()) {                  if(!isUpdate()) {
1357                          if(mid != null) getModel().setMidiInputDevice(mid.getDeviceID());                          if(mid != null) getModel().setBackendMidiInputDevice(mid.getDeviceId());
1358                          return;                          return;
1359                  }                  }
1360                                    
1361                    if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler());
1362                    
1363                  cbMidiPort.removeAllItems();                  cbMidiPort.removeAllItems();
1364                                    
1365                  if(mid == null) {                  if(mid == null) {
1366                            midiDevice = null;
1367                          cbMidiPort.setEnabled(false);                          cbMidiPort.setEnabled(false);
1368                                                    
1369                          cbMidiChannel.setSelectedItem(null);                          cbMidiChannel.setSelectedItem(null);
1370                          cbMidiChannel.setEnabled(false);                          cbMidiChannel.setEnabled(false);
1371                  } else {                  } else {
1372                            midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId());
1373                            if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler());
1374                            
1375                          cbMidiPort.setEnabled(true);                          cbMidiPort.setEnabled(true);
1376                                                    
1377                          MidiPort[] ports = mid.getMidiPorts();                          MidiPort[] ports = mid.getMidiPorts();
# Line 818  class ChannelProperties extends JPanel { Line 1392  class ChannelProperties extends JPanel {
1392          setMidiPort() {          setMidiPort() {
1393                  if(isUpdate()) return;                  if(isUpdate()) return;
1394                                    
1395                  getModel().setMidiInputPort(cbMidiPort.getSelectedIndex());                  getModel().setBackendMidiInputPort(cbMidiPort.getSelectedIndex());
1396          }          }
1397                    
1398          private void          private void
# Line 830  class ChannelProperties extends JPanel { Line 1404  class ChannelProperties extends JPanel {
1404                                    
1405                  int c = o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()) - 1;                  int c = o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()) - 1;
1406                                    
1407                  getModel().setMidiInputChannel(c);                  getModel().setBackendMidiInputChannel(c);
1408          }          }
1409                    
1410          /** Invoked when the user selects an engine. */          /** Invoked when the user selects an engine. */
# Line 842  class ChannelProperties extends JPanel { Line 1416  class ChannelProperties extends JPanel {
1416                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }
1417                  else if(newEngine == null) return;                  else if(newEngine == null) return;
1418                                    
1419                  getModel().setEngineType(newEngine.getName());                  getModel().setBackendEngineType(newEngine.getName());
1420                                    
1421          }          }
1422                    
# Line 850  class ChannelProperties extends JPanel { Line 1424  class ChannelProperties extends JPanel {
1424          setAudioDevice() {          setAudioDevice() {
1425                  if(isUpdate()) return;                  if(isUpdate()) return;
1426                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();
1427                  if(dev != null) getModel().setAudioOutputDevice(dev.getDeviceID());                  if(dev != null) getModel().setBackendAudioOutputDevice(dev.getDeviceId());
1428          }          }
1429                    
1430          /**          /**
# Line 875  class ChannelProperties extends JPanel { Line 1449  class ChannelProperties extends JPanel {
1449          private Handler          private Handler
1450          getHandler() { return handler; }          getHandler() { return handler; }
1451                    
1452          private class Handler implements MidiDeviceListListener, AudioDeviceListListener {          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1453                                            SamplerChannelListListener, MidiDeviceListener {
1454                    
1455                  /**                  /**
1456                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1457                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 902  class ChannelProperties extends JPanel { Line 1478  class ChannelProperties extends JPanel {
1478                   * instance providing the event information.                   * instance providing the event information.
1479                   */                   */
1480                  public void                  public void
1481                  deviceAdded(AudioDeviceListEvent e) {                  entryAdded(ListEvent<AudioDeviceModel> e) {
1482                          cbAudioDevice.addItem(e.getAudioDeviceModel().getDeviceInfo());                          cbAudioDevice.addItem(e.getEntry().getDeviceInfo());
1483                  }                  }
1484                    
1485                  /**                  /**
# Line 912  class ChannelProperties extends JPanel { Line 1488  class ChannelProperties extends JPanel {
1488                   * instance providing the event information.                   * instance providing the event information.
1489                   */                   */
1490                  public void                  public void
1491                  deviceRemoved(AudioDeviceListEvent e) {                  entryRemoved(ListEvent<AudioDeviceModel> e) {
1492                          cbAudioDevice.removeItem(e.getAudioDeviceModel().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1493                    }
1494                    
1495                    /**
1496                     * Invoked when a new sampler channel is created.
1497                     * @param e A <code>SamplerChannelListEvent</code>
1498                     * instance providing the event information.
1499                     */
1500                    public void
1501                    channelAdded(SamplerChannelListEvent e) { }
1502            
1503                    /**
1504                     * Invoked when a sampler channel is removed.
1505                     * @param e A <code>SamplerChannelListEvent</code>
1506                     * instance providing the event information.
1507                     */
1508                    public void
1509                    channelRemoved(SamplerChannelListEvent e) {
1510                            // Some cleanup when the channel is removed.
1511                            if(e.getChannelModel().getChannelId() == channelModel.getChannelId()) {
1512                                    SamplerModel sm = CC.getSamplerModel();
1513                                    
1514                                    sm.removeMidiDeviceListListener(getHandler());
1515                                    sm.removeAudioDeviceListListener(getHandler());
1516                                    sm.removeMidiInstrumentMapListListener(mapListListener);
1517                                    sm.removeSamplerListener(samplerListener);
1518                                    sm.removeSamplerChannelListListener(getHandler());
1519                                    
1520                                    if(midiDevice != null) {
1521                                            midiDevice.removeMidiDeviceListener(getHandler());
1522                                    }
1523                            }
1524                    }
1525                    
1526                    public void
1527                    settingsChanged(MidiDeviceEvent e) {
1528                            if(isUpdate()) {
1529                                    CC.getLogger().warning("Invalid update state");
1530                                    return;
1531                            }
1532                            
1533                            setUpdate(true);
1534                            int idx = cbMidiPort.getSelectedIndex();
1535                            MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
1536                            
1537                            cbMidiPort.removeAllItems();
1538                            for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port);
1539                            
1540                            if(idx >= cbMidiPort.getModel().getSize()) idx = 0;
1541                            
1542                            setUpdate(false);
1543                            
1544                            if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx);
1545                    }
1546            }
1547            
1548            private class MapListListener implements ListListener<MidiInstrumentMap> {
1549                    /** Invoked when a new MIDI instrument map is added to a list. */
1550                    public void
1551                    entryAdded(ListEvent<MidiInstrumentMap> e) {
1552                            cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());
1553                            boolean b = getModel().getChannelInfo().getEngine() != null;
1554                            if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);
1555                    }
1556            
1557                    /** Invoked when a new MIDI instrument map is removed from a list. */
1558                    public void
1559                    entryRemoved(ListEvent<MidiInstrumentMap> e) {
1560                            cbInstrumentMap.removeItem(e.getEntry());
1561                            if(cbInstrumentMap.getItemCount() == 0) {
1562                                    cbInstrumentMap.setSelectedItem(noMap);
1563                                    cbInstrumentMap.setEnabled(false);
1564                            }
1565                  }                  }
1566          }          }
1567  }  }

Legend:
Removed from v.787  
changed lines
  Added in v.1343

  ViewVC Help
Powered by ViewVC