/[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 1343 by iliev, Tue Sep 11 15:38:28 2007 UTC revision 1545 by iliev, Tue Dec 4 18:28:29 2007 UTC
# 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.Graphics;  import java.awt.Graphics;
28    import java.awt.Graphics2D;
29  import java.awt.Insets;  import java.awt.Insets;
30    import java.awt.Rectangle;
31    
32  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
33  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
# Line 37  import java.awt.event.MouseEvent; Line 39  import java.awt.event.MouseEvent;
39  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
40  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
41    
42    import java.text.NumberFormat;
43    
44  import java.util.logging.Level;  import java.util.logging.Level;
45    
46  import javax.swing.Action;  import javax.swing.Action;
# Line 46  import javax.swing.BoxLayout; Line 50  import javax.swing.BoxLayout;
50  import javax.swing.DefaultListCellRenderer;  import javax.swing.DefaultListCellRenderer;
51  import javax.swing.JButton;  import javax.swing.JButton;
52  import javax.swing.JComboBox;  import javax.swing.JComboBox;
53    import javax.swing.JComponent;
54  import javax.swing.JLabel;  import javax.swing.JLabel;
55  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
56  import javax.swing.JPanel;  import javax.swing.JPanel;
57  import javax.swing.JPopupMenu;  import javax.swing.JPopupMenu;
58    import javax.swing.JScrollPane;
59  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
60  import javax.swing.JToolBar;  import javax.swing.JToolBar;
61  import javax.swing.SwingConstants;  import javax.swing.SwingConstants;
# Line 67  import org.jdesktop.swingx.JXCollapsible Line 73  import org.jdesktop.swingx.JXCollapsible
73    
74  import org.jsampler.AudioDeviceModel;  import org.jsampler.AudioDeviceModel;
75  import org.jsampler.CC;  import org.jsampler.CC;
76    import org.jsampler.HF;
77  import org.jsampler.MidiDeviceModel;  import org.jsampler.MidiDeviceModel;
78  import org.jsampler.MidiInstrumentMap;  import org.jsampler.MidiInstrumentMap;
79  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
# Line 90  import org.jsampler.event.SamplerListene Line 97  import org.jsampler.event.SamplerListene
97  import org.jsampler.view.std.JSChannelOutputRoutingDlg;  import org.jsampler.view.std.JSChannelOutputRoutingDlg;
98  import org.jsampler.view.std.JSFxSendsPane;  import org.jsampler.view.std.JSFxSendsPane;
99  import org.jsampler.view.std.JSInstrumentChooser;  import org.jsampler.view.std.JSInstrumentChooser;
100    import org.jsampler.view.std.JSVolumeEditorPopup;
 import org.jvnet.lafwidget.animation.FadeConfigurationManager;  
 import org.jvnet.lafwidget.animation.FadeKind;  
101    
102  import org.jvnet.substance.SubstanceImageCreator;  import org.jvnet.substance.SubstanceImageCreator;
 import org.jvnet.substance.SubstanceLookAndFeel;  
103    
104  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
105  import org.linuxsampler.lscp.MidiInputDevice;  import org.linuxsampler.lscp.MidiInputDevice;
# Line 105  import org.linuxsampler.lscp.SamplerEngi Line 109  import org.linuxsampler.lscp.SamplerEngi
109    
110  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
111  import static org.jsampler.view.fantasia.FantasiaPrefs.*;  import static org.jsampler.view.fantasia.FantasiaPrefs.*;
112    import static org.jsampler.view.fantasia.FantasiaUtils.*;
113    import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType;
114    
115    
116  /**  /**
# Line 248  public class Channel extends org.jsample Line 254  public class Channel extends org.jsample
254                                    
255                  setOpaque(false);                  setOpaque(false);
256                                    
257                    String vmud = VOL_MEASUREMENT_UNIT_DECIBEL;
258                    preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() {
259                            public void
260                            propertyChange(PropertyChangeEvent e) {
261                                    boolean b;
262                                    b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL);
263                                    screen.updateVolumeInfo(dialVolume.getValue());
264                            }
265                    });
266                    
267                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
268                                    
269                  updateChannelInfo();                  updateChannelInfo();
# Line 260  public class Channel extends org.jsample Line 276  public class Channel extends org.jsample
276                                  public void                                  public void
277                                  propertyChange(PropertyChangeEvent e) {                                  propertyChange(PropertyChangeEvent e) {
278                                          if(e.getNewValue() == "expanded") {                                          if(e.getNewValue() == "expanded") {
279                                                    // TODO: this should be done regardles the listener != null?
280                                                  mainPane.removePropertyChangeListener(s, this);                                                  mainPane.removePropertyChangeListener(s, this);
281                                                    ///////
282                                                  listener.actionPerformed(null);                                                  listener.actionPerformed(null);
283                                                    ensureChannelIsVisible();
284                                            } else if(e.getNewValue() == "expanding/collapsing") {
285                                                    ensureChannelIsVisible();
286                                          }                                          }
287                                  }                                  }
288                          });                          });
# Line 289  public class Channel extends org.jsample Line 310  public class Channel extends org.jsample
310                  CC.getSamplerModel().addSamplerChannelListListener(getHandler());                  CC.getSamplerModel().addSamplerChannelListListener(getHandler());
311          }          }
312                    
313            private void
314            ensureChannelIsVisible() {
315                    Container p = getParent();
316                    JScrollPane sp = null;
317                    while(p != null) {
318                            if(p instanceof JScrollPane) {
319                                    sp = (JScrollPane)p;
320                                    break;
321                            }
322                            p = p.getParent();
323                    }
324                    if(sp == null) return;
325                    int h = sp.getViewport().getView().getHeight();
326                    sp.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
327            }
328            
329          private JPanel          private JPanel
330          createVSeparator() {          createVSeparator() {
331                  PixmapPane p = new PixmapPane(Res.gfxVLine);                  PixmapPane p = new PixmapPane(Res.gfxVLine);
# Line 344  public class Channel extends org.jsample Line 381  public class Channel extends org.jsample
381                                    
382                  if(vol == dialVolume.getValue()) return;                  if(vol == dialVolume.getValue()) return;
383                                    
                   
384                  /*                  /*
385                   * If the model's volume is not equal to the dial knob                   * If the model's volume is not equal to the dial knob
386                   * value we assume that the change is due to user input.                   * value we assume that the change is due to user input.
# Line 368  public class Channel extends org.jsample Line 404  public class Channel extends org.jsample
404                                    
405                  if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn);                  if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn);
406                  else btnSolo.setIcon(Res.gfxSoloOff);                  else btnSolo.setIcon(Res.gfxSoloOff);
                   
407                  dialVolume.setValue((int)(sc.getVolume() * 100));                  dialVolume.setValue((int)(sc.getVolume() * 100));
408                                    
409                  boolean b = sc.getEngine() != null;                  boolean b = sc.getEngine() != null;
# Line 392  public class Channel extends org.jsample Line 427  public class Channel extends org.jsample
427                    
428          private class EnhancedDial extends Dial {          private class EnhancedDial extends Dial {
429                  EnhancedDial() {                  EnhancedDial() {
430                          super(0, 100);                          super(0, 100, 0);
431                                                    
432                          setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP);                          setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP);
433                                                    
434                            int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
435                            setMaximum(i);
436                            String mcv = MAXIMUM_CHANNEL_VOLUME;
437                            preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() {
438                                    public void
439                                    propertyChange(PropertyChangeEvent e) {
440                                            int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
441                                            setMaximum(j);
442                                    }
443                            });
444                            
445                          addMouseListener(new MouseAdapter() {                          addMouseListener(new MouseAdapter() {
446                                  public void                                  public void
447                                  mouseClicked(MouseEvent e) {                                  mouseClicked(MouseEvent e) {
# Line 625  class ChannelScreen extends PixmapPane { Line 671  class ChannelScreen extends PixmapPane {
671          private final Channel channel;          private final Channel channel;
672                    
673          private final InstrumentPane instrumentPane;          private final InstrumentPane instrumentPane;
674          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));          
675            private JButton btnInstr =
676                    createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
677                    
678          private final JButton btnEditInstr =          private final JButton btnEditInstr =
679                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));                  createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
680          private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);          private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
681                    
682          private final JButton btnFxSends =          private final JButton btnFxSends =
683                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));                  createScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
684                    
685          private final JButton btnEngine          private final JButton btnEngine
686                  = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine"));                  = createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine"));
687                    
688          private final JPopupMenu menuEngines = new JPopupMenu();          private final JPopupMenu menuEngines = new JPopupMenu();
689                    
690          private final JLabel lVolume = new Label();          private final JButton btnVolume = createScreenButton("");
691          private final JLabel lStreams = new Label("--");          private JSVolumeEditorPopup popupVolume;
         private final JLabel lVoices = new Label("--");  
692                    
693          private InformationDialog fxSendsDlg = null;          private final JLabel lStreams = createScreenLabel(" --");
694            private final JLabel lVoices = createScreenLabel("-- ");
695                    
696          private Dimension dimVolume;          private InformationDialog fxSendsDlg = null;
697                    
698          private Timer timer;          private Timer timer;
699                    
700          class Label extends JLabel {          private static NumberFormat numberFormat = NumberFormat.getInstance();
701                  Label() { this(""); }          static {
702                                    numberFormat.setMaximumFractionDigits(1);
                 Label(String s) {  
                         super(s);  
                         setFont(Res.fontScreen);  
                         setForeground(new java.awt.Color(0xFFA300));  
                 }  
703          }          }
704                    
705          ChannelScreen(final Channel channel) {          ChannelScreen(final Channel channel) {
# Line 665  class ChannelScreen extends PixmapPane { Line 708  class ChannelScreen extends PixmapPane {
708                  setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));                  setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
709                                    
710                  this.channel = channel;                  this.channel = channel;
711                    popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.CHANNEL);
712                                    
713                  setOpaque(false);                  setOpaque(false);
714                                    
# Line 680  class ChannelScreen extends PixmapPane { Line 724  class ChannelScreen extends PixmapPane {
724                  JPanel p = new JPanel();                  JPanel p = new JPanel();
725                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
726                  p.setAlignmentX(CENTER_ALIGNMENT);                  p.setAlignmentX(CENTER_ALIGNMENT);
727                  p.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));                  p.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 0));
728                                    
729                  btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt"));                  btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt"));
730                  btnFxSends.addActionListener(new ActionListener() {                  btnFxSends.addActionListener(new ActionListener() {
# Line 702  class ChannelScreen extends PixmapPane { Line 746  class ChannelScreen extends PixmapPane {
746                                    
747                  p.add(btnFxSends);                  p.add(btnFxSends);
748                                    
749                  p.add(Box.createRigidArea(new Dimension(6, 0)));                  //p.add(Box.createRigidArea(new Dimension(6, 0)));
750                    p.add(Box.createGlue());
751                                    
752                  btnEngine.setIcon(Res.iconEngine12);                  btnEngine.setIcon(Res.iconEngine12);
753                    btnEngine.setIconTextGap(1);
754                  p.add(btnEngine);                  p.add(btnEngine);
755                  //p.add(new Label("|"));                  //p.add(new Label("|"));
756                                    
# Line 714  class ChannelScreen extends PixmapPane { Line 760  class ChannelScreen extends PixmapPane {
760                                    
761                  p.add(Box.createGlue());                  p.add(Box.createGlue());
762                                    
763                    lStreams.setFont(Res.fontScreenMono);
764                    lStreams.setHorizontalAlignment(JLabel.RIGHT);
765                    lStreams.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount"));
766                  p.add(lStreams);                  p.add(lStreams);
                 p.add(new Label("/"));  
                 p.add(lVoices);  
767                                    
768                  p.add(Box.createRigidArea(new Dimension(12, 0)));                  JLabel l = createScreenLabel("/");
769                    l.setFont(Res.fontScreenMono);
770                    l.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount"));
771                    p.add(l);
772                    
773                    lVoices.setFont(Res.fontScreenMono);
774                    lVoices.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount"));
775                    p.add(lVoices);
776                                    
777                  lVolume.setIcon(Res.iconVolume14);                  btnVolume.setIcon(Res.iconVolume14);
778                  lVolume.setAlignmentX(RIGHT_ALIGNMENT);                  btnVolume.setIconTextGap(2);
779                    btnVolume.setAlignmentX(RIGHT_ALIGNMENT);
780                    btnVolume.setHorizontalAlignment(btnVolume.LEFT);
781                  updateVolumeInfo(100);                  updateVolumeInfo(100);
782                  dimVolume = lVolume.getPreferredSize();                  Dimension d = btnVolume.getPreferredSize();
783                  p.add(lVolume);                  d.width = 60;
784                  p.setPreferredSize(new Dimension(250, p.getPreferredSize().height));                  btnVolume.setPreferredSize(d);
785                    btnVolume.setMinimumSize(d);
786                    
787                    btnVolume.addActionListener(new ActionListener() {
788                            public void
789                            actionPerformed(ActionEvent e) {
790                                    if(popupVolume.isVisible()) {
791                                            popupVolume.commit();
792                                            popupVolume.hide();
793                                    } else {
794                                            float vol = channel.getModel().getChannelInfo().getVolume();
795                                            popupVolume.setCurrentVolume(vol);
796                                            popupVolume.show();
797                                    }
798                            }
799                    });
800                    
801                    popupVolume.addActionListener(new ActionListener() {
802                            public void
803                            actionPerformed(ActionEvent e) {
804                                    channel.getModel().setBackendVolume(popupVolume.getVolumeFactor());
805                            }
806                    });
807                    
808                    p.add(btnVolume);
809                    p.setPreferredSize(new Dimension(260, p.getPreferredSize().height));
810                  p.setMinimumSize(p.getPreferredSize());                  p.setMinimumSize(p.getPreferredSize());
811                  p.setMaximumSize(p.getPreferredSize());                  p.setMaximumSize(p.getPreferredSize());
812                                    
# Line 748  class ChannelScreen extends PixmapPane { Line 829  class ChannelScreen extends PixmapPane {
829          private void          private void
830          createEngineMenu() {          createEngineMenu() {
831                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
832                          JMenuItem mi = new JMenuItem(engine.getDescription());                          JMenuItem mi = new JMenuItem(engine.getName() + " engine");
833                            mi.setToolTipText(engine.getDescription());
834                                                    
835                          mi.addActionListener(new ActionListener() {                          mi.addActionListener(new ActionListener() {
836                                  public void                                  public void
# Line 802  class ChannelScreen extends PixmapPane { Line 884  class ChannelScreen extends PixmapPane {
884                    
885          private void          private void
886          loadInstrument() {          loadInstrument() {
887                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
888                  dlg.setVisible(true);                  dlg.setVisible(true);
889                                    
890                  if(!dlg.isCancelled()) {                  if(!dlg.isCancelled()) {
# Line 828  class ChannelScreen extends PixmapPane { Line 910  class ChannelScreen extends PixmapPane {
910                  instrumentPane.update();                  instrumentPane.update();
911                    
912                  if(sc.getEngine() != null) {                  if(sc.getEngine() != null) {
913                          String s = sc.getEngine().getDescription();                          String s = sc.getEngine().getName();
914                          if(!s.equals(btnEngine.getText())) btnEngine.setText(s);                          s += " engine";
915                            if(!s.equals(btnEngine.getText())) {
916                                    btnEngine.setText(s);
917                                    btnEngine.setToolTipText(sc.getEngine().getDescription());
918                            }
919                  }                  }
920                                    
921          }          }
922                    
923          protected void          protected void
924          updateVolumeInfo(int volume) {          updateVolumeInfo(int volume) {
925                  lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume));                  if(CC.getViewConfig().isMeasurementUnitDecibel()) {
926                  lVolume.setMinimumSize(dimVolume);                          String s = numberFormat.format(HF.percentsToDecibels(volume));
927                  lVolume.setPreferredSize(dimVolume);                          btnVolume.setText(s + "dB");
928                                    } else {
929                            btnVolume.setText(String.valueOf(volume) + "%");
930                    }
931          }          }
932                    
933          /**          /**
# Line 946  class ChannelScreen extends PixmapPane { Line 1034  class ChannelScreen extends PixmapPane {
1034                  }                  }
1035          }          }
1036                    
         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));  
                           
                         putClientProperty (  
                                 SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE  
                         );  
                           
                         putClientProperty (  
                                 SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE  
                         );  
                           
                         putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE);  
                           
                         FadeConfigurationManager.getInstance().disallowFades(FadeKind.ROLLOVER, this);  
                           
                         setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));  
                         setFont(Res.fontScreen);  
                         setForeground(new java.awt.Color(0xFFA300));  
                 }  
         }  
           
1037          static class ScreenButtonBg extends PixmapPane {          static class ScreenButtonBg extends PixmapPane {
1038                  ScreenButtonBg(JButton btn) {                  ScreenButtonBg(JButton btn) {
1039                          super(Res.gfxScreenBtnBg);                          super(Res.gfxScreenBtnBg);
# Line 988  class ChannelScreen extends PixmapPane { Line 1050  class ChannelScreen extends PixmapPane {
1050                  }                  }
1051          }          }
1052                    
1053            
1054          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
1055                    
1056          private EventHandler          private EventHandler
# Line 996  class ChannelScreen extends PixmapPane { Line 1059  class ChannelScreen extends PixmapPane {
1059          private class EventHandler extends MouseAdapter implements HierarchyListener {          private class EventHandler extends MouseAdapter implements HierarchyListener {
1060                  public void                  public void
1061                  mouseEntered(MouseEvent e)  {                  mouseEntered(MouseEvent e)  {
1062                            if(channel.getChannelInfo().getInstrumentStatus() != 100) return;
1063                            
1064                          if(!sbbEditInstr.isVisible()) {                          if(!sbbEditInstr.isVisible()) {
1065                                  sbbEditInstr.setVisible(true);                                  sbbEditInstr.setVisible(true);
1066                                  instrumentPane.update();                                  instrumentPane.update();

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

  ViewVC Help
Powered by ViewVC