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

Legend:
Removed from v.1284  
changed lines
  Added in v.1285

  ViewVC Help
Powered by ViewVC