/[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 1357 by iliev, Sat Sep 22 17:27:06 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 245  public class Channel extends org.jsample Line 248  public class Channel extends org.jsample
248                                    
249                  setOpaque(false);                  setOpaque(false);
250                                    
251                    int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
252                    dialVolume.setMaximum(i);
253                    String mcv = MAXIMUM_CHANNEL_VOLUME;
254                    preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() {
255                            public void
256                            propertyChange(PropertyChangeEvent e) {
257                                    int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
258                                    dialVolume.setMaximum(j);
259                            }
260                    });
261                    
262                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
263                                    
264                  updateChannelInfo();                  updateChannelInfo();
# Line 282  public class Channel extends org.jsample Line 296  public class Channel extends org.jsample
296                                  run() { listener.actionPerformed(null); }                                  run() { listener.actionPerformed(null); }
297                          });                          });
298                  }                  }
299                    
300                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
301          }          }
302                    
303          private JPanel          private JPanel
# Line 413  public class Channel extends org.jsample Line 429  public class Channel extends org.jsample
429                  }                  }
430          }          }
431                    
432            protected void
433            onDestroy() {
434                    CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
435                    
436                    screen.onDestroy();
437                    optionsPane.onDestroy();
438            }
439            
440          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
441                    
442          private EventHandler          private EventHandler
443          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
444                    
445          private class EventHandler implements SamplerChannelListener {          private class EventHandler implements SamplerChannelListener, SamplerChannelListListener {
446                  /**                  /**
447                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
448                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 446  public class Channel extends org.jsample Line 470  public class Channel extends org.jsample
470                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
471                          screen.updateVoiceCount(getModel().getVoiceCount());                          screen.updateVoiceCount(getModel().getVoiceCount());
472                  }                  }
473                    
474                    /**
475                     * Invoked when a new sampler channel is created.
476                     * @param e A <code>SamplerChannelListEvent</code>
477                     * instance providing the event information.
478                     */
479                    public void
480                    channelAdded(SamplerChannelListEvent e) { }
481            
482                    /**
483                     * Invoked when a sampler channel is removed.
484                     * @param e A <code>SamplerChannelListEvent</code>
485                     * instance providing the event information.
486                     */
487                    public void
488                    channelRemoved(SamplerChannelListEvent e) {
489                            // Some cleanup when the channel is removed.
490                            if(e.getChannelModel().getChannelId() == getChannelId()) {
491                                    onDestroy();
492                            }
493                    }
494          }          }
495                    
496                    
# Line 589  class ChannelPane extends PixmapPane { Line 634  class ChannelPane extends PixmapPane {
634    
635  class ChannelScreen extends PixmapPane {  class ChannelScreen extends PixmapPane {
636          private final Channel channel;          private final Channel channel;
637            
638            private final InstrumentPane instrumentPane;
639          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
640                    
641            private final JButton btnEditInstr =
642                    new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
643            private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
644            
645          private final JButton btnFxSends =          private final JButton btnFxSends =
646                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
647                    
# Line 607  class ChannelScreen extends PixmapPane { Line 658  class ChannelScreen extends PixmapPane {
658                    
659          private Dimension dimVolume;          private Dimension dimVolume;
660                    
661            private Timer timer;
662            
663          class Label extends JLabel {          class Label extends JLabel {
664                  Label() { this(""); }                  Label() { this(""); }
665                                    
# Line 632  class ChannelScreen extends PixmapPane { Line 685  class ChannelScreen extends PixmapPane {
685                  btnInstr.setRolloverEnabled(false);                  btnInstr.setRolloverEnabled(false);
686                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
687                                    
688                  add(btnInstr);                  instrumentPane = new InstrumentPane();
689                    add(instrumentPane);
690                                    
691                  JPanel p = new JPanel();                  JPanel p = new JPanel();
692                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
# Line 699  class ChannelScreen extends PixmapPane { Line 753  class ChannelScreen extends PixmapPane {
753                  installListeners();                  installListeners();
754          }          }
755                    
756            protected void
757            onDestroy() { timer.stop(); }
758            
759          private void          private void
760          createEngineMenu() {          createEngineMenu() {
761                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
# Line 722  class ChannelScreen extends PixmapPane { Line 779  class ChannelScreen extends PixmapPane {
779                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) { loadInstrument(); }
780                  });                  });
781                                    
782                    btnEditInstr.addActionListener(new ActionListener() {
783                            public void
784                            actionPerformed(ActionEvent e) {
785                                    CC.getSamplerModel().editBackendInstrument(channel.getChannelId());
786                            }
787                    });
788                    
789                  btnEngine.addActionListener(new ActionListener() {                  btnEngine.addActionListener(new ActionListener() {
790                          public void                          public void
791                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
# Line 729  class ChannelScreen extends PixmapPane { Line 793  class ChannelScreen extends PixmapPane {
793                                  menuEngines.show(btnEngine, 0, y);                                  menuEngines.show(btnEngine, 0, y);
794                          }                          }
795                  });                  });
796                    
797                    addMouseListener(getHandler());
798                    addHierarchyListener(getHandler());
799                    
800                    ActionListener l = new ActionListener() {
801                            public void
802                            actionPerformed(ActionEvent e) {
803                                    if(getMousePosition(true) != null) {
804                                            getHandler().mouseEntered(null);
805                                    } else {
806                                            getHandler().mouseExited(null);
807                                    }
808                            }
809                    };
810                    timer = new Timer(1000, l);
811                    timer.start();
812          }          }
813                    
814          private void          private void
815          loadInstrument() {          loadInstrument() {
816                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
817                  dlg.setVisible(true);                  dlg.setVisible(true);
818                                    
819                  if(!dlg.isCancelled()) {                  if(!dlg.isCancelled()) {
# Line 755  class ChannelScreen extends PixmapPane { Line 835  class ChannelScreen extends PixmapPane {
835                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
836                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
837                  }                  }
838                    
839                    instrumentPane.update();
840                    
841                  if(sc.getEngine() != null) {                  if(sc.getEngine() != null) {
842                          String s = sc.getEngine().getDescription();                          String s = sc.getEngine().getDescription();
# Line 799  class ChannelScreen extends PixmapPane { Line 881  class ChannelScreen extends PixmapPane {
881                  lVoices.setMaximumSize(d);                  lVoices.setMaximumSize(d);
882          }          }
883                    
884            class InstrumentPane extends JPanel {
885                    private final JPanel leftPane = new JPanel();
886                    private final JPanel rightPane = new JPanel();
887                    
888                    InstrumentPane() {
889                            setOpaque(false);
890                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
891                            add(leftPane);
892                            add(btnInstr);
893                            add(rightPane);
894                            add(sbbEditInstr);
895                            btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt"));
896                            sbbEditInstr.setVisible(false);
897                            setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
898                            
899                            update();
900                    }
901                    
902                    public void
903                    update() {
904                            int a = btnInstr.getMinimumSize().width;
905                            int b = 0;
906                            if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width;
907                            
908                            int max = 254 - b;
909                            if(a > max) a = max;
910                            
911                            int h = btnInstr.getPreferredSize().height;
912                            btnInstr.setPreferredSize(new Dimension(a, h));
913                            h = btnInstr.getMaximumSize().height;
914                            btnInstr.setMaximumSize(new Dimension(a, h));
915                            
916                            
917                            int i = (254 - btnInstr.getPreferredSize().width) / 2;
918                            
919                            int j = i;
920                            if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width;
921                            if(i < 0 || j < 0) i = j = 0;
922                            
923                            Dimension d = new Dimension(i, 1);
924                            leftPane.setMinimumSize(d);
925                            leftPane.setPreferredSize(d);
926                            leftPane.setMaximumSize(d);
927                            
928                            d = new Dimension(j, 1);
929                            rightPane.setMinimumSize(d);
930                            rightPane.setPreferredSize(d);
931                            rightPane.setMaximumSize(d);
932                            
933                            validate();
934                    }
935            }
936            
937          class FxSendsPane extends JSFxSendsPane {          class FxSendsPane extends JSFxSendsPane {
938                  FxSendsPane(SamplerChannelModel model) {                  FxSendsPane(SamplerChannelModel model) {
939                          super(model);                          super(model);
# Line 847  class ChannelScreen extends PixmapPane { Line 982  class ChannelScreen extends PixmapPane {
982                          setForeground(new java.awt.Color(0xFFA300));                          setForeground(new java.awt.Color(0xFFA300));
983                  }                  }
984          }          }
985            
986            static class ScreenButtonBg extends PixmapPane {
987                    ScreenButtonBg(JButton btn) {
988                            super(Res.gfxScreenBtnBg);
989                            setPixmapInsets(new Insets(4, 4, 4, 4));
990                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
991                            setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
992                            add(btn);
993                            setPreferredSize(new Dimension(getPreferredSize().width, 13));
994                    }
995                    
996                    public Dimension
997                    getPreferredSize() {
998                            return new Dimension(super.getPreferredSize().width, 13);
999                    }
1000            }
1001            
1002            private final EventHandler eventHandler = new EventHandler();
1003            
1004            private EventHandler
1005            getHandler() { return eventHandler; }
1006            
1007            private class EventHandler extends MouseAdapter implements HierarchyListener {
1008                    public void
1009                    mouseEntered(MouseEvent e)  {
1010                            if(channel.getChannelInfo().getInstrumentStatus() != 100) return;
1011                            
1012                            if(!sbbEditInstr.isVisible()) {
1013                                    sbbEditInstr.setVisible(true);
1014                                    instrumentPane.update();
1015                            }
1016                    }
1017                    
1018                    public void
1019                    mouseExited(MouseEvent e)  {
1020                            if(getMousePosition(true) != null) return;
1021                            if(sbbEditInstr.isVisible()) {
1022                                    sbbEditInstr.setVisible(false);
1023                                    instrumentPane.update();
1024                            }
1025                    }
1026                    
1027                    /** Called when the hierarchy has been changed. */
1028                    public void
1029                    hierarchyChanged(HierarchyEvent e) {
1030                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
1031                                    if(getMousePosition() == null) mouseExited(null);
1032                                    else mouseEntered(null);
1033                            }
1034                    }
1035            }
1036  }  }
1037    
1038  class ChannelOptions extends JXCollapsiblePane {  class ChannelOptions extends JXCollapsiblePane {
# Line 1080  class ChannelOptions extends JXCollapsib Line 1266  class ChannelOptions extends JXCollapsib
1266                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1267                  });                  });
1268                                    
                 CC.getSamplerModel().addSamplerChannelListListener(getHandler());  
1269                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1270                                    
1271                  cbAudioDevice.addActionListener(new ActionListener() {                  cbAudioDevice.addActionListener(new ActionListener() {
# Line 1314  class ChannelOptions extends JXCollapsib Line 1499  class ChannelOptions extends JXCollapsib
1499          private void          private void
1500          setUpdate(boolean b) { update = b; }          setUpdate(boolean b) { update = b; }
1501                    
1502            protected void
1503            onDestroy() {
1504                    SamplerModel sm = CC.getSamplerModel();
1505                    
1506                    sm.removeMidiDeviceListListener(getHandler());
1507                    sm.removeAudioDeviceListListener(getHandler());
1508                    sm.removeMidiInstrumentMapListListener(mapListListener);
1509                    sm.removeSamplerListener(samplerListener);
1510                    
1511                    if(midiDevice != null) {
1512                            midiDevice.removeMidiDeviceListener(getHandler());
1513                    }
1514            }
1515            
1516          private final Handler handler = new Handler();          private final Handler handler = new Handler();
1517                    
1518          private Handler          private Handler
1519          getHandler() { return handler; }          getHandler() { return handler; }
1520                    
1521          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1522                                          SamplerChannelListListener, MidiDeviceListener {                                          MidiDeviceListener {
1523                  /**                  /**
1524                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1525                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 1361  class ChannelOptions extends JXCollapsib Line 1560  class ChannelOptions extends JXCollapsib
1560                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1561                  }                  }
1562                                    
                 /**  
                  * 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());  
                                 }  
                         }  
                 }  
                   
1563                  public void                  public void
1564                  settingsChanged(MidiDeviceEvent e) {                  settingsChanged(MidiDeviceEvent e) {
1565                          if(isUpdate()) {                          if(isUpdate()) {

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

  ViewVC Help
Powered by ViewVC