/[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 1318 by iliev, Sat Sep 1 13:46:04 2007 UTC revision 1496 by iliev, Mon Nov 19 22:22:22 2007 UTC
# Line 22  Line 22 
22    
23  package org.jsampler.view.fantasia;  package org.jsampler.view.fantasia;
24    
25    import java.awt.Container;
26  import java.awt.Cursor;  import java.awt.Cursor;
27  import java.awt.Dimension;  import java.awt.Dimension;
28  import java.awt.Graphics;  import java.awt.Graphics;
29    import java.awt.Graphics2D;
30  import java.awt.Insets;  import java.awt.Insets;
31    import java.awt.Rectangle;
32    
33  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
34  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
35    import java.awt.event.HierarchyEvent;
36    import java.awt.event.HierarchyListener;
37  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
38  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
39    
# Line 48  import javax.swing.JLabel; Line 53  import javax.swing.JLabel;
53  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
54  import javax.swing.JPanel;  import javax.swing.JPanel;
55  import javax.swing.JPopupMenu;  import javax.swing.JPopupMenu;
56    import javax.swing.JScrollPane;
57  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
58  import javax.swing.JToolBar;  import javax.swing.JToolBar;
59  import javax.swing.SwingConstants;  import javax.swing.SwingConstants;
60    import javax.swing.Timer;
61    
62  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
63  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
# Line 245  public class Channel extends org.jsample Line 252  public class Channel extends org.jsample
252                                    
253                  setOpaque(false);                  setOpaque(false);
254                                    
255                    int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
256                    dialVolume.setMaximum(i);
257                    String mcv = MAXIMUM_CHANNEL_VOLUME;
258                    preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() {
259                            public void
260                            propertyChange(PropertyChangeEvent e) {
261                                    int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
262                                    dialVolume.setMaximum(j);
263                            }
264                    });
265                    
266                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
267                                    
268                  updateChannelInfo();                  updateChannelInfo();
# Line 257  public class Channel extends org.jsample Line 275  public class Channel extends org.jsample
275                                  public void                                  public void
276                                  propertyChange(PropertyChangeEvent e) {                                  propertyChange(PropertyChangeEvent e) {
277                                          if(e.getNewValue() == "expanded") {                                          if(e.getNewValue() == "expanded") {
278                                                    // TODO: this should be done regardles the listener != null?
279                                                  mainPane.removePropertyChangeListener(s, this);                                                  mainPane.removePropertyChangeListener(s, this);
280                                                    ///////
281                                                  listener.actionPerformed(null);                                                  listener.actionPerformed(null);
282                                                    ensureChannelIsVisible();
283                                            } else if(e.getNewValue() == "expanding/collapsing") {
284                                                    ensureChannelIsVisible();
285                                          }                                          }
286                                  }                                  }
287                          });                          });
# Line 282  public class Channel extends org.jsample Line 305  public class Channel extends org.jsample
305                                  run() { listener.actionPerformed(null); }                                  run() { listener.actionPerformed(null); }
306                          });                          });
307                  }                  }
308                    
309                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
310            }
311            
312            private void
313            ensureChannelIsVisible() {
314                    Container p = getParent();
315                    JScrollPane sp = null;
316                    while(p != null) {
317                            if(p instanceof JScrollPane) {
318                                    sp = (JScrollPane)p;
319                                    break;
320                            }
321                            p = p.getParent();
322                    }
323                    if(sp == null) return;
324                    int h = sp.getViewport().getView().getHeight();
325                    sp.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
326          }          }
327                    
328          private JPanel          private JPanel
# Line 413  public class Channel extends org.jsample Line 454  public class Channel extends org.jsample
454                  }                  }
455          }          }
456                    
457            protected void
458            onDestroy() {
459                    CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
460                    
461                    screen.onDestroy();
462                    optionsPane.onDestroy();
463            }
464            
465          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
466                    
467          private EventHandler          private EventHandler
468          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
469                    
470          private class EventHandler implements SamplerChannelListener {          private class EventHandler implements SamplerChannelListener, SamplerChannelListListener {
471                  /**                  /**
472                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
473                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 446  public class Channel extends org.jsample Line 495  public class Channel extends org.jsample
495                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
496                          screen.updateVoiceCount(getModel().getVoiceCount());                          screen.updateVoiceCount(getModel().getVoiceCount());
497                  }                  }
498                    
499                    /**
500                     * Invoked when a new sampler channel is created.
501                     * @param e A <code>SamplerChannelListEvent</code>
502                     * instance providing the event information.
503                     */
504                    public void
505                    channelAdded(SamplerChannelListEvent e) { }
506            
507                    /**
508                     * Invoked when a sampler channel is removed.
509                     * @param e A <code>SamplerChannelListEvent</code>
510                     * instance providing the event information.
511                     */
512                    public void
513                    channelRemoved(SamplerChannelListEvent e) {
514                            // Some cleanup when the channel is removed.
515                            if(e.getChannelModel().getChannelId() == getChannelId()) {
516                                    onDestroy();
517                            }
518                    }
519          }          }
520                    
521                    
# Line 589  class ChannelPane extends PixmapPane { Line 659  class ChannelPane extends PixmapPane {
659    
660  class ChannelScreen extends PixmapPane {  class ChannelScreen extends PixmapPane {
661          private final Channel channel;          private final Channel channel;
662            
663            private final InstrumentPane instrumentPane;
664          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
665                    
666            private final JButton btnEditInstr =
667                    new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
668            private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
669            
670          private final JButton btnFxSends =          private final JButton btnFxSends =
671                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
672                    
# Line 599  class ChannelScreen extends PixmapPane { Line 675  class ChannelScreen extends PixmapPane {
675                    
676          private final JPopupMenu menuEngines = new JPopupMenu();          private final JPopupMenu menuEngines = new JPopupMenu();
677                    
678          private final JLabel lVolume = new Label();          private final JLabel lVolume = new ScreenLabel("");
679          private final JLabel lStreams = new Label("--");          private final JLabel lStreams = new ScreenLabel(" --");
680          private final JLabel lVoices = new Label("--");          private final JLabel lVoices = new ScreenLabel("-- ");
681                    
682          private InformationDialog fxSendsDlg = null;          private InformationDialog fxSendsDlg = null;
683                    
684          private Dimension dimVolume;          private Dimension dimVolume;
685                    
686          class Label extends JLabel {          private Timer timer;
                 Label() { this(""); }  
                   
                 Label(String s) {  
                         super(s);  
                         setFont(Res.fontScreen);  
                         setForeground(new java.awt.Color(0xFFA300));  
                 }  
         }  
687                    
688          ChannelScreen(final Channel channel) {          ChannelScreen(final Channel channel) {
689                  super(Res.gfxChannelScreen);                  super(Res.gfxChannelScreen);
690                  setPixmapInsets(new Insets(6, 6, 6, 6));                  setPixmapInsets(new Insets(6, 6, 6, 6));
691                  setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));                  setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4));
692                                    
693                  this.channel = channel;                  this.channel = channel;
694                                    
# Line 632  class ChannelScreen extends PixmapPane { Line 700  class ChannelScreen extends PixmapPane {
700                  btnInstr.setRolloverEnabled(false);                  btnInstr.setRolloverEnabled(false);
701                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
702                                    
703                  add(btnInstr);                  instrumentPane = new InstrumentPane();
704                    add(instrumentPane);
705                                    
706                  JPanel p = new JPanel();                  JPanel p = new JPanel();
707                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
# Line 671  class ChannelScreen extends PixmapPane { Line 740  class ChannelScreen extends PixmapPane {
740                                    
741                  p.add(Box.createGlue());                  p.add(Box.createGlue());
742                                    
743                    lStreams.setFont(Res.fontScreenMono);
744                    lStreams.setHorizontalAlignment(JLabel.RIGHT);
745                  p.add(lStreams);                  p.add(lStreams);
                 p.add(new Label("/"));  
                 p.add(lVoices);  
746                                    
747                  p.add(Box.createRigidArea(new Dimension(12, 0)));                  JLabel l = new ScreenLabel("/");
748                    l.setFont(Res.fontScreenMono);
749                    p.add(l);
750                    
751                    lVoices.setFont(Res.fontScreenMono);
752                    p.add(lVoices);
753                                    
754                  lVolume.setIcon(Res.iconVolume14);                  lVolume.setIcon(Res.iconVolume14);
755                  lVolume.setAlignmentX(RIGHT_ALIGNMENT);                  lVolume.setAlignmentX(RIGHT_ALIGNMENT);
# Line 699  class ChannelScreen extends PixmapPane { Line 773  class ChannelScreen extends PixmapPane {
773                  installListeners();                  installListeners();
774          }          }
775                    
776            protected void
777            onDestroy() { timer.stop(); }
778            
779          private void          private void
780          createEngineMenu() {          createEngineMenu() {
781                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
# Line 722  class ChannelScreen extends PixmapPane { Line 799  class ChannelScreen extends PixmapPane {
799                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) { loadInstrument(); }
800                  });                  });
801                                    
802                    btnEditInstr.addActionListener(new ActionListener() {
803                            public void
804                            actionPerformed(ActionEvent e) {
805                                    CC.getSamplerModel().editBackendInstrument(channel.getChannelId());
806                            }
807                    });
808                    
809                  btnEngine.addActionListener(new ActionListener() {                  btnEngine.addActionListener(new ActionListener() {
810                          public void                          public void
811                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
# Line 729  class ChannelScreen extends PixmapPane { Line 813  class ChannelScreen extends PixmapPane {
813                                  menuEngines.show(btnEngine, 0, y);                                  menuEngines.show(btnEngine, 0, y);
814                          }                          }
815                  });                  });
816                    
817                    addMouseListener(getHandler());
818                    addHierarchyListener(getHandler());
819                    
820                    ActionListener l = new ActionListener() {
821                            public void
822                            actionPerformed(ActionEvent e) {
823                                    if(getMousePosition(true) != null) {
824                                            getHandler().mouseEntered(null);
825                                    } else {
826                                            getHandler().mouseExited(null);
827                                    }
828                            }
829                    };
830                    timer = new Timer(1000, l);
831                    timer.start();
832          }          }
833                    
834          private void          private void
835          loadInstrument() {          loadInstrument() {
836                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
837                  dlg.setVisible(true);                  dlg.setVisible(true);
838                                    
839                  if(!dlg.isCancelled()) {                  if(!dlg.isCancelled()) {
# Line 755  class ChannelScreen extends PixmapPane { Line 855  class ChannelScreen extends PixmapPane {
855                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
856                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
857                  }                  }
858                    
859                    instrumentPane.update();
860                    
861                  if(sc.getEngine() != null) {                  if(sc.getEngine() != null) {
862                          String s = sc.getEngine().getDescription();                          String s = sc.getEngine().getDescription();
# Line 799  class ChannelScreen extends PixmapPane { Line 901  class ChannelScreen extends PixmapPane {
901                  lVoices.setMaximumSize(d);                  lVoices.setMaximumSize(d);
902          }          }
903                    
904            class InstrumentPane extends JPanel {
905                    private final JPanel leftPane = new JPanel();
906                    private final JPanel rightPane = new JPanel();
907                    
908                    InstrumentPane() {
909                            setOpaque(false);
910                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
911                            add(leftPane);
912                            add(btnInstr);
913                            add(rightPane);
914                            add(sbbEditInstr);
915                            btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt"));
916                            sbbEditInstr.setVisible(false);
917                            setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
918                            
919                            update();
920                    }
921                    
922                    public void
923                    update() {
924                            int a = btnInstr.getMinimumSize().width;
925                            int b = 0;
926                            if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width;
927                            
928                            int max = 254 - b;
929                            if(a > max) a = max;
930                            
931                            int h = btnInstr.getPreferredSize().height;
932                            btnInstr.setPreferredSize(new Dimension(a, h));
933                            h = btnInstr.getMaximumSize().height;
934                            btnInstr.setMaximumSize(new Dimension(a, h));
935                            
936                            
937                            int i = (254 - btnInstr.getPreferredSize().width) / 2;
938                            
939                            int j = i;
940                            if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width;
941                            if(i < 0 || j < 0) i = j = 0;
942                            
943                            Dimension d = new Dimension(i, 1);
944                            leftPane.setMinimumSize(d);
945                            leftPane.setPreferredSize(d);
946                            leftPane.setMaximumSize(d);
947                            
948                            d = new Dimension(j, 1);
949                            rightPane.setMinimumSize(d);
950                            rightPane.setPreferredSize(d);
951                            rightPane.setMaximumSize(d);
952                            
953                            validate();
954                    }
955            }
956            
957          class FxSendsPane extends JSFxSendsPane {          class FxSendsPane extends JSFxSendsPane {
958                  FxSendsPane(SamplerChannelModel model) {                  FxSendsPane(SamplerChannelModel model) {
959                          super(model);                          super(model);
# Line 846  class ChannelScreen extends PixmapPane { Line 1001  class ChannelScreen extends PixmapPane {
1001                          setFont(Res.fontScreen);                          setFont(Res.fontScreen);
1002                          setForeground(new java.awt.Color(0xFFA300));                          setForeground(new java.awt.Color(0xFFA300));
1003                  }                  }
1004                    
1005                    protected void
1006                    paintComponent(Graphics g) {
1007                            Graphics2D g2d = (Graphics2D)g;
1008                            
1009                            g2d.setRenderingHint (
1010                                    java.awt.RenderingHints.KEY_TEXT_ANTIALIASING,
1011                                    java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON
1012                            );
1013                            
1014                            super.paintComponent(g2d);
1015                    }
1016            }
1017            
1018            static class ScreenButtonBg extends PixmapPane {
1019                    ScreenButtonBg(JButton btn) {
1020                            super(Res.gfxScreenBtnBg);
1021                            setPixmapInsets(new Insets(4, 4, 4, 4));
1022                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
1023                            setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
1024                            add(btn);
1025                            setPreferredSize(new Dimension(getPreferredSize().width, 13));
1026                    }
1027                    
1028                    public Dimension
1029                    getPreferredSize() {
1030                            return new Dimension(super.getPreferredSize().width, 13);
1031                    }
1032            }
1033            
1034            
1035            
1036            static class ScreenLabel extends JLabel {
1037                    ScreenLabel() { this(""); }
1038                    
1039                    ScreenLabel(String s) {
1040                            super(s);
1041                            setFont(Res.fontScreen);
1042                            setForeground(new java.awt.Color(0xFFA300));
1043                    }
1044                    
1045                    protected void
1046                    paintComponent(Graphics g) {
1047                            Graphics2D g2d = (Graphics2D)g;
1048                            
1049                            g2d.setRenderingHint (
1050                                    java.awt.RenderingHints.KEY_TEXT_ANTIALIASING,
1051                                    java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON
1052                            );
1053                            
1054                            super.paintComponent(g2d);
1055                    }
1056            }
1057            
1058            private final EventHandler eventHandler = new EventHandler();
1059            
1060            private EventHandler
1061            getHandler() { return eventHandler; }
1062            
1063            private class EventHandler extends MouseAdapter implements HierarchyListener {
1064                    public void
1065                    mouseEntered(MouseEvent e)  {
1066                            if(channel.getChannelInfo().getInstrumentStatus() != 100) return;
1067                            
1068                            if(!sbbEditInstr.isVisible()) {
1069                                    sbbEditInstr.setVisible(true);
1070                                    instrumentPane.update();
1071                            }
1072                    }
1073                    
1074                    public void
1075                    mouseExited(MouseEvent e)  {
1076                            if(getMousePosition(true) != null) return;
1077                            if(sbbEditInstr.isVisible()) {
1078                                    sbbEditInstr.setVisible(false);
1079                                    instrumentPane.update();
1080                            }
1081                    }
1082                    
1083                    /** Called when the hierarchy has been changed. */
1084                    public void
1085                    hierarchyChanged(HierarchyEvent e) {
1086                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
1087                                    if(getMousePosition() == null) mouseExited(null);
1088                                    else mouseEntered(null);
1089                            }
1090                    }
1091          }          }
1092  }  }
1093    
# Line 1080  class ChannelOptions extends JXCollapsib Line 1322  class ChannelOptions extends JXCollapsib
1322                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1323                  });                  });
1324                                    
                 CC.getSamplerModel().addSamplerChannelListListener(getHandler());  
1325                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1326                                    
1327                  cbAudioDevice.addActionListener(new ActionListener() {                  cbAudioDevice.addActionListener(new ActionListener() {
# Line 1314  class ChannelOptions extends JXCollapsib Line 1555  class ChannelOptions extends JXCollapsib
1555          private void          private void
1556          setUpdate(boolean b) { update = b; }          setUpdate(boolean b) { update = b; }
1557                    
1558            protected void
1559            onDestroy() {
1560                    SamplerModel sm = CC.getSamplerModel();
1561                    
1562                    sm.removeMidiDeviceListListener(getHandler());
1563                    sm.removeAudioDeviceListListener(getHandler());
1564                    sm.removeMidiInstrumentMapListListener(mapListListener);
1565                    sm.removeSamplerListener(samplerListener);
1566                    
1567                    if(midiDevice != null) {
1568                            midiDevice.removeMidiDeviceListener(getHandler());
1569                    }
1570            }
1571            
1572          private final Handler handler = new Handler();          private final Handler handler = new Handler();
1573                    
1574          private Handler          private Handler
1575          getHandler() { return handler; }          getHandler() { return handler; }
1576                    
1577          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1578                                          SamplerChannelListListener, MidiDeviceListener {                                          MidiDeviceListener {
1579                  /**                  /**
1580                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1581                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 1361  class ChannelOptions extends JXCollapsib Line 1616  class ChannelOptions extends JXCollapsib
1616                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1617                  }                  }
1618                                    
                 /**  
                  * Invoked when a new sampler channel is created.  
                  * @param e A <code>SamplerChannelListEvent</code>  
                  * instance providing the event information.  
                  */  
                 public void  
                 channelAdded(SamplerChannelListEvent e) { }  
           
                 /**  
                  * Invoked when a sampler channel is removed.  
                  * @param e A <code>SamplerChannelListEvent</code>  
                  * instance providing the event information.  
                  */  
                 public void  
                 channelRemoved(SamplerChannelListEvent e) {  
                         // Some cleanup when the channel is removed.  
                         if(e.getChannelModel().getChannelId() == channel.getChannelId()) {  
                                 SamplerModel sm = CC.getSamplerModel();  
                                   
                                 sm.removeMidiDeviceListListener(getHandler());  
                                 sm.removeAudioDeviceListListener(getHandler());  
                                 sm.removeMidiInstrumentMapListListener(mapListListener);  
                                 sm.removeSamplerListener(samplerListener);  
                                 sm.removeSamplerChannelListListener(getHandler());  
                                   
                                 if(midiDevice != null) {  
                                         midiDevice.removeMidiDeviceListener(getHandler());  
                                 }  
                         }  
                 }  
                   
1619                  public void                  public void
1620                  settingsChanged(MidiDeviceEvent e) {                  settingsChanged(MidiDeviceEvent e) {
1621                          if(isUpdate()) {                          if(isUpdate()) {

Legend:
Removed from v.1318  
changed lines
  Added in v.1496

  ViewVC Help
Powered by ViewVC