--- jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java 2007/09/01 13:46:04 1318
+++ jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java 2007/09/22 17:27:06 1357
@@ -29,6 +29,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@@ -51,6 +53,7 @@
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
+import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -245,6 +248,17 @@
setOpaque(false);
+ int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
+ dialVolume.setMaximum(i);
+ String mcv = MAXIMUM_CHANNEL_VOLUME;
+ preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() {
+ public void
+ propertyChange(PropertyChangeEvent e) {
+ int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME);
+ dialVolume.setMaximum(j);
+ }
+ });
+
getModel().addSamplerChannelListener(getHandler());
updateChannelInfo();
@@ -282,6 +296,8 @@
run() { listener.actionPerformed(null); }
});
}
+
+ CC.getSamplerModel().addSamplerChannelListListener(getHandler());
}
private JPanel
@@ -413,12 +429,20 @@
}
}
+ protected void
+ onDestroy() {
+ CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
+
+ screen.onDestroy();
+ optionsPane.onDestroy();
+ }
+
private final EventHandler eventHandler = new EventHandler();
private EventHandler
getHandler() { return eventHandler; }
- private class EventHandler implements SamplerChannelListener {
+ private class EventHandler implements SamplerChannelListener, SamplerChannelListListener {
/**
* Invoked when changes are made to a sampler channel.
* @param e A SamplerChannelEvent
instance
@@ -446,6 +470,27 @@
voiceCountChanged(SamplerChannelEvent e) {
screen.updateVoiceCount(getModel().getVoiceCount());
}
+
+ /**
+ * Invoked when a new sampler channel is created.
+ * @param e A SamplerChannelListEvent
+ * instance providing the event information.
+ */
+ public void
+ channelAdded(SamplerChannelListEvent e) { }
+
+ /**
+ * Invoked when a sampler channel is removed.
+ * @param e A SamplerChannelListEvent
+ * instance providing the event information.
+ */
+ public void
+ channelRemoved(SamplerChannelListEvent e) {
+ // Some cleanup when the channel is removed.
+ if(e.getChannelModel().getChannelId() == getChannelId()) {
+ onDestroy();
+ }
+ }
}
@@ -589,8 +634,14 @@
class ChannelScreen extends PixmapPane {
private final Channel channel;
+
+ private final InstrumentPane instrumentPane;
private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
+ private final JButton btnEditInstr =
+ new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
+ private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
+
private final JButton btnFxSends =
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
@@ -607,6 +658,8 @@
private Dimension dimVolume;
+ private Timer timer;
+
class Label extends JLabel {
Label() { this(""); }
@@ -632,7 +685,8 @@
btnInstr.setRolloverEnabled(false);
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
- add(btnInstr);
+ instrumentPane = new InstrumentPane();
+ add(instrumentPane);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
@@ -699,6 +753,9 @@
installListeners();
}
+ protected void
+ onDestroy() { timer.stop(); }
+
private void
createEngineMenu() {
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
@@ -722,6 +779,13 @@
actionPerformed(ActionEvent e) { loadInstrument(); }
});
+ btnEditInstr.addActionListener(new ActionListener() {
+ public void
+ actionPerformed(ActionEvent e) {
+ CC.getSamplerModel().editBackendInstrument(channel.getChannelId());
+ }
+ });
+
btnEngine.addActionListener(new ActionListener() {
public void
actionPerformed(ActionEvent e) {
@@ -729,11 +793,27 @@
menuEngines.show(btnEngine, 0, y);
}
});
+
+ addMouseListener(getHandler());
+ addHierarchyListener(getHandler());
+
+ ActionListener l = new ActionListener() {
+ public void
+ actionPerformed(ActionEvent e) {
+ if(getMousePosition(true) != null) {
+ getHandler().mouseEntered(null);
+ } else {
+ getHandler().mouseExited(null);
+ }
+ }
+ };
+ timer = new Timer(1000, l);
+ timer.start();
}
private void
loadInstrument() {
- JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame());
+ JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
dlg.setVisible(true);
if(!dlg.isCancelled()) {
@@ -755,6 +835,8 @@
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
}
+
+ instrumentPane.update();
if(sc.getEngine() != null) {
String s = sc.getEngine().getDescription();
@@ -799,6 +881,59 @@
lVoices.setMaximumSize(d);
}
+ class InstrumentPane extends JPanel {
+ private final JPanel leftPane = new JPanel();
+ private final JPanel rightPane = new JPanel();
+
+ InstrumentPane() {
+ setOpaque(false);
+ setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
+ add(leftPane);
+ add(btnInstr);
+ add(rightPane);
+ add(sbbEditInstr);
+ btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt"));
+ sbbEditInstr.setVisible(false);
+ setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
+
+ update();
+ }
+
+ public void
+ update() {
+ int a = btnInstr.getMinimumSize().width;
+ int b = 0;
+ if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width;
+
+ int max = 254 - b;
+ if(a > max) a = max;
+
+ int h = btnInstr.getPreferredSize().height;
+ btnInstr.setPreferredSize(new Dimension(a, h));
+ h = btnInstr.getMaximumSize().height;
+ btnInstr.setMaximumSize(new Dimension(a, h));
+
+
+ int i = (254 - btnInstr.getPreferredSize().width) / 2;
+
+ int j = i;
+ if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width;
+ if(i < 0 || j < 0) i = j = 0;
+
+ Dimension d = new Dimension(i, 1);
+ leftPane.setMinimumSize(d);
+ leftPane.setPreferredSize(d);
+ leftPane.setMaximumSize(d);
+
+ d = new Dimension(j, 1);
+ rightPane.setMinimumSize(d);
+ rightPane.setPreferredSize(d);
+ rightPane.setMaximumSize(d);
+
+ validate();
+ }
+ }
+
class FxSendsPane extends JSFxSendsPane {
FxSendsPane(SamplerChannelModel model) {
super(model);
@@ -847,6 +982,57 @@
setForeground(new java.awt.Color(0xFFA300));
}
}
+
+ static class ScreenButtonBg extends PixmapPane {
+ ScreenButtonBg(JButton btn) {
+ super(Res.gfxScreenBtnBg);
+ setPixmapInsets(new Insets(4, 4, 4, 4));
+ setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
+ setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
+ add(btn);
+ setPreferredSize(new Dimension(getPreferredSize().width, 13));
+ }
+
+ public Dimension
+ getPreferredSize() {
+ return new Dimension(super.getPreferredSize().width, 13);
+ }
+ }
+
+ private final EventHandler eventHandler = new EventHandler();
+
+ private EventHandler
+ getHandler() { return eventHandler; }
+
+ private class EventHandler extends MouseAdapter implements HierarchyListener {
+ public void
+ mouseEntered(MouseEvent e) {
+ if(channel.getChannelInfo().getInstrumentStatus() != 100) return;
+
+ if(!sbbEditInstr.isVisible()) {
+ sbbEditInstr.setVisible(true);
+ instrumentPane.update();
+ }
+ }
+
+ public void
+ mouseExited(MouseEvent e) {
+ if(getMousePosition(true) != null) return;
+ if(sbbEditInstr.isVisible()) {
+ sbbEditInstr.setVisible(false);
+ instrumentPane.update();
+ }
+ }
+
+ /** Called when the hierarchy has been changed. */
+ public void
+ hierarchyChanged(HierarchyEvent e) {
+ if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
+ if(getMousePosition() == null) mouseExited(null);
+ else mouseEntered(null);
+ }
+ }
+ }
}
class ChannelOptions extends JXCollapsiblePane {
@@ -1080,7 +1266,6 @@
actionPerformed(ActionEvent e) { updateInstrumentMap(); }
});
- CC.getSamplerModel().addSamplerChannelListListener(getHandler());
CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
cbAudioDevice.addActionListener(new ActionListener() {
@@ -1314,13 +1499,27 @@
private void
setUpdate(boolean b) { update = b; }
+ protected void
+ onDestroy() {
+ SamplerModel sm = CC.getSamplerModel();
+
+ sm.removeMidiDeviceListListener(getHandler());
+ sm.removeAudioDeviceListListener(getHandler());
+ sm.removeMidiInstrumentMapListListener(mapListListener);
+ sm.removeSamplerListener(samplerListener);
+
+ if(midiDevice != null) {
+ midiDevice.removeMidiDeviceListener(getHandler());
+ }
+ }
+
private final Handler handler = new Handler();
private Handler
getHandler() { return handler; }
private class Handler implements MidiDeviceListListener, ListListener,
- SamplerChannelListListener, MidiDeviceListener {
+ MidiDeviceListener {
/**
* Invoked when a new MIDI device is created.
* @param e A MidiDeviceListEvent
@@ -1361,37 +1560,6 @@
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
}
- /**
- * Invoked when a new sampler channel is created.
- * @param e A SamplerChannelListEvent
- * instance providing the event information.
- */
- public void
- channelAdded(SamplerChannelListEvent e) { }
-
- /**
- * Invoked when a sampler channel is removed.
- * @param e A SamplerChannelListEvent
- * 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());
- }
- }
- }
-
public void
settingsChanged(MidiDeviceEvent e) {
if(isUpdate()) {