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

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

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

revision 912 by iliev, Mon Aug 7 18:34:40 2006 UTC revision 1975 by iliev, Mon Aug 3 14:54:18 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005, 2006 Grigor Kirilov Iliev   *   Copyright (C) 2005-2008 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.fantasia;  package org.jsampler.view.fantasia;
24    
25  import java.awt.Cursor;  import java.awt.Container;
26  import java.awt.Dimension;  import java.awt.Dimension;
27  import java.awt.Insets;  import java.awt.Rectangle;
28    
29  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
30  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
31  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
32  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
33    
34  import java.util.logging.Level;  import java.beans.PropertyChangeEvent;
35    import java.beans.PropertyChangeListener;
36    
37  import javax.swing.BorderFactory;  import java.text.NumberFormat;
38  import javax.swing.Box;  
39    import javax.swing.AbstractAction;
40    import javax.swing.Action;
41  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
42  import javax.swing.DefaultListCellRenderer;  import javax.swing.ImageIcon;
43  import javax.swing.JButton;  import javax.swing.JButton;
44  import javax.swing.JComboBox;  import javax.swing.JComponent;
45  import javax.swing.JLabel;  import javax.swing.JLabel;
46    import javax.swing.JMenuItem;
47  import javax.swing.JPanel;  import javax.swing.JPanel;
48  import javax.swing.JToggleButton;  import javax.swing.JPopupMenu;
49  import javax.swing.SwingConstants;  import javax.swing.JScrollPane;
50    import javax.swing.JToolBar;
 import javax.swing.event.ChangeEvent;  
 import javax.swing.event.ChangeListener;  
51    
52  import net.sf.juife.Dial;  import org.jdesktop.swingx.JXCollapsiblePane;
 import net.sf.juife.JuifeUtils;  
 import net.sf.juife.TitleBar;  
53    
 import org.jsampler.AudioDeviceModel;  
54  import org.jsampler.CC;  import org.jsampler.CC;
55  import org.jsampler.MidiDeviceModel;  import org.jsampler.HF;
56  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
 import org.jsampler.SamplerModel;  
57    
 import org.jsampler.event.AudioDeviceListEvent;  
 import org.jsampler.event.AudioDeviceListListener;  
 import org.jsampler.event.MidiDeviceListEvent;  
 import org.jsampler.event.MidiDeviceListListener;  
 import org.jsampler.event.SamplerChannelAdapter;  
58  import org.jsampler.event.SamplerChannelEvent;  import org.jsampler.event.SamplerChannelEvent;
59    import org.jsampler.event.SamplerChannelListEvent;
60    import org.jsampler.event.SamplerChannelListListener;
61  import org.jsampler.event.SamplerChannelListener;  import org.jsampler.event.SamplerChannelListener;
62    
63  import org.jsampler.task.RemoveChannel;  import org.jsampler.view.JSChannel;
64    import org.jsampler.view.JSChannelsPane;
65    
66    import org.jsampler.view.fantasia.basic.PixmapToggleButton;
67    
68    import org.jsampler.view.std.JSChannelOutputRoutingDlg;
69    import org.jsampler.view.std.JSFxSendsDlg;
70    import org.jsampler.view.std.JSFxSendsPane;
71    import org.jsampler.view.std.JSInstrumentChooser;
72    import org.jsampler.view.std.JSVolumeEditorPopup;
73    
 import org.linuxsampler.lscp.AudioOutputDevice;  
 import org.linuxsampler.lscp.MidiInputDevice;  
 import org.linuxsampler.lscp.MidiPort;  
74  import org.linuxsampler.lscp.SamplerChannel;  import org.linuxsampler.lscp.SamplerChannel;
 import org.linuxsampler.lscp.SamplerEngine;  
75    
76    import static org.jsampler.view.fantasia.A4n.a4n;
77  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
78    import static org.jsampler.view.fantasia.FantasiaPrefs.*;
79    import static org.jsampler.view.fantasia.FantasiaUtils.*;
80    import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType;
81    
82    
83  /**  /**
84   *   *
85   * @author Grigor Iliev   * @author Grigor Iliev
86   */   */
87  public class Channel extends org.jsampler.view.JSChannel {  public class Channel extends JSChannel {
88          private final ChannelScreen screen = new ChannelScreen(this);          private final JXCollapsiblePane mainPane;
89          private final ChannelOptions optionsPane = new ChannelOptions(this);          private final ChannelOptionsPane optionsPane = new ChannelOptionsPane();
           
         private final PowerButton btnPower = new PowerButton();  
         private final MuteButton btnMute = new MuteButton();  
         private final SoloButton btnSolo = new SoloButton();  
         private final OptionsButton btnOptions = new OptionsButton();  
90                    
91          private final EnhancedDial dialVolume = new EnhancedDial();          private final ViewTracker viewTracker;
92            
93            private JSFxSendsDlg fxSendsDlg = null;
94            
95            private final ContextMenu contextMenu;
96                    
97          private boolean selected = false;          private boolean selected = false;
98                    
99            private AnimatedPorpetyListener animatedPorpetyListener = new AnimatedPorpetyListener();
100            
101            class AnimatedPorpetyListener implements PropertyChangeListener {
102                    public void
103                    propertyChange(PropertyChangeEvent e) {
104                            mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
105                    }
106            }
107            
108            ////////////////////////////////
109            // ******* Mouse tracker *******
110            ////////////////////////////////
111            private static int mouseOverChannelId = -1;
112            private static boolean mousePressed = false;
113            
114            private static ActionListener guiListener = null;
115            
116            private static Channel oldMouseOverChannel = null;
117            private static Channel newMouseOverChannel = null;
118            
119            
120            private static void
121            mouseMoved() {
122                    JSChannelsPane cp = CC.getMainFrame().getSelectedChannelsPane();
123                    for(int i = 0; i < cp.getChannelCount(); i++) {
124                            mouseMoved((Channel)cp.getChannel(i));
125                    }
126                    
127                    if(oldMouseOverChannel == newMouseOverChannel) return;
128                    
129                    if(oldMouseOverChannel != null) oldMouseOverChannel.mouseExited();
130                    
131                    if(newMouseOverChannel != null) {
132                            mouseOverChannelId = newMouseOverChannel.getChannelId();
133                            newMouseOverChannel.mouseEntered();
134                    }
135                    
136                    oldMouseOverChannel = newMouseOverChannel = null;
137            }
138            
139            private static void
140            mouseMoved(Channel c) {
141                    int id = c.getChannelId();
142                    if(c.mainPane.getMousePosition(true) != null) {
143                            newMouseOverChannel = c;
144                    } else if(id == mouseOverChannelId) {
145                            oldMouseOverChannel = c;
146                    }
147            }
148            
149            ////////////////////////////////
150            
151            
152          /**          /**
153           * Creates a new instance of <code>Channel</code> using the specified           * Creates a new instance of <code>Channel</code> using the specified
154           * non-<code>null</code> channel model.           * non-<code>null</code> channel model.
# Line 101  public class Channel extends org.jsample Line 157  public class Channel extends org.jsample
157           */           */
158          public          public
159          Channel(SamplerChannelModel model) {          Channel(SamplerChannelModel model) {
160                    this(model, null);
161            }
162            
163            /**
164             * Creates a new instance of <code>Channel</code> using the specified
165             * non-<code>null</code> channel model.
166             * @param model The model to be used by this channel.
167             * @param listener A listener which is notified when the newly created
168             * channel is fully expanded on the screen.
169             * @throws IllegalArgumentException If the model is <code>null</code>.
170             */
171            public
172            Channel(SamplerChannelModel model, final ActionListener listener) {
173                    this (
174                            model, listener,
175                            preferences().getIntProperty(DEFAULT_CHANNEL_VIEW) == 0 ?
176                                    ChannelView.Type.SMALL : ChannelView.Type.NORMAL
177                    );
178            }
179            
180            /**
181             * Creates a new instance of <code>Channel</code> using the specified
182             * non-<code>null</code> channel model.
183             * @param model The model to be used by this channel.
184             * @param listener A listener which is notified when the newly created
185             * channel is fully expanded on the screen.
186             * @param type Specifies the view type to be used.
187             * @throws IllegalArgumentException If the model is <code>null</code>.
188             */
189            public
190            Channel(SamplerChannelModel model, final ActionListener listener, ChannelView.Type type) {
191                  super(model);                  super(model);
192                                    
193                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                 JPanel p = new JPanel();  
                 p.setName("Channel");  
                 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));  
                   
                 //p.add(Box.createRigidArea(new Dimension(3, 0)));  
                   
                 btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT);  
                   
                 TitleBar tb = new TitleBar();  
                 tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4));  
                 tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));  
                 tb.setOpaque(false);  
                 tb.setAlignmentY(JPanel.TOP_ALIGNMENT);  
                 tb.add(btnPower);  
                 tb.setPreferredSize(new Dimension(tb.getPreferredSize().width, 58));  
                 tb.setMinimumSize(tb.getPreferredSize());  
                 tb.setMaximumSize(tb.getPreferredSize());  
                 p.add(tb);  
                   
                 //p.add(Box.createRigidArea(new Dimension(4, 0)));  
                   
                 p.add(createVSeparator());  
                   
                 //p.add(Box.createRigidArea(new Dimension(3, 0)));  
                   
                 JPanel p2 = new JPanel();  
                 p2.setOpaque(false);  
                 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));  
                 p2.setAlignmentY(JPanel.TOP_ALIGNMENT);  
                 p2.setBorder(BorderFactory.createEmptyBorder(5, 3, 0, 2));  
                 p2.add(screen);  
                 p.add(p2);  
                   
                 p.add(createVSeparator());  
                   
                 p2 = new JPanel();  
                 p2.setOpaque(false);  
                 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));  
                 p2.setAlignmentY(JPanel.TOP_ALIGNMENT);  
                 p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));  
                 p2.add(new JLabel(Res.iconMuteTitle));  
                 p2.add(btnMute);  
                 p2.add(new JLabel(Res.iconSoloTitle));  
                 p2.add(btnSolo);  
                   
                 p.add(p2);  
                   
                 p.add(createVSeparator());  
                   
                 p2 = new JPanel();  
                 p2.setOpaque(false);  
                 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));  
                 p2.setAlignmentY(JPanel.TOP_ALIGNMENT);  
                 p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));  
                 JLabel l = new JLabel(Res.iconVolumeTitle);  
                 l.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));  
                 p2.add(l);  
                 dialVolume.setDialPixmap(Res.iconVolumeDial, 30, 330);  
                 dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 p2.add(dialVolume);  
                 p.add(p2);  
                   
                 p.add(createVSeparator());  
                   
                 p2 = new JPanel();  
                 p2.setOpaque(false);  
                 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));  
                 p2.setAlignmentY(JPanel.TOP_ALIGNMENT);  
                 p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0));  
                 l = new JLabel(Res.iconOptionsTitle);  
                 l.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));  
                 p2.add(l);  
                   
                 p2.add(Box.createRigidArea(new Dimension(0, 3)));  
                   
                 btnOptions.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 p2.add(btnOptions);  
                 p.add(p2);  
                   
                   
                 p.setPreferredSize(new Dimension(420, 60));  
                 p.setMinimumSize(p.getPreferredSize());  
                 p.setMaximumSize(p.getPreferredSize());  
                 //p.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));  
   
                 p.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
194                  optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);
                 add(p);  
                 add(optionsPane);  
195                                    
196                  setOpaque(true);                  mainPane = new JXCollapsiblePane();
197                    viewTracker = new ViewTracker();
198                    contextMenu = new ContextMenu();
199                    
200                    mainPane.getContentPane().setLayout (
201                            new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)
202                    );
203                    
204                    switch(type) {
205                            case SMALL: viewTracker.setView(new SmallChannelView(Channel.this)); break;
206                            case NORMAL: viewTracker.setView(new NormalChannelView(Channel.this)); break;
207                            default: viewTracker.setView(new NormalChannelView(Channel.this));
208                    }
209                    
210                    setOpaque(false);
211                                    
212                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
213                                    
214                  updateChannelInfo();                  updateChannelInfo();
215                    
216                    add(mainPane);
217                    
218                    if(listener != null) {
219                            final String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
220                            mainPane.addPropertyChangeListener(s, new PropertyChangeListener() {
221                                    public void
222                                    propertyChange(PropertyChangeEvent e) {
223                                            if(e.getNewValue() == "expanded") {
224                                                    // TODO: this should be done regardles the listener != null?
225                                                    mainPane.removePropertyChangeListener(s, this);
226                                                    ///////
227                                                    listener.actionPerformed(null);
228                                                    ensureChannelIsVisible();
229                                            } else if(e.getNewValue() == "expanding/collapsing") {
230                                                    ensureChannelIsVisible();
231                                            }
232                                    }
233                            });
234                    }
235                    
236                    mainPane.setAnimated(false);
237                    mainPane.setCollapsed(true);
238                    mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
239                    mainPane.setCollapsed(false);
240                    
241                    preferences().addPropertyChangeListener(ANIMATED, animatedPorpetyListener);
242                    
243                    if(listener != null) {
244                            javax.swing.SwingUtilities.invokeLater(new Runnable() {
245                                    public void
246                                    run() { listener.actionPerformed(null); }
247                            });
248                    }
249                    
250                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
251                    
252                    installGuiListener();
253          }          }
254                    
255          private JPanel          private static void
256          createVSeparator() {          installGuiListener() {
257                  JPanel p = new JPanel();                  if(guiListener != null) return;
258                  p.setName("VSeparator");                  
259                  p.setOpaque(false);                  guiListener = new ActionListener() {
260                  p.setAlignmentY(JPanel.TOP_ALIGNMENT);                          public void
261                  p.setPreferredSize(new Dimension(2, 60));                          actionPerformed(ActionEvent e) {
262                  p.setMinimumSize(p.getPreferredSize());                                  mouseMoved();
263                  p.setMaximumSize(p.getPreferredSize());                          }
264                  return p;                  };
265                    
266                    ((MainFrame)CC.getMainFrame()).getGuiTimer().addActionListener(guiListener);
267            }
268            
269            private void
270            mouseEntered() {
271                    viewTracker.mouseEntered();
272            }
273            
274            private void
275            mouseExited() {
276                    viewTracker.mouseExited();
277            }
278            
279            private void
280            ensureChannelIsVisible() {
281                    Container p = getParent();
282                    JScrollPane sp = null;
283                    while(p != null) {
284                            if(p instanceof JScrollPane) {
285                                    sp = (JScrollPane)p;
286                                    break;
287                            }
288                            p = p.getParent();
289                    }
290                    if(sp == null) return;
291                    int h = sp.getViewport().getView().getHeight();
292                    sp.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
293          }          }
294                    
295          /**          /**
296           * Determines whether the channel is selected.           * Determines whether the channel is selected.
297           * @return <code>true</code> if the channel is selected, <code>false</code> otherwise.           * @return <code>true</code> if the channel is selected, <code>false</code> otherwise.
298           */           */
299          public boolean isSelected() { return selected; }          @Override
300            public boolean
301            isSelected() { return selected; }
302                    
303          /**          /**
304           * Sets the selection state of this channel.           * Sets the selection state of this channel.
# Line 227  public class Channel extends org.jsample Line 306  public class Channel extends org.jsample
306           * @param select Specifies the new selection state of this channel;           * @param select Specifies the new selection state of this channel;
307           * <code>true</code> to select the channel, <code>false</code> otherwise.           * <code>true</code> to select the channel, <code>false</code> otherwise.
308           */           */
309            @Override
310          public void          public void
311          setSelected(boolean select) {          setSelected(boolean select) {
312                                    if(selected == select) return;
313                  selected = select;                  selected = select;
314                    repaint();
315          }          }
316                    
317          /** Shows the channel properties. */          /** Shows the channel properties. */
318          public void          public void
319          expandChannel() { if(!btnOptions.isSelected()) btnOptions.doClick(); }          expandChannel() { expandChannel(optionsPane.isAnimated()); }
320                    
321                    /** Shows the channel properties. */
322          /** Invoked when the user changes the volume */          public void
323          private void          expandChannel(boolean animated) {
324          setVolume() {                  boolean b = optionsPane.isAnimated();
325                  screen.updateVolumeInfo(dialVolume.getValue());                  optionsPane.setAnimated(animated);
326                                    viewTracker.getCurrentView().expandChannel();
327                  if(dialVolume.getValueIsAdjusting()) return;                  optionsPane.setAnimated(b);
                   
                 int vol = (int)(getChannelInfo().getVolume() * 100);  
                   
                 if(vol == dialVolume.getValue()) return;  
                   
                   
                 /*  
                  * If the model's volume is not equal to the dial knob  
                  * value we assume that the change is due to user input.  
                  * So we must update the volume at the backend too.  
                  */  
                 float volume = dialVolume.getValue();  
                 volume /= 100;  
                 getModel().setVolume(volume);  
328          }          }
329                    
330          /**          /**
# Line 266  public class Channel extends org.jsample Line 333  public class Channel extends org.jsample
333           */           */
334          private void          private void
335          updateChannelInfo() {          updateChannelInfo() {
336                  SamplerChannel sc = getChannelInfo();                  viewTracker.getCurrentView().updateChannelInfo();
337                            }
338                  screen.updateScreenInfo(sc);          
339                  updateMuteIcon(sc);          public void
340            loadInstrument() {
341                    JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
342                    dlg.setVisible(true);
343                                    
344                  if(sc.isSoloChannel()) btnSolo.setIcon(Res.iconSoloOn);                  if(!dlg.isCancelled()) {
345                  else btnSolo.setIcon(Res.iconSoloOff);                          SamplerChannelModel m = getModel();
346                            m.loadBackendInstrument(dlg.getInstrumentFile(), dlg.getInstrumentIndex());
347                    }
348            }
349            
350            public void
351            fallbackToOriginalView() {
352                    viewTracker.fallbackToOriginalView();
353            }
354            
355            public boolean
356            isUsingOriginalView() {
357                    return viewTracker.isUsingOriginalView();
358            }
359            
360            protected void
361            onDestroy() {
362                    CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
363                    preferences().removePropertyChangeListener(ANIMATED, animatedPorpetyListener);
364                    if(fxSendsDlg != null) fxSendsDlg.dispose();
365                    viewTracker.onDestroy();
366            }
367                                    
368                  dialVolume.setValue((int)(sc.getVolume() * 100));          public void
369            remove() {
370                    if(!mainPane.isAnimated()) {
371                            CC.getSamplerModel().removeBackendChannel(getChannelId());
372                            return;
373                    }
374                                    
375                  boolean b = sc.getEngine() != null;                  String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
376                  dialVolume.setEnabled(b);                  mainPane.addPropertyChangeListener(s, getHandler());
377                  btnSolo.setEnabled(b);                  mainPane.setCollapsed(true);
                 btnMute.setEnabled(b);  
378          }          }
379                    
380          /**          public void
381           * Updates the mute button with the proper icon regarding to information obtained          showOptionsPane(boolean show) { optionsPane.showOptionsPane(show); }
          * from <code>channel</code>.  
          * @param channel A <code>SamplerChannel</code> instance containing the new settings  
          * for this channel.  
          */  
         private void  
         updateMuteIcon(SamplerChannel channel) {  
                 if(channel.isMutedBySolo()) btnMute.setIcon(Res.iconMutedBySolo);  
                 else if(channel.isMuted()) btnMute.setIcon(Res.iconMuteOn);  
                 else btnMute.setIcon(Res.iconMuteOff);  
         }  
382                    
383          private class EnhancedDial extends Dial {          public void
384                  EnhancedDial() {          showFxSendsDialog() {
385                          super(0, 100);                  if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
386                                                    fxSendsDlg.toFront();
387                          setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP);                          return;
                           
                         addMouseListener(new MouseAdapter() {  
                                 public void  
                                 mouseClicked(MouseEvent e) {  
                                         if(e.getButton() == e.BUTTON3) {  
                                                 setValue(getMaximum() / 2);  
                                                 return;  
                                         }  
                                           
                                         if(e.getButton() != e.BUTTON1) return;  
                                           
                                         if(e.getClickCount() < 2) return;  
                                         setValue(getValueByPoint(e.getPoint()));  
                                 }  
                         });  
                           
                         addChangeListener(new ChangeListener() {  
                                 public void  
                                 stateChanged(ChangeEvent e) { setVolume(); }  
                         });  
388                  }                  }
389                    
390                    fxSendsDlg = new JSFxSendsDlg(new FxSendsPane(getModel()));
391                    fxSendsDlg.setVisible(true);
392          }          }
393                    
394          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
# Line 328  public class Channel extends org.jsample Line 396  public class Channel extends org.jsample
396          private EventHandler          private EventHandler
397          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
398                    
399          private class EventHandler implements SamplerChannelListener {          private class EventHandler implements SamplerChannelListener,
400                                            SamplerChannelListListener, PropertyChangeListener {
401                  /**                  /**
402                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
403                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
404                   * containing event information.                   * containing event information.
405                   */                   */
406                    @Override
407                  public void                  public void
408                  channelChanged(SamplerChannelEvent e) { updateChannelInfo(); }                  channelChanged(SamplerChannelEvent e) { updateChannelInfo(); }
409                    
# Line 342  public class Channel extends org.jsample Line 412  public class Channel extends org.jsample
412                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
413                   * containing event information.                   * containing event information.
414                   */                   */
415                    @Override
416                  public void                  public void
417                  streamCountChanged(SamplerChannelEvent e) {                  streamCountChanged(SamplerChannelEvent e) {
418                          screen.updateStreamCount(getModel().getStreamCount());                          viewTracker.getCurrentView().updateStreamCount(getModel().getStreamCount());
419                  }                  }
420                    
421                  /**                  /**
# Line 352  public class Channel extends org.jsample Line 423  public class Channel extends org.jsample
423                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
424                   * containing event information.                   * containing event information.
425                   */                   */
426                    @Override
427                  public void                  public void
428                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
429                          screen.updateVoiceCount(getModel().getVoiceCount());                          viewTracker.getCurrentView().updateVoiceCount(getModel().getVoiceCount());
430                  }                  }
         }  
           
           
         private class PowerButton extends PixmapToggleButton implements ActionListener {  
                 PowerButton() {  
                         super(Res.iconPowerOff, Res.iconPowerOn);  
431                                    
432                          setSelected(true);                  /**
433                          addActionListener(this);                   * Invoked when a new sampler channel is created.
434                     * @param e A <code>SamplerChannelListEvent</code>
435                     * instance providing the event information.
436                     */
437                    @Override
438                    public void
439                    channelAdded(SamplerChannelListEvent e) { }
440            
441                    /**
442                     * Invoked when a sampler channel is removed.
443                     * @param e A <code>SamplerChannelListEvent</code>
444                     * instance providing the event information.
445                     */
446                    @Override
447                    public void
448                    channelRemoved(SamplerChannelListEvent e) {
449                            // Some cleanup when the channel is removed.
450                            if(e.getChannelModel().getChannelId() == getChannelId()) {
451                                    onDestroy();
452                            }
453                  }                  }
454                                    
455                    @Override
456                  public void                  public void
457                  actionPerformed(ActionEvent e) {                  propertyChange(PropertyChangeEvent e) {
458                          CC.getTaskQueue().add(new RemoveChannel(getChannelID()));                          if(e.getNewValue() == "collapsed") {
459                                    CC.getSamplerModel().removeBackendChannel(getChannelId());
460                            }
461                  }                  }
                   
                 public boolean  
                 contains(int x, int y) { return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71; }  
462          }          }
463                    
464          private class MuteButton extends PixmapButton implements ActionListener {          public ViewTracker
465                  MuteButton() {          getViewTracker() { return viewTracker; }
466                          super(Res.iconMuteOff);          
467                          addActionListener(this);          class ViewTracker extends MouseAdapter implements PropertyChangeListener {
468                  }                  private ChannelView originalView;
469                    private ChannelView mouseOverView;
470                    private ChannelView currentView;
471                                    
472                  public void                  private ChannelView.Type mouseOverViewType = null;
                 actionPerformed(ActionEvent e) {  
                         SamplerChannel sc = getChannelInfo();  
                         boolean b = true;  
473                                    
474                          /*                  ViewTracker() {
475                           * Changing the mute button icon now instead of                          
476                           * leaving the work to the notification mechanism of the LinuxSampler.                          
477                           */                          updateMouseOverViewType();
478                          if(sc.isMuted() && !sc.isMutedBySolo()) {                          
479                                  b = false;                          String s = DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER;
480                                  boolean hasSolo = CC.getSamplerModel().hasSoloChannel();                          preferences().addPropertyChangeListener(s, this);
                           
                                 if(sc.isSoloChannel() || !hasSolo) setIcon(Res.iconMuteOff);  
                                 else setIcon(Res.iconMutedBySolo);  
                         } else setIcon(Res.iconMuteOn);  
481                                                    
482                          Channel.this.getModel().setMute(b);                          s = CHANNEL_VIEW_ON_MOUSE_OVER;
483                            preferences().addPropertyChangeListener(s, this);
484                  }                  }
485                                    
486                  public boolean                  public boolean
487                  contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); }                  isUsingOriginalView() {
488          }                          return currentView == originalView;
           
         private class SoloButton extends PixmapButton implements ActionListener {  
                 SoloButton() {  
                         super(Res.iconSoloOff);  
                         addActionListener(this);  
489                  }                  }
490                                    
491                  public void                  private void
492                  actionPerformed(ActionEvent e) {                  installListeners() {
493                          SamplerChannel sc = getChannelInfo();                          
494                          boolean b = !sc.isSoloChannel();                  }
495                                    
496                          /*                  private void
497                           * Changing the solo button icon (and related) now instead of                  uninstallListeners() {
498                           * leaving the work to the notification mechanism of the LinuxSampler.                          
499                           */                  }
500                          if(b) {                  
501                                  setIcon(Res.iconSoloOn);                  private void
502                                  if(sc.isMutedBySolo()) btnMute.setIcon(Res.iconMuteOff);                  updateMouseOverViewType() {
503                          } else {                          if(mouseOverView != null) {
504                                  setIcon(Res.iconSoloOff);                                  mouseOverView.removeEnhancedMouseListener(this);
505                                  if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1)                          }
506                                          btnMute.setIcon(Res.iconMutedBySolo);                          
507                            mouseOverView = null;
508                            
509                            boolean b;
510                            b = preferences().getBoolProperty(DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER);
511                            if(!b) {
512                                    mouseOverViewType = null;
513                                    uninstallListeners();
514                                    return;
515                            }
516                            
517                            int i = preferences().getIntProperty(CHANNEL_VIEW_ON_MOUSE_OVER);
518                            
519                            switch(i) {
520                                    case 0: mouseOverViewType = ChannelView.Type.SMALL; break;
521                                    case 1: mouseOverViewType = ChannelView.Type.NORMAL; break;
522                                    default:mouseOverViewType = null;
523                          }                          }
524                            
525                            if(mouseOverViewType != null) {
526                                    installListeners();
527                            }
528                    }
529                                    
530                          Channel.this.getModel().setSolo(b);                  public ChannelView
531                    getMouseOverView() {
532                            if(mouseOverViewType == null) return null;
533                            
534                            if(mouseOverView == null) {
535                                    Channel channel = Channel.this;
536                                    
537                                    switch(mouseOverViewType) {
538                                    case SMALL: mouseOverView = new SmallChannelView(channel); break;
539                                    case NORMAL: mouseOverView = new NormalChannelView(channel); break;
540                                    default: mouseOverView = new NormalChannelView(channel);
541                                    }
542                                    
543                                    mouseOverView.addEnhancedMouseListener(this);
544                            }
545                            
546                            return mouseOverView;
547                  }                  }
548                                    
549                  public boolean                  public ChannelView
550                  contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); }                  getCurrentView() { return currentView; }
551          }                  
552                            public ChannelView
553          private class OptionsButton extends PixmapToggleButton implements ActionListener {                  getOriginalView() { return originalView; }
554                  OptionsButton() {                  
555                          super(Res.iconOptionsOff, Res.iconOptionsOn);                  public void
556                          addActionListener(this);                  setView(ChannelView view) {
557                            setView(view, true);
558                  }                  }
559                                    
560                  public void                  public void
561                  actionPerformed(ActionEvent e) {                  setView(ChannelView view, boolean manual) {
562                          showOptionsPane(isSelected());                          boolean selected = false;
563                            if(currentView != null) selected = currentView.isOptionsButtonSelected();
564                                                    
565                          String s;                          if(manual) {
566                          if(isSelected()) s = i18n.getButtonLabel("OptionsButton.ttHideOptions");                                  if(originalView != null) {
567                          else s = i18n.getButtonLabel("OptionsButton.ttShowOptions");                                          originalView.removeEnhancedMouseListener(this);
568                                    }
569                                    
570                                    if(originalView != currentView) destroyOriginalView();
571                                    if(currentView != null && currentView.getType() == view.getType()) {
572                                            originalView = currentView;
573                                            originalView.addEnhancedMouseListener(this);
574                                            destroyView(view);
575                                            return;
576                                    }
577                                    
578                                    removeCurrentView();
579                                    
580                                    originalView = view;
581                                    originalView.addEnhancedMouseListener(this);
582                                    currentView = view;
583                            } else {
584                                    if(view.getType() == getCurrentView().getType()) {
585                                            destroyView(view);
586                                            return;
587                                    }
588                                    
589                                    removeCurrentView();
590                                    currentView = view;
591                            }
592                                                    
593                          setToolTipText(s);                          currentView.setOptionsButtonSelected(selected);
594                            
595                            updateView();
596                  }                  }
597                                    
598                  private void                  private void
599                  showOptionsPane(boolean show) {                  updateView() {
600                          optionsPane.setVisible(show);                          ChannelOptionsView view = getCurrentView().getChannelOptionsView();
601                          MainFrame.repack(CC.getMainFrame());                          if(view != null) optionsPane.setContentPane(view.getComponent());
602                  }                          
603                                            updateChannelInfo();
                 public boolean  
                 contains(int x, int y) { return y < 13; }  
         }  
 }  
   
 class ChannelScreen extends JPanel {  
         private final Channel channel;  
         private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));  
         private JButton btnReset = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnReset"));  
         private JButton btnDuplicate =  
                 new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnDuplicate"));  
           
         private final JLabel lVolume = new JLabel();  
         private final JLabel lStreams = new JLabel("--");  
         private final JLabel lVoices = new JLabel("--");  
           
         ChannelScreen(Channel channel) {  
                 this.channel = channel;  
                   
                 setName("ChannelScreen");  
                 setOpaque(true);  
604                                    
605                  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));                          mainPane.add(getCurrentView().getComponent());
606                            mainPane.add(optionsPane);
607                            mainPane.validate();
608                            mainPane.revalidate();
609                            mainPane.repaint();
610                    }
611                                    
612                  btnInstr.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));                  public void
613                  btnInstr.setAlignmentX(CENTER_ALIGNMENT);                  fallbackToOriginalView() {
614                            if(currentView == originalView) return;
615                            
616                            boolean selected = false;
617                            if(currentView != null) selected = currentView.isOptionsButtonSelected();
618                            
619                            removeCurrentView();
620                            currentView = originalView;
621                            currentView.setOptionsButtonSelected(selected);
622                            
623                            updateView();
624                    }
625                                    
626                  add(btnInstr);                  private void
627                    removeCurrentView() { removeView(currentView); }
628                                    
629                  JPanel p = new JPanel();                  private void
630                  p.setOpaque(false);                  destroyCurrentView() { destroyView(currentView); }
                 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));  
                 p.setAlignmentX(CENTER_ALIGNMENT);  
                 p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));  
                 //lVolume.setFont(lVolume.getFont().deriveFont(java.awt.Font.PLAIN));  
631                                    
632                  p.add(btnDuplicate);                  private void
633                    removeOriginalView() { removeView(originalView); }
634                                    
635                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  private void
636                    destroyOriginalView() { destroyView(originalView); }
637                                    
638                  p.add(new JLabel("|"));                  private void
639                    removeView(ChannelView view) {
640                            if(view == null) return;
641                            
642                            mainPane.remove(view.getComponent());
643                            mainPane.remove(optionsPane);
644                                    
645                            destroyView(view);
646                    }
647                                    
648                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  private void
649                    destroyView(ChannelView view) {
650                            if(view == null) return;
651                            
652                            view.uninstallView();
653                            
654                            view = null;
655                    }
656                                    
657                  p.add(btnReset);                  public boolean
658                    isMouseOverEnabled() { return mouseOverViewType != null; }
659                                    
660                  p.add(Box.createGlue());                  private void
661                    mouseEntered() {
662                            if(!isMouseOverEnabled()) return;
663                            if(getCurrentView().getType() == getMouseOverView().getType()) return;
664                            
665                            JSChannel[] channels = CC.getMainFrame().getChannelsPane(0).getChannels();
666                            for(JSChannel c : channels) {
667                                    if(c == Channel.this) continue;
668                                    
669                                    Channel chn = (Channel)c;
670                                    if(!(chn).isUsingOriginalView()) chn.fallbackToOriginalView();
671                            }
672                            
673                            setView(getMouseOverView(), false);
674                    }
675                                    
676                  p.add(lStreams);                  private void
677                  p.add(new JLabel("/"));                  mouseExited() {
678                  p.add(lVoices);                          if(!isMouseOverEnabled()) return;
679                            if(getCurrentView().getType() == originalView.getType()) return;
680                            
681                            fallbackToOriginalView();
682                    }
683                                    
684                  p.add(Box.createRigidArea(new Dimension(12, 0)));                  @Override
685                    public void
686                    mouseEntered(MouseEvent e) {
687                            guiListener.actionPerformed(null);
688                    }
689                                    
690                  lVolume.setAlignmentX(RIGHT_ALIGNMENT);                  @Override
691                  p.add(lVolume);                  public void
692                  p.setPreferredSize(new Dimension(250, p.getPreferredSize().height));                  mouseExited(MouseEvent e) {
693                  p.setMinimumSize(p.getPreferredSize());                          guiListener.actionPerformed(null);
694                  p.setMaximumSize(p.getPreferredSize());                  }
695                                    
696                  add(p);                  @Override
697                    public void
698                    mousePressed(MouseEvent e) {
699                            mousePressed = true;
700                    }
701                                    
702                    @Override
703                    public void
704                    mouseReleased(MouseEvent e) {
705                            mousePressed = false;
706                    }
707                                    
708                  setPreferredSize(new Dimension(270, 48));                  public void
709                  setMinimumSize(getPreferredSize());                  onDestroy() {
710                  setMaximumSize(getPreferredSize());                          destroyCurrentView();
711                            destroyOriginalView();
712                            
713                            uninstallListeners();
714                            
715                            if(currentView != null) {
716                                    currentView.removeEnhancedMouseListener(this);
717                            }
718                            
719                            if(mouseOverView != null) {
720                                    mouseOverView.removeEnhancedMouseListener(this);
721                            }
722                            
723                            String s = DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER;
724                            preferences().removePropertyChangeListener(s, this);
725                            
726                            s = CHANNEL_VIEW_ON_MOUSE_OVER;
727                            preferences().removePropertyChangeListener(s, this);
728                    }
729                                    
730                  installListeners();                  @Override
731                    public void
732                    propertyChange(PropertyChangeEvent e) {
733                            updateMouseOverViewType();
734                    }
735          }          }
736                    
737          private void          class EditInstrumentAction extends AbstractAction implements SamplerChannelListener {
738          installListeners() {                  EditInstrumentAction() {
739                  btnInstr.addActionListener(new ActionListener() {                          super(i18n.getMenuLabel("channels.editInstrument"));
740                          public void                          channelChanged(null);
741                          actionPerformed(ActionEvent e) { loadInstrument(); }                          getModel().addSamplerChannelListener(this);
742                  });                  }
           
                 btnReset.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { channel.getModel().resetChannel(); }  
                 });  
                   
                 btnDuplicate.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { channel.getModel().duplicateChannel(); }  
                 });  
         }  
   
         private void  
         loadInstrument() {  
                 InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame());  
                 dlg.setVisible(true);  
743                                    
744                  if(!dlg.isCancelled()) {                  @Override
745                          SamplerChannelModel m = channel.getModel();                  public void
746                          m.loadInstrument(dlg.getFileName(), dlg.getInstrumentIndex());                  actionPerformed(ActionEvent e) {
747                            CC.getSamplerModel().editBackendInstrument(getChannelId());
748                  }                  }
749          }                  
750                            @Override
751          protected void                  public void
752          updateScreenInfo(SamplerChannel sc) {                  channelChanged(SamplerChannelEvent e) {
753                  int status = sc.getInstrumentStatus();                          boolean b = getChannelInfo().getInstrumentStatus() == 100;
754                  if(status >= 0 && status < 100) {                          setEnabled(b);
                         btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status));  
                 } else if(status == -1) {  
                         btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));  
                 } else if(status < -1) {  
                          btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument"));  
                 } else {  
                         if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());  
                         else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));  
755                  }                  }
           
756                                    
757                    @Override
758                    public void
759                    streamCountChanged(SamplerChannelEvent e) { }
760                                    
761                    @Override
762                    public void
763                    voiceCountChanged(SamplerChannelEvent e) { }
764          }          }
765                    
766          protected void          class FxSendsAction extends AbstractAction {
767          updateVolumeInfo(int volume) {                  FxSendsAction() {
768                  lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume));                          super(i18n.getMenuLabel("channels.fxSends"));
769                    }
770                                    
771          }                  @Override
772                            public void
773          /**                  actionPerformed(ActionEvent e) {
774           * Updates the number of active disk streams.                          showFxSendsDialog();
          * @param count The new number of active disk streams.  
          */  
         protected void  
         updateStreamCount(int count) {  
                 Dimension d = lStreams.getPreferredSize();  
                 lStreams.setText(count == 0 ? "--" : String.valueOf(count));  
                 d = JuifeUtils.getUnionSize(d, lStreams.getPreferredSize());  
                 lStreams.setMinimumSize(d);  
                 lStreams.setPreferredSize(d);  
                 lStreams.setMaximumSize(d);  
         }  
           
         /**  
          * Updates the number of active voices.  
          * @param count The new number of active voices.  
          */  
         protected void  
         updateVoiceCount(int count) {  
                 Dimension d = lVoices.getPreferredSize();  
                 lVoices.setText(count == 0 ? "--" : String.valueOf(count));  
                 d = JuifeUtils.getUnionSize(d, lVoices.getPreferredSize());  
                 lVoices.setMinimumSize(d);  
                 lVoices.setPreferredSize(d);  
                 lVoices.setMaximumSize(d);  
         }  
           
         static class ScreenButton extends JButton {  
                 ScreenButton(String s) {  
                         super(s);  
                         setContentAreaFilled(false);  
                         setFocusPainted(false);  
                         setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));  
                         setMargin(new Insets(0, 0, 0, 0));  
                         setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));  
775                  }                  }
776          }          }
 }  
   
 class ChannelOptions extends JPanel {  
         private final Channel channel;  
777                    
778          private final JComboBox cbMidiDevice = new JComboBox();          class ChannelRoutingAction extends AbstractAction implements SamplerChannelListener {
779          private final JComboBox cbMidiPort = new JComboBox();                  ChannelRoutingAction() {
780          private final JComboBox cbMidiChannel = new JComboBox();                          super(i18n.getMenuLabel("channels.channelRouting"));
781          private final JComboBox cbEngine = new JComboBox();                          channelChanged(null);
782          private final JComboBox cbAudioDevice = new JComboBox();                          getModel().addSamplerChannelListener(this);
783                            }
         private boolean update = false;  
           
         ChannelOptions(Channel channel) {  
                 this.channel = channel;  
                   
                 setName("ChannelOptions");  
                 setVisible(false);  
                 setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4));  
                 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));  
                   
                 setPreferredSize(new Dimension(420, 44));  
                 setMinimumSize(getPreferredSize());  
                 setMaximumSize(getPreferredSize());  
                   
                 JPanel p = new JPanel();  
                 p.setOpaque(true);  
                 p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));  
                 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));  
                 JLabel l = new JLabel(Res.iconMidiInputTitle);  
                 l.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(l);  
                   
                 JPanel p2 = new JPanel();  
                 p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));  
                 p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));  
                   
                 Object o = cbMidiDevice.getRenderer();  
                 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);  
                   
                 cbMidiDevice.setPreferredSize(new Dimension(40, 18));  
                 cbMidiDevice.setMinimumSize(cbMidiDevice.getPreferredSize());  
                 cbMidiDevice.setMaximumSize(cbMidiDevice.getPreferredSize());  
                 p2.add(cbMidiDevice);  
                   
                 p2.add(Box.createRigidArea(new Dimension(3, 0)));  
                   
                 o = cbMidiPort.getRenderer();  
                 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);  
                   
                 cbMidiPort.setPreferredSize(new Dimension(67, 18));  
                 cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize());  
                 cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize());  
                 p2.add(cbMidiPort);  
                   
                 p2.add(Box.createRigidArea(new Dimension(3, 0)));  
                   
                 o = cbMidiChannel.getRenderer();  
                 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);  
                   
                 cbMidiChannel.addItem("All");  
                 for(int i = 1; i <= 16; i++) cbMidiChannel.addItem("Channel " + String.valueOf(i));  
                 cbMidiChannel.setPreferredSize(new Dimension(80, 18));  
                 cbMidiChannel.setMinimumSize(cbMidiChannel.getPreferredSize());  
                 cbMidiChannel.setMaximumSize(cbMidiChannel.getPreferredSize());  
                   
                 p2.add(cbMidiChannel);  
                 p2.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(p2);  
                   
                 add(p);  
                   
                 add(Box.createRigidArea(new Dimension(4, 0)));  
                   
                 p = new JPanel();  
                 p.setOpaque(true);  
                 p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));  
                 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));  
                 l = new JLabel(Res.iconEngineTitle);  
                 l.setAlignmentX(LEFT_ALIGNMENT);  
                 l.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(l);  
                   
                 p.add(Box.createRigidArea(new Dimension(0, 3)));  
                   
                 o = cbEngine.getRenderer();  
                 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER);  
                   
                 for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e);  
                 cbEngine.setPreferredSize(new Dimension(125, 18));  
                 cbEngine.setMinimumSize(cbEngine.getPreferredSize());  
                 cbEngine.setMaximumSize(cbEngine.getPreferredSize());  
                 cbEngine.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(cbEngine);  
                   
                 add(p);  
                   
                 add(Box.createRigidArea(new Dimension(4, 0)));  
                   
                 p = new JPanel();  
                 p.setOpaque(true);  
                 p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4));  
                 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));  
                 l = new JLabel(Res.iconAudioOutputTitle);  
                 l.setAlignmentX(LEFT_ALIGNMENT);  
                 l.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(l);  
                   
                 p.add(Box.createRigidArea(new Dimension(0, 3)));  
                   
                 o = cbAudioDevice.getRenderer();  
                 if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT);  
                   
                 cbAudioDevice.setPreferredSize(new Dimension(61, 18));  
                 cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize());  
                 cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize());  
                 cbAudioDevice.setAlignmentX(LEFT_ALIGNMENT);  
                 p.add(cbAudioDevice);  
                   
                 add(p);  
                   
                 cbMidiDevice.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { setMidiDevice(); }  
                 });  
                   
                 cbMidiPort.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { setMidiPort(); }  
                 });  
                   
                 cbMidiChannel.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { setMidiChannel(); }  
                 });  
                   
                 cbEngine.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { setEngineType(); }  
                 });  
784                                    
785                  cbAudioDevice.addActionListener(new ActionListener() {                  @Override
786                          public void                  public void
787                          actionPerformed(ActionEvent e) { setAudioDevice(); }                  actionPerformed(ActionEvent e) {
788                  });                          SamplerChannel c = getChannelInfo();
789                            new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
790                    }
791                                    
792                  channel.getModel().addSamplerChannelListener(new SamplerChannelAdapter() {                  @Override
793                          public void                  public void
794                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }                  channelChanged(SamplerChannelEvent e) {
795                  });                          boolean b = getChannelInfo().getAudioOutputDevice() != -1;
796                            setEnabled(b);
797                    }
798                                    
799                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());                  @Override
800                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());                  public void
801                    streamCountChanged(SamplerChannelEvent e) { }
802                                    
803                  updateMidiDevices();                  @Override
804                  updateAudioDevices();                  public void
805                  updateChannelProperties();                  voiceCountChanged(SamplerChannelEvent e) { }
806          }          }
807                    
808          /**          public ContextMenu
809           * Updates the channel settings. This method is invoked when changes to the          getContextMenu() { return contextMenu; }
810           * channel were made.          
811           */          class ContextMenu extends MouseAdapter {
812          private void                  private JPopupMenu menu = null;
         updateChannelProperties() {  
                 SamplerModel sm = CC.getSamplerModel();  
                 SamplerChannel sc = channel.getModel().getChannelInfo();  
                   
                 MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice());  
                 AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice());  
                   
                 if(isUpdate()) CC.getLogger().warning("Unexpected update state!");  
813                                    
814                  setUpdate(true);                  ContextMenu() {
815                            
816                    }
817                                    
818                  try {                  private void
819                          cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());                  createMenu() {
820                            menu = new JPopupMenu();
821                            menu.add(new JMenuItem(new EditInstrumentAction()));
822                            menu.addSeparator();
823                                                    
824                          cbEngine.setSelectedItem(sc.getEngine());                          MenuManager.ChannelViewGroup group;
825                            group = new MenuManager.ChannelViewGroup(true, true);
826                            MenuManager.getMenuManager().registerChannelViewGroup(group);
827                                                    
828                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          for(JMenuItem mi : group.getMenuItems()) menu.add(mi);
829                  } catch(Exception x) {                          
830                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          menu.addSeparator();
831                            
832                            menu.add(new JMenuItem(a4n.moveChannelsOnTop));
833                            menu.add(new JMenuItem(a4n.moveChannelsUp));
834                            menu.add(new JMenuItem(a4n.moveChannelsDown));
835                            menu.add(new JMenuItem(a4n.moveChannelsAtBottom));
836                            
837                            menu.add(new MainFrame.ToPanelMenu());
838                            
839                            menu.addSeparator();
840                            
841                            menu.add(new JMenuItem(new FxSendsAction()));
842                            menu.add(new JMenuItem(new ChannelRoutingAction()));
843                    }
844                    
845                    private JPopupMenu
846                    getMenu() {
847                            if(menu == null) createMenu();
848                            return menu;
849                  }                  }
850                                    
851                  setUpdate(false);                  @Override
852                    public void
853                    mousePressed(MouseEvent e) {
854                            if(e.isPopupTrigger()) show(e);
855                    }
856            
857                    @Override
858                    public void
859                    mouseReleased(MouseEvent e) {
860                            if(e.isPopupTrigger()) show(e);
861                    }
862            
863                    void
864                    show(MouseEvent e) {
865                            getMenu().show(e.getComponent(), e.getX(), e.getY());
866                    }
867          }          }
868                    
869          /**          class FxSendsPane extends JSFxSendsPane {
870           * Updates the MIDI device list.                  FxSendsPane(SamplerChannelModel model) {
871           */                          super(model);
872          private void                          
873          updateMidiDevices() {                          actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
874                  SamplerModel sm = CC.getSamplerModel();                          actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
875                  SamplerChannel sc = channel.getModel().getChannelInfo();                  }
                   
                 setUpdate(true);  
                   
                 try {  
                         cbMidiDevice.removeAllItems();  
876                                    
877                          for(MidiDeviceModel m : sm.getMidiDeviceModels())                  @Override
878                                  cbMidiDevice.addItem(m.getDeviceInfo());                  protected JToolBar
879                    createToolBar() {
880                            JToolBar tb = new JToolBar();
881                            Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
882                            tb.setMaximumSize(d);
883                            tb.setFloatable(false);
884                            tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
885                            
886                            tb.add(new ToolbarButton(actionAddFxSend));
887                            tb.add(new ToolbarButton(actionRemoveFxSend));
888                                    
889                          MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice());                          return tb;
                         cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo());  
                 } catch(Exception x) {  
                         CC.getLogger().log(Level.WARNING, "Unkown error", x);  
890                  }                  }
                   
                 setUpdate(false);  
891          }          }
892                    
893          /**          public static class StreamVoiceCountPane extends JPanel {
894           * Updates the audio device list.                  private final Channel channel;
          */  
         private void  
         updateAudioDevices() {  
                 SamplerModel sm = CC.getSamplerModel();  
                 SamplerChannel sc = channel.getModel().getChannelInfo();  
                   
                 setUpdate(true);  
895                                    
896                  try {                  private final JLabel lStreams = createScreenLabel(" --");
897                          cbAudioDevice.removeAllItems();                  private final JLabel lSlash = createScreenLabel("/");
898                    private final JLabel lVoices = createScreenLabel("-- ");
899                                    
900                          for(AudioDeviceModel m : sm.getAudioDeviceModels())                  public
901                                  cbAudioDevice.addItem(m.getDeviceInfo());                  StreamVoiceCountPane(Channel channel) {
902                            this.channel = channel;
903                            
904                            setOpaque(false);
905                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
906                            lStreams.setFont(Res.fontScreenMono);
907                            lStreams.setHorizontalAlignment(JLabel.RIGHT);
908                            lStreams.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
909                            
910                            Dimension d = lStreams.getPreferredSize();
911                            lStreams.setMinimumSize(d);
912                            lStreams.setPreferredSize(d);
913                            lStreams.setMaximumSize(d);
914                            add(lStreams);
915                            
916                            lSlash.setFont(Res.fontScreenMono);
917                            lSlash.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
918                            add(lSlash);
919                            
920                            lVoices.setFont(Res.fontScreenMono);
921                            lVoices.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
922                            
923                            d = lStreams.getPreferredSize();
924                            lVoices.setMinimumSize(d);
925                            lVoices.setPreferredSize(d);
926                            lVoices.setMaximumSize(d);
927                            add(lVoices);
928                            
929                            lStreams.addMouseListener(channel.getContextMenu());
930                            lSlash.addMouseListener(channel.getContextMenu());
931                            lVoices.addMouseListener(channel.getContextMenu());
932                    }
933                                    
934                          AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice());                  public void
935                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                  updateStreamCount(int count) {
936                  } catch(Exception x) {                          lStreams.setText(count == 0 ? " --" : String.valueOf(count));
                         CC.getLogger().log(Level.WARNING, "Unkown error", x);  
937                  }                  }
938                                    
939                  setUpdate(false);                  public void
940                    updateVoiceCount(int count) {
941                            lVoices.setText(count == 0 ? "-- " : String.valueOf(count));
942                    }
943          }          }
944                    
945          private void          public static class VolumePane extends JPanel {
946          setMidiDevice() {                  private final Channel channel;
947                  MidiInputDevice mid = (MidiInputDevice)cbMidiDevice.getSelectedItem();                  private final JButton btnVolume = createScreenButton("");
948                                    private JSVolumeEditorPopup popupVolume;
                 if(!isUpdate()) {  
                         if(mid != null) channel.getModel().setMidiInputDevice(mid.getDeviceID());  
                         return;  
                 }  
949                                    
950                  cbMidiPort.removeAllItems();                  private static NumberFormat numberFormat = NumberFormat.getInstance();
951                    static { numberFormat.setMaximumFractionDigits(1); }
952                                    
953                  if(mid == null) {                  public
954                          cbMidiPort.setEnabled(false);                  VolumePane(final Channel channel) {
955                            this.channel = channel;
956                            setOpaque(false);
957                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
958                                                    
959                          cbMidiChannel.setSelectedItem(null);                          btnVolume.setIcon(Res.iconVolume14);
960                          cbMidiChannel.setEnabled(false);                          btnVolume.setIconTextGap(2);
961                  } else {                          btnVolume.setAlignmentX(RIGHT_ALIGNMENT);
962                          cbMidiPort.setEnabled(true);                          btnVolume.setHorizontalAlignment(btnVolume.LEFT);
963                            updateVolumeInfo(100);
964                            Dimension d = btnVolume.getPreferredSize();
965                            d.width = 57;
966                            btnVolume.setPreferredSize(d);
967                            btnVolume.setMinimumSize(d);
968                            
969                            add(btnVolume);
970                            
971                            btnVolume.addActionListener(new ActionListener() {
972                                    public void
973                                    actionPerformed(ActionEvent e) {
974                                            if(popupVolume.isVisible()) {
975                                                    popupVolume.commit();
976                                                    popupVolume.hide();
977                                            } else {
978                                                    float vol = channel.getModel().getChannelInfo().getVolume();
979                                                    popupVolume.setCurrentVolume(vol);
980                                                    popupVolume.show();
981                                            }
982                                    }
983                            });
984                                                    
985                          MidiPort[] ports = mid.getMidiPorts();                          popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.CHANNEL);
                         for(MidiPort port : ports) cbMidiPort.addItem(port);  
986                                                    
987                          int p = channel.getModel().getChannelInfo().getMidiInputPort();                          popupVolume.addActionListener(new ActionListener() {
988                          cbMidiPort.setSelectedItem(p >= 0 && p < ports.length ? ports[p] : null);                                  public void
989                                    actionPerformed(ActionEvent e) {
990                                            channel.getModel().setBackendVolume(popupVolume.getVolumeFactor());
991                                    }
992                            });
993                                                    
994                          cbMidiChannel.setEnabled(true);                          btnVolume.addMouseListener(channel.getContextMenu());
                         int c = channel.getModel().getChannelInfo().getMidiInputChannel();  
                         cbMidiChannel.setSelectedItem(c == -1 ? "All" : "Channel " + (c + 1));  
995                  }                  }
         }  
           
         private void  
         setMidiPort() {  
                 if(isUpdate()) return;  
996                                    
997                  channel.getModel().setMidiInputPort(cbMidiPort.getSelectedIndex());                  public void
998                    updateVolumeInfo(int volume) {
999                            if(CC.getViewConfig().isMeasurementUnitDecibel()) {
1000                                    String s = numberFormat.format(HF.percentsToDecibels(volume));
1001                                    btnVolume.setText(s + "dB");
1002                            } else {
1003                                    btnVolume.setText(String.valueOf(volume) + "%");
1004                            }
1005                    }
1006          }          }
1007                    
1008          private void          public static class PowerButton extends PixmapToggleButton implements ActionListener {
1009          setMidiChannel() {                  private final Channel channel;
                 if(isUpdate()) return;  
                   
                 Object o = cbMidiChannel.getSelectedItem();  
                 if(o == null) return;  
                 String s = o.toString();  
1010                                    
1011                  int c = s.equals("All") ? -1 : Integer.parseInt(s.substring(8)) - 1;                  PowerButton(Channel channel) {
1012                            this(channel, Res.gfxPowerOff, Res.gfxPowerOn);
1013                    }
1014                                    
1015                  channel.getModel().setMidiInputChannel(c);                  PowerButton(Channel channel, ImageIcon defaultIcon, ImageIcon selectedIcon) {
1016          }                          super(defaultIcon, selectedIcon);
1017                                    
1018          /** Invoked when the user selects an engine. */                          this.channel = channel;
         private void  
         setEngineType() {  
                 Object oldEngine = channel.getModel().getChannelInfo().getEngine();  
                 SamplerEngine newEngine = (SamplerEngine)cbEngine.getSelectedItem();  
1019                                    
1020                  if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; }                          setSelected(true);
1021                  else if(newEngine == null) return;                          addActionListener(this);
1022                            setToolTipText(i18n.getButtonLabel("Channel.ttRemoveChannel"));
1023                    }
1024                                    
1025                  channel.getModel().setEngineType(newEngine.getName());                  @Override
1026                    public void
1027                    actionPerformed(ActionEvent e) {
1028                            boolean b = preferences().getBoolProperty(CONFIRM_CHANNEL_REMOVAL);
1029                            if(b) {
1030                                    String s = i18n.getMessage("Channel.remove?", channel.getChannelId());
1031                                    if(!HF.showYesNoDialog(channel, s)) {
1032                                            setSelected(true);
1033                                            return;
1034                                    }
1035                            }
1036                            channel.remove();
1037                    }
1038                                    
1039                    @Override
1040                    public boolean
1041                    contains(int x, int y) { return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71; }
1042          }          }
1043                    
1044          private void          public static class OptionsButton extends PixmapToggleButton
1045          setAudioDevice() {                                          implements ActionListener, PropertyChangeListener {
1046                  if(isUpdate()) return;                  
1047                  AudioOutputDevice dev = (AudioOutputDevice)cbAudioDevice.getSelectedItem();                  private final Channel channel;
1048                  if(dev != null) channel.getModel().setAudioOutputDevice(dev.getDeviceID());                  
1049          }                  OptionsButton(Channel channel) {
1050                                    super(Res.gfxOptionsOff, Res.gfxOptionsOn);
1051          /**                          
1052           * Determines whether the currently processed changes are due to update.                          this.channel = channel;
1053           * @return <code>true</code> if the currently processed changes are due to update and                          
1054           * <code>false</code> if the currently processed changes are due to user input.                          setRolloverIcon(Res.gfxOptionsOffRO);
1055           */                          this.setRolloverSelectedIcon(Res.gfxOptionsOnRO);
1056          private boolean                          addActionListener(this);
1057          isUpdate() { return update; }                          setToolTipText(i18n.getButtonLabel("Channel.ttShowOptions"));
           
         /**  
          * Sets whether the currently processed changes are due to update.  
          * @param b Specify <code>true</code> to indicate that the currently  
          * processed changes are due to update; <code>false</code>  
          * indicates that the currently processed changes are due to user input.  
          */  
         private void  
         setUpdate(boolean b) { update = b; }  
           
         private final Handler handler = new Handler();  
           
         private Handler  
         getHandler() { return handler; }  
           
         private class Handler implements MidiDeviceListListener, AudioDeviceListListener {  
                 /**  
                  * Invoked when a new MIDI device is created.  
                  * @param e A <code>MidiDeviceListEvent</code>  
                  * instance providing the event information.  
                  */  
                 public void  
                 deviceAdded(MidiDeviceListEvent e) {  
                         cbMidiDevice.addItem(e.getMidiDeviceModel().getDeviceInfo());  
1058                  }                  }
1059                            
1060                  /**                  @Override
                  * Invoked when a MIDI device is removed.  
                  * @param e A <code>MidiDeviceListEvent</code>  
                  * instance providing the event information.  
                  */  
1061                  public void                  public void
1062                  deviceRemoved(MidiDeviceListEvent e) {                  actionPerformed(ActionEvent e) {
1063                          cbMidiDevice.removeItem(e.getMidiDeviceModel().getDeviceInfo());                          ChannelView view = channel.viewTracker.getCurrentView();
1064                            
1065                            if(isSelected() && view.getChannelOptionsView() == null) {
1066                                    view.installChannelOptionsView();
1067                                    JComponent c = view.getChannelOptionsView().getComponent();
1068                                    channel.optionsPane.setContentPane(c);
1069                            }
1070                            
1071                            channel.showOptionsPane(isSelected());
1072                            
1073                            String s;
1074                            if(isSelected()) s = i18n.getButtonLabel("Channel.ttHideOptions");
1075                            else s = i18n.getButtonLabel("Channel.ttShowOptions");
1076                            
1077                            setToolTipText(s);
1078                            
1079                            s = JXCollapsiblePane.ANIMATION_STATE_KEY;
1080                            channel.optionsPane.addPropertyChangeListener(s, this);
1081                  }                  }
1082                                    
1083                  /**                  @Override
                  * Invoked when a new audio device is created.  
                  * @param e An <code>AudioDeviceListEvent</code>  
                  * instance providing the event information.  
                  */  
1084                  public void                  public void
1085                  deviceAdded(AudioDeviceListEvent e) {                  propertyChange(PropertyChangeEvent e) {
1086                          cbAudioDevice.addItem(e.getAudioDeviceModel().getDeviceInfo());                          if(e.getNewValue() == "collapsed") {
1087                                    ChannelView view = channel.viewTracker.getCurrentView();
1088                                    view.uninstallChannelOptionsView();
1089                                    channel.optionsPane.setContentPane(new JPanel());
1090                            }
1091                  }                  }
1092                            
                 /**  
                  * Invoked when an audio device is removed.  
                  * @param e An <code>AudioDeviceListEvent</code>  
                  * instance providing the event information.  
                  */  
1093                  public void                  public void
1094                  deviceRemoved(AudioDeviceListEvent e) {                  onDestroy() {
1095                          cbAudioDevice.removeItem(e.getAudioDeviceModel().getDeviceInfo());                          String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
1096                            channel.optionsPane.removePropertyChangeListener(s, this);
1097                  }                  }
1098                    
1099                    @Override
1100                    public boolean
1101                    contains(int x, int y) { return super.contains(x, y) & y < 13; }
1102            }
1103    }
1104    
1105    class ChannelOptionsPane extends JXCollapsiblePane {
1106            ChannelOptionsPane() {
1107                    setAnimated(false);
1108                    setCollapsed(true);
1109                    setAnimated(preferences().getBoolProperty(ANIMATED));
1110                    
1111                    preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
1112                            public void
1113                            propertyChange(PropertyChangeEvent e) {
1114                                    setAnimated(preferences().getBoolProperty(ANIMATED));
1115                            }
1116                    });
1117          }          }
1118            
1119            public void
1120            showOptionsPane(boolean show) { setCollapsed(!show); }
1121  }  }

Legend:
Removed from v.912  
changed lines
  Added in v.1975

  ViewVC Help
Powered by ViewVC