/[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 1467 by iliev, Sat Nov 3 13:14:31 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.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;
34    import java.awt.event.HierarchyEvent;
35    import java.awt.event.HierarchyListener;
36  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
37  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
38    
# Line 48  import javax.swing.JLabel; Line 52  import javax.swing.JLabel;
52  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
53  import javax.swing.JPanel;  import javax.swing.JPanel;
54  import javax.swing.JPopupMenu;  import javax.swing.JPopupMenu;
55    import javax.swing.JScrollPane;
56  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
57  import javax.swing.JToolBar;  import javax.swing.JToolBar;
58  import javax.swing.SwingConstants;  import javax.swing.SwingConstants;
59    import javax.swing.Timer;
60    
61  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
62  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
# Line 245  public class Channel extends org.jsample Line 251  public class Channel extends org.jsample
251                                    
252                  setOpaque(false);                  setOpaque(false);
253                                    
254                    int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
255                    dialVolume.setMaximum(i);
256                    String mcv = MAXIMUM_CHANNEL_VOLUME;
257                    preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() {
258                            public void
259                            propertyChange(PropertyChangeEvent e) {
260                                    int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
261                                    dialVolume.setMaximum(j);
262                            }
263                    });
264                    
265                  getModel().addSamplerChannelListener(getHandler());                  getModel().addSamplerChannelListener(getHandler());
266                                    
267                  updateChannelInfo();                  updateChannelInfo();
# Line 257  public class Channel extends org.jsample Line 274  public class Channel extends org.jsample
274                                  public void                                  public void
275                                  propertyChange(PropertyChangeEvent e) {                                  propertyChange(PropertyChangeEvent e) {
276                                          if(e.getNewValue() == "expanded") {                                          if(e.getNewValue() == "expanded") {
277                                                    // TODO: this should be done regardles the listener != null?
278                                                  mainPane.removePropertyChangeListener(s, this);                                                  mainPane.removePropertyChangeListener(s, this);
279                                                    ///////
280                                                  listener.actionPerformed(null);                                                  listener.actionPerformed(null);
281                                                    ensureChannelIsVisible();
282                                            } else if(e.getNewValue() == "expanding/collapsing") {
283                                                    ensureChannelIsVisible();
284                                          }                                          }
285                                  }                                  }
286                          });                          });
# Line 282  public class Channel extends org.jsample Line 304  public class Channel extends org.jsample
304                                  run() { listener.actionPerformed(null); }                                  run() { listener.actionPerformed(null); }
305                          });                          });
306                  }                  }
307                    
308                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
309            }
310            
311            private void
312            ensureChannelIsVisible() {
313                    Container p = getParent();
314                    JScrollPane sp = null;
315                    while(p != null) {
316                            if(p instanceof JScrollPane) {
317                                    sp = (JScrollPane)p;
318                                    break;
319                            }
320                            p = p.getParent();
321                    }
322                    if(sp == null) return;
323                    int h = sp.getViewport().getView().getHeight();
324                    sp.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
325          }          }
326                    
327          private JPanel          private JPanel
# Line 413  public class Channel extends org.jsample Line 453  public class Channel extends org.jsample
453                  }                  }
454          }          }
455                    
456            protected void
457            onDestroy() {
458                    CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
459                    
460                    screen.onDestroy();
461                    optionsPane.onDestroy();
462            }
463            
464          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
465                    
466          private EventHandler          private EventHandler
467          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
468                    
469          private class EventHandler implements SamplerChannelListener {          private class EventHandler implements SamplerChannelListener, SamplerChannelListListener {
470                  /**                  /**
471                   * Invoked when changes are made to a sampler channel.                   * Invoked when changes are made to a sampler channel.
472                   * @param e A <code>SamplerChannelEvent</code> instance                   * @param e A <code>SamplerChannelEvent</code> instance
# Line 446  public class Channel extends org.jsample Line 494  public class Channel extends org.jsample
494                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
495                          screen.updateVoiceCount(getModel().getVoiceCount());                          screen.updateVoiceCount(getModel().getVoiceCount());
496                  }                  }
497                    
498                    /**
499                     * Invoked when a new sampler channel is created.
500                     * @param e A <code>SamplerChannelListEvent</code>
501                     * instance providing the event information.
502                     */
503                    public void
504                    channelAdded(SamplerChannelListEvent e) { }
505            
506                    /**
507                     * Invoked when a sampler channel is removed.
508                     * @param e A <code>SamplerChannelListEvent</code>
509                     * instance providing the event information.
510                     */
511                    public void
512                    channelRemoved(SamplerChannelListEvent e) {
513                            // Some cleanup when the channel is removed.
514                            if(e.getChannelModel().getChannelId() == getChannelId()) {
515                                    onDestroy();
516                            }
517                    }
518          }          }
519                    
520                    
# Line 589  class ChannelPane extends PixmapPane { Line 658  class ChannelPane extends PixmapPane {
658    
659  class ChannelScreen extends PixmapPane {  class ChannelScreen extends PixmapPane {
660          private final Channel channel;          private final Channel channel;
661            
662            private final InstrumentPane instrumentPane;
663          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));          private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
664                    
665            private final JButton btnEditInstr =
666                    new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
667            private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
668            
669          private final JButton btnFxSends =          private final JButton btnFxSends =
670                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));                  new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
671                    
# Line 607  class ChannelScreen extends PixmapPane { Line 682  class ChannelScreen extends PixmapPane {
682                    
683          private Dimension dimVolume;          private Dimension dimVolume;
684                    
685            private Timer timer;
686            
687          class Label extends JLabel {          class Label extends JLabel {
688                  Label() { this(""); }                  Label() { this(""); }
689                                    
# Line 632  class ChannelScreen extends PixmapPane { Line 709  class ChannelScreen extends PixmapPane {
709                  btnInstr.setRolloverEnabled(false);                  btnInstr.setRolloverEnabled(false);
710                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));                  btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
711                                    
712                  add(btnInstr);                  instrumentPane = new InstrumentPane();
713                    add(instrumentPane);
714                                    
715                  JPanel p = new JPanel();                  JPanel p = new JPanel();
716                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
# Line 699  class ChannelScreen extends PixmapPane { Line 777  class ChannelScreen extends PixmapPane {
777                  installListeners();                  installListeners();
778          }          }
779                    
780            protected void
781            onDestroy() { timer.stop(); }
782            
783          private void          private void
784          createEngineMenu() {          createEngineMenu() {
785                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {                  for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
# Line 722  class ChannelScreen extends PixmapPane { Line 803  class ChannelScreen extends PixmapPane {
803                          actionPerformed(ActionEvent e) { loadInstrument(); }                          actionPerformed(ActionEvent e) { loadInstrument(); }
804                  });                  });
805                                    
806                    btnEditInstr.addActionListener(new ActionListener() {
807                            public void
808                            actionPerformed(ActionEvent e) {
809                                    CC.getSamplerModel().editBackendInstrument(channel.getChannelId());
810                            }
811                    });
812                    
813                  btnEngine.addActionListener(new ActionListener() {                  btnEngine.addActionListener(new ActionListener() {
814                          public void                          public void
815                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
# Line 729  class ChannelScreen extends PixmapPane { Line 817  class ChannelScreen extends PixmapPane {
817                                  menuEngines.show(btnEngine, 0, y);                                  menuEngines.show(btnEngine, 0, y);
818                          }                          }
819                  });                  });
820                    
821                    addMouseListener(getHandler());
822                    addHierarchyListener(getHandler());
823                    
824                    ActionListener l = new ActionListener() {
825                            public void
826                            actionPerformed(ActionEvent e) {
827                                    if(getMousePosition(true) != null) {
828                                            getHandler().mouseEntered(null);
829                                    } else {
830                                            getHandler().mouseExited(null);
831                                    }
832                            }
833                    };
834                    timer = new Timer(1000, l);
835                    timer.start();
836          }          }
837                    
838          private void          private void
839          loadInstrument() {          loadInstrument() {
840                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
841                  dlg.setVisible(true);                  dlg.setVisible(true);
842                                    
843                  if(!dlg.isCancelled()) {                  if(!dlg.isCancelled()) {
# Line 755  class ChannelScreen extends PixmapPane { Line 859  class ChannelScreen extends PixmapPane {
859                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                          if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
860                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                          else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
861                  }                  }
862                    
863                    instrumentPane.update();
864                    
865                  if(sc.getEngine() != null) {                  if(sc.getEngine() != null) {
866                          String s = sc.getEngine().getDescription();                          String s = sc.getEngine().getDescription();
# Line 799  class ChannelScreen extends PixmapPane { Line 905  class ChannelScreen extends PixmapPane {
905                  lVoices.setMaximumSize(d);                  lVoices.setMaximumSize(d);
906          }          }
907                    
908            class InstrumentPane extends JPanel {
909                    private final JPanel leftPane = new JPanel();
910                    private final JPanel rightPane = new JPanel();
911                    
912                    InstrumentPane() {
913                            setOpaque(false);
914                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
915                            add(leftPane);
916                            add(btnInstr);
917                            add(rightPane);
918                            add(sbbEditInstr);
919                            btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt"));
920                            sbbEditInstr.setVisible(false);
921                            setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
922                            
923                            update();
924                    }
925                    
926                    public void
927                    update() {
928                            int a = btnInstr.getMinimumSize().width;
929                            int b = 0;
930                            if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width;
931                            
932                            int max = 254 - b;
933                            if(a > max) a = max;
934                            
935                            int h = btnInstr.getPreferredSize().height;
936                            btnInstr.setPreferredSize(new Dimension(a, h));
937                            h = btnInstr.getMaximumSize().height;
938                            btnInstr.setMaximumSize(new Dimension(a, h));
939                            
940                            
941                            int i = (254 - btnInstr.getPreferredSize().width) / 2;
942                            
943                            int j = i;
944                            if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width;
945                            if(i < 0 || j < 0) i = j = 0;
946                            
947                            Dimension d = new Dimension(i, 1);
948                            leftPane.setMinimumSize(d);
949                            leftPane.setPreferredSize(d);
950                            leftPane.setMaximumSize(d);
951                            
952                            d = new Dimension(j, 1);
953                            rightPane.setMinimumSize(d);
954                            rightPane.setPreferredSize(d);
955                            rightPane.setMaximumSize(d);
956                            
957                            validate();
958                    }
959            }
960            
961          class FxSendsPane extends JSFxSendsPane {          class FxSendsPane extends JSFxSendsPane {
962                  FxSendsPane(SamplerChannelModel model) {                  FxSendsPane(SamplerChannelModel model) {
963                          super(model);                          super(model);
# Line 847  class ChannelScreen extends PixmapPane { Line 1006  class ChannelScreen extends PixmapPane {
1006                          setForeground(new java.awt.Color(0xFFA300));                          setForeground(new java.awt.Color(0xFFA300));
1007                  }                  }
1008          }          }
1009            
1010            static class ScreenButtonBg extends PixmapPane {
1011                    ScreenButtonBg(JButton btn) {
1012                            super(Res.gfxScreenBtnBg);
1013                            setPixmapInsets(new Insets(4, 4, 4, 4));
1014                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
1015                            setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
1016                            add(btn);
1017                            setPreferredSize(new Dimension(getPreferredSize().width, 13));
1018                    }
1019                    
1020                    public Dimension
1021                    getPreferredSize() {
1022                            return new Dimension(super.getPreferredSize().width, 13);
1023                    }
1024            }
1025            
1026            private final EventHandler eventHandler = new EventHandler();
1027            
1028            private EventHandler
1029            getHandler() { return eventHandler; }
1030            
1031            private class EventHandler extends MouseAdapter implements HierarchyListener {
1032                    public void
1033                    mouseEntered(MouseEvent e)  {
1034                            if(channel.getChannelInfo().getInstrumentStatus() != 100) return;
1035                            
1036                            if(!sbbEditInstr.isVisible()) {
1037                                    sbbEditInstr.setVisible(true);
1038                                    instrumentPane.update();
1039                            }
1040                    }
1041                    
1042                    public void
1043                    mouseExited(MouseEvent e)  {
1044                            if(getMousePosition(true) != null) return;
1045                            if(sbbEditInstr.isVisible()) {
1046                                    sbbEditInstr.setVisible(false);
1047                                    instrumentPane.update();
1048                            }
1049                    }
1050                    
1051                    /** Called when the hierarchy has been changed. */
1052                    public void
1053                    hierarchyChanged(HierarchyEvent e) {
1054                            if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
1055                                    if(getMousePosition() == null) mouseExited(null);
1056                                    else mouseEntered(null);
1057                            }
1058                    }
1059            }
1060  }  }
1061    
1062  class ChannelOptions extends JXCollapsiblePane {  class ChannelOptions extends JXCollapsiblePane {
# Line 1080  class ChannelOptions extends JXCollapsib Line 1290  class ChannelOptions extends JXCollapsib
1290                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }                          actionPerformed(ActionEvent e) { updateInstrumentMap(); }
1291                  });                  });
1292                                    
                 CC.getSamplerModel().addSamplerChannelListListener(getHandler());  
1293                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);                  CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
1294                                    
1295                  cbAudioDevice.addActionListener(new ActionListener() {                  cbAudioDevice.addActionListener(new ActionListener() {
# Line 1314  class ChannelOptions extends JXCollapsib Line 1523  class ChannelOptions extends JXCollapsib
1523          private void          private void
1524          setUpdate(boolean b) { update = b; }          setUpdate(boolean b) { update = b; }
1525                    
1526            protected void
1527            onDestroy() {
1528                    SamplerModel sm = CC.getSamplerModel();
1529                    
1530                    sm.removeMidiDeviceListListener(getHandler());
1531                    sm.removeAudioDeviceListListener(getHandler());
1532                    sm.removeMidiInstrumentMapListListener(mapListListener);
1533                    sm.removeSamplerListener(samplerListener);
1534                    
1535                    if(midiDevice != null) {
1536                            midiDevice.removeMidiDeviceListener(getHandler());
1537                    }
1538            }
1539            
1540          private final Handler handler = new Handler();          private final Handler handler = new Handler();
1541                    
1542          private Handler          private Handler
1543          getHandler() { return handler; }          getHandler() { return handler; }
1544                    
1545          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1546                                          SamplerChannelListListener, MidiDeviceListener {                                          MidiDeviceListener {
1547                  /**                  /**
1548                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
1549                   * @param e A <code>MidiDeviceListEvent</code>                   * @param e A <code>MidiDeviceListEvent</code>
# Line 1361  class ChannelOptions extends JXCollapsib Line 1584  class ChannelOptions extends JXCollapsib
1584                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());                          cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
1585                  }                  }
1586                                    
                 /**  
                  * 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());  
                                 }  
                         }  
                 }  
                   
1587                  public void                  public void
1588                  settingsChanged(MidiDeviceEvent e) {                  settingsChanged(MidiDeviceEvent e) {
1589                          if(isUpdate()) {                          if(isUpdate()) {

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

  ViewVC Help
Powered by ViewVC