/[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 1340 by iliev, Sat Sep 1 13:46:04 2007 UTC revision 1341 by iliev, Mon Sep 10 22:29:09 2007 UTC
# Line 29  import java.awt.Insets; Line 29  import java.awt.Insets;
29    
30  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
31  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
32    import java.awt.event.HierarchyEvent;
33    import java.awt.event.HierarchyListener;
34  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
35  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
36    
# Line 51  import javax.swing.JPopupMenu; Line 53  import javax.swing.JPopupMenu;
53  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
54  import javax.swing.JToolBar;  import javax.swing.JToolBar;
55  import javax.swing.SwingConstants;  import javax.swing.SwingConstants;
56    import javax.swing.Timer;
57    
58  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
59  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
# Line 282  public class Channel extends org.jsample Line 285  public class Channel extends org.jsample
285                                  run() { listener.actionPerformed(null); }                                  run() { listener.actionPerformed(null); }
286                          });                          });
287                  }                  }
288                    
289                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
290          }          }
291                    
292          private JPanel          private JPanel
# Line 413  public class Channel extends org.jsample Line 418  public class Channel extends org.jsample
418                  }                  }
419          }          }
420                    
421            protected void
422            onDestroy() {
423                    CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
424                    
425                    screen.onDestroy();
426                    optionsPane.onDestroy();
427            }
428            
429          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
430                    
431          private EventHandler          private EventHandler
432          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
433                    
434          private class EventHandler implements SamplerChannelListener {          private class EventHandler implements SamplerChannelListener, SamplerChannelListListener {
435                  /**                  /**
436                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
437                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 446  public class Channel extends org.jsample Line 459  public class Channel extends org.jsample
459                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
460                          screen.updateVoiceCount(getModel().getVoiceCount());                          screen.updateVoiceCount(getModel().getVoiceCount());
461                  }                  }
462                    
463                    /**
464                     * Invoked when a new sampler channel is created.
465                     * @param e A <code>SamplerChannelListEvent</code>
466                     * instance providing the event information.
467                     */
468                    public void
469                    channelAdded(SamplerChannelListEvent e) { }
470            
471                    /**
472                     * Invoked when a sampler channel is removed.
473                     * @param e A <code>SamplerChannelListEvent</code>
474                     * instance providing the event information.
475                     */
476                    public void
477                    channelRemoved(SamplerChannelListEvent e) {
478                            // Some cleanup when the channel is removed.
479                            if(e.getChannelModel().getChannelId() == getChannelId()) {
480                                    onDestroy();
481                            }
482                    }
483          }          }
484                    
485                    
# Line 589  class ChannelPane extends PixmapPane { Line 623  class ChannelPane extends PixmapPane {
623    
624  class ChannelScreen extends PixmapPane {  class ChannelScreen extends PixmapPane {
625          private final Channel channel;          private final Channel channel;
626            
627            private final InstrumentPane instrumentPane;
628          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
629                    
630            private final JButton btnEditInstr =
631                    new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
632            private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
633            
634          private final JButton btnFxSends =          private final JButton btnFxSends =
635                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
636                    
# Line 607  class ChannelScreen extends PixmapPane { Line 647  class ChannelScreen extends PixmapPane {
647                    
648          private Dimension dimVolume;          private Dimension dimVolume;
649                    
650            private Timer timer;
651            
652          class Label extends JLabel {          class Label extends JLabel {
653                  Label() { this(""); }                  Label() { this(""); }
654                                    
# Line 632  class ChannelScreen extends PixmapPane { Line 674  class ChannelScreen extends PixmapPane {
674                  btnInstr.setRolloverEnabled(false);                  btnInstr.setRolloverEnabled(false);
675                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
676                                    
677                  add(btnInstr);                  instrumentPane = new InstrumentPane();
678                    add(instrumentPane);
679                                    
680                  JPanel p = new JPanel();                  JPanel p = new JPanel();
681                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
# Line 699  class ChannelScreen extends PixmapPane { Line 742  class ChannelScreen extends PixmapPane {
742                  installListeners();                  installListeners();
743          }          }
744                    
745            protected void
746            onDestroy() { timer.stop(); }
747            
748          private void          private void
749          createEngineMenu() {          createEngineMenu() {
750                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
# Line 722  class ChannelScreen extends PixmapPane { Line 768  class ChannelScreen extends PixmapPane {
768                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) { loadInstrument(); }
769                  });                  });
770                                    
771                    btnEditInstr.addActionListener(new ActionListener() {
772                            public void
773                            actionPerformed(ActionEvent e) {
774                                    CC.getSamplerModel().editBackendInstrument(channel.getChannelId());
775                            }
776                    });
777                    
778                  btnEngine.addActionListener(new ActionListener() {                  btnEngine.addActionListener(new ActionListener() {
779                          public void                          public void
780                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
# Line 729  class ChannelScreen extends PixmapPane { Line 782  class ChannelScreen extends PixmapPane {
782                                  menuEngines.show(btnEngine, 0, y);                                  menuEngines.show(btnEngine, 0, y);
783                          }                          }
784                  });                  });
785                    
786                    addMouseListener(getHandler());
787                    addHierarchyListener(getHandler());
788                    
789                    ActionListener l = new ActionListener() {
790                            public void
791                            actionPerformed(ActionEvent e) {
792                                    if(getMousePosition(true) != null) {
793                                            getHandler().mouseEntered(null);
794                                    } else {
795                                            getHandler().mouseExited(null);
796                                    }
797                            }
798                    };
799                    timer = new Timer(1000, l);
800                    timer.start();
801          }          }
802                    
803          private void          private void
# Line 755  class ChannelScreen extends PixmapPane { Line 824  class ChannelScreen extends PixmapPane {
824                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
825                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
826                  }                  }
827                    
828                    instrumentPane.update();
829                    
830                  if(sc.getEngine() != null) {                  if(sc.getEngine() != null) {
831                          String s = sc.getEngine().getDescription();                          String s = sc.getEngine().getDescription();
# Line 799  class ChannelScreen extends PixmapPane { Line 870  class ChannelScreen extends PixmapPane {
870                  lVoices.setMaximumSize(d);                  lVoices.setMaximumSize(d);
871          }          }
872                    
873            class InstrumentPane extends JPanel {
874                    private final JPanel leftPane = new JPanel();
875                    private final JPanel rightPane = new JPanel();
876                    
877                    InstrumentPane() {
878                            setOpaque(false);
879                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
880                            add(leftPane);
881                            add(btnInstr);
882                            add(rightPane);
883                            add(sbbEditInstr);
884                            sbbEditInstr.setVisible(false);
885                            setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
886                            
887                            update();
888                    }
889                    
890                    public void
891                    update() {
892                            int a = btnInstr.getMinimumSize().width;
893                            int b = 0;
894                            if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width;
895                            
896                            int max = 254 - b;
897                            if(a > max) a = max;
898                            
899                            int h = btnInstr.getPreferredSize().height;
900                            btnInstr.setPreferredSize(new Dimension(a, h));
901                            h = btnInstr.getMaximumSize().height;
902                            btnInstr.setMaximumSize(new Dimension(a, h));
903                            
904                            
905                            int i = (254 - btnInstr.getPreferredSize().width) / 2;
906                            
907                            int j = i;
908                            if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width;
909                            if(i < 0 || j < 0) i = j = 0;
910                            
911                            Dimension d = new Dimension(i, 1);
912                            leftPane.setMinimumSize(d);
913                            leftPane.setPreferredSize(d);
914                            leftPane.setMaximumSize(d);
915                            
916                            d = new Dimension(j, 1);
917                            rightPane.setMinimumSize(d);
918                            rightPane.setPreferredSize(d);
919                            rightPane.setMaximumSize(d);
920                            
921                            validate();
922                    }
923            }
924            
925          class FxSendsPane extends JSFxSendsPane {          class FxSendsPane extends JSFxSendsPane {
926                  FxSendsPane(SamplerChannelModel model) {                  FxSendsPane(SamplerChannelModel model) {
927                          super(model);                          super(model);
# Line 847  class ChannelScreen extends PixmapPane { Line 970  class ChannelScreen extends PixmapPane {
970                          setForeground(new java.awt.Color(0xFFA300));                          setForeground(new java.awt.Color(0xFFA300));
971                  }                  }
972          }          }
973            
974            static class ScreenButtonBg extends PixmapPane {
975                    ScreenButtonBg(JButton btn) {
976                            super(Res.gfxScreenBtnBg);
977                            setPixmapInsets(new Insets(4, 4, 4, 4));
978                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
979                            setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
980                            add(btn);
981                            setPreferredSize(new Dimension(getPreferredSize().width, 13));
982                    }
983                    
984                    public Dimension
985                    getPreferredSize() {
986                            return new Dimension(super.getPreferredSize().width, 13);
987                    }
988            }
989            
990            private final EventHandler eventHandler = new EventHandler();
991            
992            private EventHandler
993            getHandler() { return eventHandler; }
994            
995            private class EventHandler extends MouseAdapter implements HierarchyListener {
996                    public void
997                    mouseEntered(MouseEvent e)  {
998                            if(!sbbEditInstr.isVisible()) {
999                                    sbbEditInstr.setVisible(true);
1000                                    instrumentPane.update();
1001                            }
1002                    }
1003                    
1004                    public void
1005                    mouseExited(MouseEvent e)  {
1006                            if(getMousePosition(true) != null) return;
1007                            if(sbbEditInstr.isVisible()) {
1008                                    sbbEditInstr.setVisible(false);
1009                                    instrumentPane.update();
1010                            }
1011                    }
1012                    
1013                    /** Called when the hierarchy has been changed. */
1014                    public void
1015                    hierarchyChanged(HierarchyEvent e) {
1016                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
1017                                    if(getMousePosition() == null) mouseExited(null);
1018                                    else mouseEntered(null);
1019                            }
1020                    }
1021            }
1022  }  }
1023    
1024  class ChannelOptions extends JXCollapsiblePane {  class ChannelOptions extends JXCollapsiblePane {
# Line 1080  class ChannelOptions extends JXCollapsib Line 1252  class ChannelOptions extends JXCollapsib
1252                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1253                  });                  });
1254                                    
                 CC.getSamplerModel().addSamplerChannelListListener(getHandler());  
1255                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1256                                    
1257                  cbAudioDevice.addActionListener(new ActionListener() {                  cbAudioDevice.addActionListener(new ActionListener() {
# Line 1314  class ChannelOptions extends JXCollapsib Line 1485  class ChannelOptions extends JXCollapsib
1485          private void          private void
1486          setUpdate(boolean b) { update = b; }          setUpdate(boolean b) { update = b; }
1487                    
1488            protected void
1489            onDestroy() {
1490                    SamplerModel sm = CC.getSamplerModel();
1491                    
1492                    sm.removeMidiDeviceListListener(getHandler());
1493                    sm.removeAudioDeviceListListener(getHandler());
1494                    sm.removeMidiInstrumentMapListListener(mapListListener);
1495                    sm.removeSamplerListener(samplerListener);
1496                    
1497                    if(midiDevice != null) {
1498                            midiDevice.removeMidiDeviceListener(getHandler());
1499                    }
1500            }
1501            
1502          private final Handler handler = new Handler();          private final Handler handler = new Handler();
1503                    
1504          private Handler          private Handler
1505          getHandler() { return handler; }          getHandler() { return handler; }
1506                    
1507          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1508                                          SamplerChannelListListener, MidiDeviceListener {                                          MidiDeviceListener {
1509                  /**                  /**
1510                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1511                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 1361  class ChannelOptions extends JXCollapsib Line 1546  class ChannelOptions extends JXCollapsib
1546                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1547                  }                  }
1548                                    
                 /**  
                  * 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());  
                                 }  
                         }  
                 }  
                   
1549                  public void                  public void
1550                  settingsChanged(MidiDeviceEvent e) {                  settingsChanged(MidiDeviceEvent e) {
1551                          if(isUpdate()) {                          if(isUpdate()) {

Legend:
Removed from v.1340  
changed lines
  Added in v.1341

  ViewVC Help
Powered by ViewVC