/[svn]/jsampler/trunk/src/org/jsampler/view/classic/Channel.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/classic/Channel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1204 by iliev, Thu May 24 21:43:45 2007 UTC revision 1341 by iliev, Mon Sep 10 22:29:09 2007 UTC
# Line 63  import javax.swing.JPanel; Line 63  import javax.swing.JPanel;
63  import javax.swing.JSeparator;  import javax.swing.JSeparator;
64  import javax.swing.JSlider;  import javax.swing.JSlider;
65  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
66    import javax.swing.JToolBar;
67  import javax.swing.TransferHandler;  import javax.swing.TransferHandler;
68    
69  import javax.swing.border.Border;  import javax.swing.border.Border;
# Line 86  import org.jsampler.SamplerModel; Line 87  import org.jsampler.SamplerModel;
87    
88  import org.jsampler.event.ListEvent;  import org.jsampler.event.ListEvent;
89  import org.jsampler.event.ListListener;  import org.jsampler.event.ListListener;
90    import org.jsampler.event.MidiDeviceEvent;
91  import org.jsampler.event.MidiDeviceListEvent;  import org.jsampler.event.MidiDeviceListEvent;
92  import org.jsampler.event.MidiDeviceListListener;  import org.jsampler.event.MidiDeviceListListener;
93    import org.jsampler.event.MidiDeviceListener;
94  import org.jsampler.event.SamplerAdapter;  import org.jsampler.event.SamplerAdapter;
95  import org.jsampler.event.SamplerChannelAdapter;  import org.jsampler.event.SamplerChannelAdapter;
96  import org.jsampler.event.SamplerChannelEvent;  import org.jsampler.event.SamplerChannelEvent;
# Line 95  import org.jsampler.event.SamplerChannel Line 98  import org.jsampler.event.SamplerChannel
98  import org.jsampler.event.SamplerChannelListListener;  import org.jsampler.event.SamplerChannelListListener;
99  import org.jsampler.event.SamplerChannelListener;  import org.jsampler.event.SamplerChannelListener;
100  import org.jsampler.event.SamplerEvent;  import org.jsampler.event.SamplerEvent;
101    import org.jsampler.event.SamplerListener;
102    
103    import org.jsampler.view.std.JSChannelOutputRoutingDlg;
104    import org.jsampler.view.std.JSFxSendsPane;
105    import org.jsampler.view.std.JSInstrumentChooser;
106    
107  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
108  import org.linuxsampler.lscp.MidiInputDevice;  import org.linuxsampler.lscp.MidiInputDevice;
# Line 328  public class Channel extends org.jsample Line 336  public class Channel extends org.jsample
336                                    
337                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));                  mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
338                  addMouseListener(getHandler());                  addMouseListener(getHandler());
339                    addHierarchyListener(getHandler());
340                                    
341                  JPanel p = new JPanel();                  JPanel p = new JPanel();
342                  p.setOpaque(false);                  p.setOpaque(false);
# Line 812  public class Channel extends org.jsample Line 821  public class Channel extends org.jsample
821                    
822          private void          private void
823          loadInstrument() {          loadInstrument() {
824                  InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame());                  JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());
825                  dlg.setVisible(true);                  dlg.setVisible(true);
826                                    
827                  if(dlg.isCancelled()) return;                  if(dlg.isCancelled()) return;
# Line 856  class ChannelProperties extends JPanel { Line 865  class ChannelProperties extends JPanel {
865          private InformationDialog fxSendsDlg = null;          private InformationDialog fxSendsDlg = null;
866                    
867          private SamplerChannelModel channelModel = null;          private SamplerChannelModel channelModel = null;
868            private MidiDeviceModel midiDevice = null;
869                    
870          private boolean update = false;          private boolean update = false;
871                    
872            private final SamplerListener samplerListener;
873            private final MapListListener mapListListener = new MapListListener();
874            
875          private class NoMap {          private class NoMap {
876                  public String                  public String
877                  toString() { return "[None]"; }                  toString() { return "[None]"; }
# Line 947  class ChannelProperties extends JPanel { Line 960  class ChannelProperties extends JPanel {
960                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }                          channelChanged(SamplerChannelEvent e) { updateChannelProperties(); }
961                  });                  });
962                                    
963                  CC.getSamplerModel().addSamplerListener(new SamplerAdapter() {                  samplerListener = new SamplerAdapter() {
964                          /** Invoked when the default MIDI instrument map is changed. */                          /** Invoked when the default MIDI instrument map is changed. */
965                          public void                          public void
966                          defaultMapChanged(SamplerEvent e) {                          defaultMapChanged(SamplerEvent e) {
967                                  updateCbInstrumentMapToolTipText();                                  updateCbInstrumentMapToolTipText();
                                   
968                          }                          }
969                  });                  };
970                    
971                    CC.getSamplerModel().addSamplerListener(samplerListener);
972                                    
973                  cbInstrumentMap.addItem(noMap);                  cbInstrumentMap.addItem(noMap);
974                  cbInstrumentMap.addItem(defaultMap);                  cbInstrumentMap.addItem(defaultMap);
# Line 985  class ChannelProperties extends JPanel { Line 999  class ChannelProperties extends JPanel {
999                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());
1000                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());
1001                  CC.getSamplerModel().addSamplerChannelListListener(getHandler());                  CC.getSamplerModel().addSamplerChannelListListener(getHandler());
1002                                    CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
                 CC.getSamplerModel().addMidiInstrumentMapListListener(new MapListListener());  
1003                                    
1004                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));                  btnAudioProps.setToolTipText(i18n.getLabel("ChannelProperties.routing"));
1005                    btnAudioProps.setEnabled(false);
1006                  btnAudioProps.addActionListener(new ActionListener() {                  btnAudioProps.addActionListener(new ActionListener() {
1007                          public void                          public void
1008                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
1009                                  SamplerChannel c = getModel().getChannelInfo();                                  SamplerChannel c = getModel().getChannelInfo();
1010                                  new ChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);                                  new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
1011                                                    
1012                          }                          }
1013                  });                  });
# Line 1010  class ChannelProperties extends JPanel { Line 1024  class ChannelProperties extends JPanel {
1024                                  FxSendsPane p = new FxSendsPane(getModel());                                  FxSendsPane p = new FxSendsPane(getModel());
1025                                  int id = getModel().getChannelId();                                  int id = getModel().getChannelId();
1026                                  fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);                                  fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
1027                                  fxSendsDlg.setTitle(i18n.getLabel("FxSendsPane.title", id));                                  fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id));
1028                                  fxSendsDlg.setModal(false);                                  fxSendsDlg.setModal(false);
1029                                  fxSendsDlg.showCloseButton(false);                                  fxSendsDlg.showCloseButton(false);
1030                                  fxSendsDlg.setVisible(true);                                  fxSendsDlg.setVisible(true);
# Line 1022  class ChannelProperties extends JPanel { Line 1036  class ChannelProperties extends JPanel {
1036                  updateChannelProperties();                  updateChannelProperties();
1037          }          }
1038                    
1039            class FxSendsPane extends JSFxSendsPane {
1040                    FxSendsPane(SamplerChannelModel model) {
1041                            super(model);
1042                            
1043                            actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
1044                            actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
1045                    }
1046                    
1047                    protected JToolBar
1048                    createToolBar() {
1049                            JToolBar tb = new JToolBar();
1050                            Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
1051                            tb.setMaximumSize(d);
1052                            tb.setFloatable(false);
1053                            tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
1054                            
1055                            tb.add(new ToolbarButton(actionAddFxSend));
1056                            tb.add(new ToolbarButton(actionRemoveFxSend));
1057                    
1058                            return tb;
1059                    }
1060            }
1061            
1062          private JPanel          private JPanel
1063          createEnginePane() {          createEnginePane() {
1064                  for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngines.addItem(e);                  for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngines.addItem(e);
# Line 1221  class ChannelProperties extends JPanel { Line 1258  class ChannelProperties extends JPanel {
1258                          cbEngines.setSelectedItem(sc.getEngine());                          cbEngines.setSelectedItem(sc.getEngine());
1259                                                    
1260                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());                          cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo());
1261                            btnAudioProps.setEnabled(am != null);
1262                  } catch(Exception x) {                  } catch(Exception x) {
1263                          CC.getLogger().log(Level.WARNING, "Unkown error", x);                          CC.getLogger().log(Level.WARNING, "Unkown error", x);
1264                  }                  }
1265                                    
1266                  if(sc.getEngine() != null) {                  if(sc.getEngine() != null) {
1267                          if(cbInstrumentMap.getItemCount() > 0) cbInstrumentMap.setEnabled(true);                          cbInstrumentMap.setEnabled(true);
1268                            int id = sc.getMidiInstrumentMapId();
1269                            Object o;
1270                            if(id == -2) o = defaultMap;
1271                            else if(id == -1) o = noMap;
1272                            else o = CC.getSamplerModel().getMidiInstrumentMapById(id);
1273                            
1274                            if(cbInstrumentMap.getSelectedItem() != o) {
1275                                    cbInstrumentMap.setSelectedItem(o);
1276                            }
1277                  } else {                  } else {
1278                          cbInstrumentMap.setSelectedItem(noMap);                          cbInstrumentMap.setSelectedItem(noMap);
1279                          cbInstrumentMap.setEnabled(false);                          cbInstrumentMap.setEnabled(false);
# Line 1294  class ChannelProperties extends JPanel { Line 1341  class ChannelProperties extends JPanel {
1341                          return;                          return;
1342                  }                  }
1343                                    
1344                    if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler());
1345                    
1346                  cbMidiPort.removeAllItems();                  cbMidiPort.removeAllItems();
1347                                    
1348                  if(mid == null) {                  if(mid == null) {
1349                            midiDevice = null;
1350                          cbMidiPort.setEnabled(false);                          cbMidiPort.setEnabled(false);
1351                                                    
1352                          cbMidiChannel.setSelectedItem(null);                          cbMidiChannel.setSelectedItem(null);
1353                          cbMidiChannel.setEnabled(false);                          cbMidiChannel.setEnabled(false);
1354                  } else {                  } else {
1355                            midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId());
1356                            if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler());
1357                            
1358                          cbMidiPort.setEnabled(true);                          cbMidiPort.setEnabled(true);
1359                                                    
1360                          MidiPort[] ports = mid.getMidiPorts();                          MidiPort[] ports = mid.getMidiPorts();
# Line 1379  class ChannelProperties extends JPanel { Line 1432  class ChannelProperties extends JPanel {
1432          private Handler          private Handler
1433          getHandler() { return handler; }          getHandler() { return handler; }
1434                    
1435          private class Handler implements MidiDeviceListListener,          private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>,
1436                                  ListListener<AudioDeviceModel>, SamplerChannelListListener {                                          SamplerChannelListListener, MidiDeviceListener {
1437                                    
1438                  /**                  /**
1439                   * Invoked when a new MIDI device is created.                   * Invoked when a new MIDI device is created.
# Line 1439  class ChannelProperties extends JPanel { Line 1492  class ChannelProperties extends JPanel {
1492                  channelRemoved(SamplerChannelListEvent e) {                  channelRemoved(SamplerChannelListEvent e) {
1493                          // Some cleanup when the channel is removed.                          // Some cleanup when the channel is removed.
1494                          if(e.getChannelModel().getChannelId() == channelModel.getChannelId()) {                          if(e.getChannelModel().getChannelId() == channelModel.getChannelId()) {
1495                                  CC.getSamplerModel().removeMidiDeviceListListener(getHandler());                                  SamplerModel sm = CC.getSamplerModel();
1496                                  CC.getSamplerModel().removeAudioDeviceListListener(getHandler());                                  
1497                                    sm.removeMidiDeviceListListener(getHandler());
1498                                    sm.removeAudioDeviceListListener(getHandler());
1499                                    sm.removeMidiInstrumentMapListListener(mapListListener);
1500                                    sm.removeSamplerListener(samplerListener);
1501                                    sm.removeSamplerChannelListListener(getHandler());
1502                                    
1503                                    if(midiDevice != null) {
1504                                            midiDevice.removeMidiDeviceListener(getHandler());
1505                                    }
1506                          }                          }
1507                  }                  }
1508                    
1509                    public void
1510                    settingsChanged(MidiDeviceEvent e) {
1511                            if(isUpdate()) {
1512                                    CC.getLogger().warning("Invalid update state");
1513                                    return;
1514                            }
1515                            
1516                            setUpdate(true);
1517                            int idx = cbMidiPort.getSelectedIndex();
1518                            MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo();
1519                            
1520                            cbMidiPort.removeAllItems();
1521                            for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port);
1522                            
1523                            if(idx >= cbMidiPort.getModel().getSize()) idx = 0;
1524                            
1525                            setUpdate(false);
1526                            
1527                            if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx);
1528                    }
1529          }          }
1530                    
1531          private class MapListListener implements ListListener<MidiInstrumentMap> {          private class MapListListener implements ListListener<MidiInstrumentMap> {
1532                  /** Invoked when a new MIDI instrument map is added to a list. */                  /** Invoked when a new MIDI instrument map is added to a list. */
1533                  public void                  public void
1534                  entryAdded(ListEvent<MidiInstrumentMap> e) {                  entryAdded(ListEvent<MidiInstrumentMap> e) {
                         //cbInstrumentMap.addItem(e.getEntry());  
1535                          cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());                          cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount());
1536                          boolean b = getModel().getChannelInfo().getEngine() != null;                          boolean b = getModel().getChannelInfo().getEngine() != null;
1537                          if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);                          if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true);

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

  ViewVC Help
Powered by ViewVC