1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
22 |
|
|
23 |
package org.jsampler.view.fantasia; |
package org.jsampler.view.fantasia; |
24 |
|
|
25 |
import java.awt.Cursor; |
import java.awt.Container; |
26 |
import java.awt.Dimension; |
import java.awt.Dimension; |
27 |
import java.awt.Graphics; |
import java.awt.Graphics; |
28 |
|
import java.awt.Graphics2D; |
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 |
|
|
39 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
40 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
41 |
|
|
42 |
|
import java.text.NumberFormat; |
43 |
|
|
44 |
import java.util.logging.Level; |
import java.util.logging.Level; |
45 |
|
|
46 |
import javax.swing.Action; |
import javax.swing.Action; |
50 |
import javax.swing.DefaultListCellRenderer; |
import javax.swing.DefaultListCellRenderer; |
51 |
import javax.swing.JButton; |
import javax.swing.JButton; |
52 |
import javax.swing.JComboBox; |
import javax.swing.JComboBox; |
53 |
|
import javax.swing.JComponent; |
54 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
55 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
56 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
57 |
import javax.swing.JPopupMenu; |
import javax.swing.JPopupMenu; |
58 |
|
import javax.swing.JScrollPane; |
59 |
import javax.swing.JToggleButton; |
import javax.swing.JToggleButton; |
60 |
import javax.swing.JToolBar; |
import javax.swing.JToolBar; |
61 |
import javax.swing.SwingConstants; |
import javax.swing.SwingConstants; |
62 |
|
import javax.swing.Timer; |
63 |
|
|
64 |
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeEvent; |
65 |
import javax.swing.event.ChangeListener; |
import javax.swing.event.ChangeListener; |
73 |
|
|
74 |
import org.jsampler.AudioDeviceModel; |
import org.jsampler.AudioDeviceModel; |
75 |
import org.jsampler.CC; |
import org.jsampler.CC; |
76 |
|
import org.jsampler.HF; |
77 |
import org.jsampler.MidiDeviceModel; |
import org.jsampler.MidiDeviceModel; |
78 |
import org.jsampler.MidiInstrumentMap; |
import org.jsampler.MidiInstrumentMap; |
79 |
import org.jsampler.SamplerChannelModel; |
import org.jsampler.SamplerChannelModel; |
97 |
import org.jsampler.view.std.JSChannelOutputRoutingDlg; |
import org.jsampler.view.std.JSChannelOutputRoutingDlg; |
98 |
import org.jsampler.view.std.JSFxSendsPane; |
import org.jsampler.view.std.JSFxSendsPane; |
99 |
import org.jsampler.view.std.JSInstrumentChooser; |
import org.jsampler.view.std.JSInstrumentChooser; |
100 |
|
import org.jsampler.view.std.JSVolumeEditorPopup; |
|
import org.jvnet.lafwidget.animation.FadeConfigurationManager; |
|
|
import org.jvnet.lafwidget.animation.FadeKind; |
|
101 |
|
|
102 |
import org.jvnet.substance.SubstanceImageCreator; |
import org.jvnet.substance.SubstanceImageCreator; |
|
import org.jvnet.substance.SubstanceLookAndFeel; |
|
103 |
|
|
104 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
105 |
import org.linuxsampler.lscp.MidiInputDevice; |
import org.linuxsampler.lscp.MidiInputDevice; |
109 |
|
|
110 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
111 |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
112 |
|
import static org.jsampler.view.fantasia.FantasiaUtils.*; |
113 |
|
import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType; |
114 |
|
|
115 |
|
|
116 |
/** |
/** |
139 |
*/ |
*/ |
140 |
public |
public |
141 |
Channel(SamplerChannelModel model) { |
Channel(SamplerChannelModel model) { |
142 |
|
this(model, null); |
143 |
|
} |
144 |
|
|
145 |
|
/** |
146 |
|
* Creates a new instance of <code>Channel</code> using the specified |
147 |
|
* non-<code>null</code> channel model. |
148 |
|
* @param model The model to be used by this channel. |
149 |
|
* @param listener A listener which is notified when the newly created |
150 |
|
* channel is fully expanded on the screen. |
151 |
|
* @throws IllegalArgumentException If the model is <code>null</code>. |
152 |
|
*/ |
153 |
|
public |
154 |
|
Channel(SamplerChannelModel model, final ActionListener listener) { |
155 |
super(model); |
super(model); |
156 |
|
|
157 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
254 |
|
|
255 |
setOpaque(false); |
setOpaque(false); |
256 |
|
|
257 |
|
String vmud = VOL_MEASUREMENT_UNIT_DECIBEL; |
258 |
|
preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() { |
259 |
|
public void |
260 |
|
propertyChange(PropertyChangeEvent e) { |
261 |
|
boolean b; |
262 |
|
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
263 |
|
screen.updateVolumeInfo(dialVolume.getValue()); |
264 |
|
} |
265 |
|
}); |
266 |
|
|
267 |
getModel().addSamplerChannelListener(getHandler()); |
getModel().addSamplerChannelListener(getHandler()); |
268 |
|
|
269 |
updateChannelInfo(); |
updateChannelInfo(); |
270 |
|
|
271 |
add(mainPane); |
add(mainPane); |
272 |
|
|
273 |
|
if(listener != null) { |
274 |
|
final String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
275 |
|
mainPane.addPropertyChangeListener(s, new PropertyChangeListener() { |
276 |
|
public void |
277 |
|
propertyChange(PropertyChangeEvent e) { |
278 |
|
if(e.getNewValue() == "expanded") { |
279 |
|
// TODO: this should be done regardles the listener != null? |
280 |
|
mainPane.removePropertyChangeListener(s, this); |
281 |
|
/////// |
282 |
|
listener.actionPerformed(null); |
283 |
|
ensureChannelIsVisible(); |
284 |
|
} else if(e.getNewValue() == "expanding/collapsing") { |
285 |
|
ensureChannelIsVisible(); |
286 |
|
} |
287 |
|
} |
288 |
|
}); |
289 |
|
} |
290 |
|
|
291 |
mainPane.setAnimated(false); |
mainPane.setAnimated(false); |
292 |
mainPane.setCollapsed(true); |
mainPane.setCollapsed(true); |
293 |
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
299 |
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
300 |
} |
} |
301 |
}); |
}); |
302 |
|
|
303 |
|
if(listener != null) { |
304 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
305 |
|
public void |
306 |
|
run() { listener.actionPerformed(null); } |
307 |
|
}); |
308 |
|
} |
309 |
|
|
310 |
|
CC.getSamplerModel().addSamplerChannelListListener(getHandler()); |
311 |
|
} |
312 |
|
|
313 |
|
private void |
314 |
|
ensureChannelIsVisible() { |
315 |
|
Container p = getParent(); |
316 |
|
JScrollPane sp = null; |
317 |
|
while(p != null) { |
318 |
|
if(p instanceof JScrollPane) { |
319 |
|
sp = (JScrollPane)p; |
320 |
|
break; |
321 |
|
} |
322 |
|
p = p.getParent(); |
323 |
|
} |
324 |
|
if(sp == null) return; |
325 |
|
int h = sp.getViewport().getView().getHeight(); |
326 |
|
sp.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1)); |
327 |
} |
} |
328 |
|
|
329 |
private JPanel |
private JPanel |
381 |
|
|
382 |
if(vol == dialVolume.getValue()) return; |
if(vol == dialVolume.getValue()) return; |
383 |
|
|
|
|
|
384 |
/* |
/* |
385 |
* If the model's volume is not equal to the dial knob |
* If the model's volume is not equal to the dial knob |
386 |
* value we assume that the change is due to user input. |
* value we assume that the change is due to user input. |
404 |
|
|
405 |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn); |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn); |
406 |
else btnSolo.setIcon(Res.gfxSoloOff); |
else btnSolo.setIcon(Res.gfxSoloOff); |
|
|
|
407 |
dialVolume.setValue((int)(sc.getVolume() * 100)); |
dialVolume.setValue((int)(sc.getVolume() * 100)); |
408 |
|
|
409 |
boolean b = sc.getEngine() != null; |
boolean b = sc.getEngine() != null; |
427 |
|
|
428 |
private class EnhancedDial extends Dial { |
private class EnhancedDial extends Dial { |
429 |
EnhancedDial() { |
EnhancedDial() { |
430 |
super(0, 100); |
super(0, 100, 0); |
431 |
|
|
432 |
setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP); |
setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP); |
433 |
|
|
434 |
|
int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
435 |
|
setMaximum(i); |
436 |
|
String mcv = MAXIMUM_CHANNEL_VOLUME; |
437 |
|
preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() { |
438 |
|
public void |
439 |
|
propertyChange(PropertyChangeEvent e) { |
440 |
|
int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
441 |
|
setMaximum(j); |
442 |
|
} |
443 |
|
}); |
444 |
|
|
445 |
addMouseListener(new MouseAdapter() { |
addMouseListener(new MouseAdapter() { |
446 |
public void |
public void |
447 |
mouseClicked(MouseEvent e) { |
mouseClicked(MouseEvent e) { |
464 |
} |
} |
465 |
} |
} |
466 |
|
|
467 |
|
protected void |
468 |
|
onDestroy() { |
469 |
|
CC.getSamplerModel().removeSamplerChannelListListener(getHandler()); |
470 |
|
|
471 |
|
screen.onDestroy(); |
472 |
|
optionsPane.onDestroy(); |
473 |
|
} |
474 |
|
|
475 |
private final EventHandler eventHandler = new EventHandler(); |
private final EventHandler eventHandler = new EventHandler(); |
476 |
|
|
477 |
private EventHandler |
private EventHandler |
478 |
getHandler() { return eventHandler; } |
getHandler() { return eventHandler; } |
479 |
|
|
480 |
private class EventHandler implements SamplerChannelListener { |
private class EventHandler implements SamplerChannelListener, SamplerChannelListListener { |
481 |
/** |
/** |
482 |
* Invoked when changes are made to a sampler channel. |
* Invoked when changes are made to a sampler channel. |
483 |
* @param e A <code>SamplerChannelEvent</code> instance |
* @param e A <code>SamplerChannelEvent</code> instance |
505 |
voiceCountChanged(SamplerChannelEvent e) { |
voiceCountChanged(SamplerChannelEvent e) { |
506 |
screen.updateVoiceCount(getModel().getVoiceCount()); |
screen.updateVoiceCount(getModel().getVoiceCount()); |
507 |
} |
} |
508 |
|
|
509 |
|
/** |
510 |
|
* Invoked when a new sampler channel is created. |
511 |
|
* @param e A <code>SamplerChannelListEvent</code> |
512 |
|
* instance providing the event information. |
513 |
|
*/ |
514 |
|
public void |
515 |
|
channelAdded(SamplerChannelListEvent e) { } |
516 |
|
|
517 |
|
/** |
518 |
|
* Invoked when a sampler channel is removed. |
519 |
|
* @param e A <code>SamplerChannelListEvent</code> |
520 |
|
* instance providing the event information. |
521 |
|
*/ |
522 |
|
public void |
523 |
|
channelRemoved(SamplerChannelListEvent e) { |
524 |
|
// Some cleanup when the channel is removed. |
525 |
|
if(e.getChannelModel().getChannelId() == getChannelId()) { |
526 |
|
onDestroy(); |
527 |
|
} |
528 |
|
} |
529 |
} |
} |
530 |
|
|
531 |
|
|
537 |
|
|
538 |
setSelected(true); |
setSelected(true); |
539 |
addActionListener(this); |
addActionListener(this); |
540 |
|
setToolTipText(i18n.getButtonLabel("Channel.ttRemoveChannel")); |
541 |
} |
} |
542 |
|
|
543 |
public void |
public void |
544 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
545 |
|
boolean b = preferences().getBoolProperty(CONFIRM_CHANNEL_REMOVAL); |
546 |
|
if(b) { |
547 |
|
String s = i18n.getMessage("Channel.remove?", getChannelId()); |
548 |
|
if(!HF.showYesNoDialog(Channel.this, s)) { |
549 |
|
setSelected(true); |
550 |
|
return; |
551 |
|
} |
552 |
|
} |
553 |
|
remove(); |
554 |
|
} |
555 |
|
|
556 |
|
private void |
557 |
|
remove() { |
558 |
if(!mainPane.isAnimated()) { |
if(!mainPane.isAnimated()) { |
559 |
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
560 |
return; |
return; |
651 |
setRolloverIcon(Res.gfxOptionsOffRO); |
setRolloverIcon(Res.gfxOptionsOffRO); |
652 |
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
653 |
addActionListener(this); |
addActionListener(this); |
654 |
|
setToolTipText(i18n.getButtonLabel("Channel.ttShowOptions")); |
655 |
} |
} |
656 |
|
|
657 |
public void |
public void |
659 |
showOptionsPane(isSelected()); |
showOptionsPane(isSelected()); |
660 |
|
|
661 |
String s; |
String s; |
662 |
if(isSelected()) s = i18n.getButtonLabel("OptionsButton.ttHideOptions"); |
if(isSelected()) s = i18n.getButtonLabel("Channel.ttHideOptions"); |
663 |
else s = i18n.getButtonLabel("OptionsButton.ttShowOptions"); |
else s = i18n.getButtonLabel("Channel.ttShowOptions"); |
664 |
|
|
665 |
setToolTipText(s); |
setToolTipText(s); |
666 |
} |
} |
684 |
|
|
685 |
class ChannelScreen extends PixmapPane { |
class ChannelScreen extends PixmapPane { |
686 |
private final Channel channel; |
private final Channel channel; |
687 |
private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
|
688 |
|
private final InstrumentPane instrumentPane; |
689 |
|
|
690 |
|
private JButton btnInstr = |
691 |
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
692 |
|
|
693 |
|
private final JButton btnEditInstr = |
694 |
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
695 |
|
private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr); |
696 |
|
|
697 |
private final JButton btnFxSends = |
private final JButton btnFxSends = |
698 |
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends")); |
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends")); |
699 |
|
|
700 |
private final JButton btnEngine |
private final JButton btnEngine |
701 |
= new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine")); |
= createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine")); |
702 |
|
|
703 |
private final JPopupMenu menuEngines = new JPopupMenu(); |
private final JPopupMenu menuEngines = new JPopupMenu(); |
704 |
|
|
705 |
private final JLabel lVolume = new Label(); |
private final JButton btnVolume = createScreenButton(""); |
706 |
private final JLabel lStreams = new Label("--"); |
private JSVolumeEditorPopup popupVolume; |
707 |
private final JLabel lVoices = new Label("--"); |
|
708 |
|
private final JLabel lStreams = createScreenLabel(" --"); |
709 |
|
private final JLabel lVoices = createScreenLabel("-- "); |
710 |
|
|
711 |
private InformationDialog fxSendsDlg = null; |
private InformationDialog fxSendsDlg = null; |
712 |
|
|
713 |
private Dimension dimVolume; |
private Timer timer; |
714 |
|
|
715 |
class Label extends JLabel { |
private static NumberFormat numberFormat = NumberFormat.getInstance(); |
716 |
Label() { this(""); } |
static { |
717 |
|
numberFormat.setMaximumFractionDigits(1); |
|
Label(String s) { |
|
|
super(s); |
|
|
setFont(Res.fontScreen); |
|
|
setForeground(new java.awt.Color(0xFFA300)); |
|
|
} |
|
718 |
} |
} |
719 |
|
|
720 |
ChannelScreen(final Channel channel) { |
ChannelScreen(final Channel channel) { |
723 |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
724 |
|
|
725 |
this.channel = channel; |
this.channel = channel; |
726 |
|
popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.CHANNEL); |
727 |
|
|
728 |
setOpaque(false); |
setOpaque(false); |
729 |
|
|
733 |
btnInstr.setRolloverEnabled(false); |
btnInstr.setRolloverEnabled(false); |
734 |
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
735 |
|
|
736 |
add(btnInstr); |
instrumentPane = new InstrumentPane(); |
737 |
|
add(instrumentPane); |
738 |
|
|
739 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
740 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
741 |
p.setAlignmentX(CENTER_ALIGNMENT); |
p.setAlignmentX(CENTER_ALIGNMENT); |
742 |
p.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); |
p.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 0)); |
743 |
|
|
744 |
btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt")); |
btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt")); |
745 |
btnFxSends.addActionListener(new ActionListener() { |
btnFxSends.addActionListener(new ActionListener() { |
761 |
|
|
762 |
p.add(btnFxSends); |
p.add(btnFxSends); |
763 |
|
|
764 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
765 |
|
p.add(Box.createGlue()); |
766 |
|
|
767 |
btnEngine.setIcon(Res.iconEngine12); |
btnEngine.setIcon(Res.iconEngine12); |
768 |
|
btnEngine.setIconTextGap(1); |
769 |
p.add(btnEngine); |
p.add(btnEngine); |
770 |
//p.add(new Label("|")); |
//p.add(new Label("|")); |
771 |
|
|
775 |
|
|
776 |
p.add(Box.createGlue()); |
p.add(Box.createGlue()); |
777 |
|
|
778 |
|
lStreams.setFont(Res.fontScreenMono); |
779 |
|
lStreams.setHorizontalAlignment(JLabel.RIGHT); |
780 |
|
lStreams.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
781 |
p.add(lStreams); |
p.add(lStreams); |
|
p.add(new Label("/")); |
|
|
p.add(lVoices); |
|
782 |
|
|
783 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
JLabel l = createScreenLabel("/"); |
784 |
|
l.setFont(Res.fontScreenMono); |
785 |
|
l.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
786 |
|
p.add(l); |
787 |
|
|
788 |
|
lVoices.setFont(Res.fontScreenMono); |
789 |
|
lVoices.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
790 |
|
p.add(lVoices); |
791 |
|
|
792 |
lVolume.setIcon(Res.iconVolume14); |
btnVolume.setIcon(Res.iconVolume14); |
793 |
lVolume.setAlignmentX(RIGHT_ALIGNMENT); |
btnVolume.setIconTextGap(2); |
794 |
|
btnVolume.setAlignmentX(RIGHT_ALIGNMENT); |
795 |
|
btnVolume.setHorizontalAlignment(btnVolume.LEFT); |
796 |
updateVolumeInfo(100); |
updateVolumeInfo(100); |
797 |
dimVolume = lVolume.getPreferredSize(); |
Dimension d = btnVolume.getPreferredSize(); |
798 |
p.add(lVolume); |
d.width = 60; |
799 |
p.setPreferredSize(new Dimension(250, p.getPreferredSize().height)); |
btnVolume.setPreferredSize(d); |
800 |
|
btnVolume.setMinimumSize(d); |
801 |
|
|
802 |
|
btnVolume.addActionListener(new ActionListener() { |
803 |
|
public void |
804 |
|
actionPerformed(ActionEvent e) { |
805 |
|
if(popupVolume.isVisible()) { |
806 |
|
popupVolume.commit(); |
807 |
|
popupVolume.hide(); |
808 |
|
} else { |
809 |
|
float vol = channel.getModel().getChannelInfo().getVolume(); |
810 |
|
popupVolume.setCurrentVolume(vol); |
811 |
|
popupVolume.show(); |
812 |
|
} |
813 |
|
} |
814 |
|
}); |
815 |
|
|
816 |
|
popupVolume.addActionListener(new ActionListener() { |
817 |
|
public void |
818 |
|
actionPerformed(ActionEvent e) { |
819 |
|
channel.getModel().setBackendVolume(popupVolume.getVolumeFactor()); |
820 |
|
} |
821 |
|
}); |
822 |
|
|
823 |
|
p.add(btnVolume); |
824 |
|
p.setPreferredSize(new Dimension(260, p.getPreferredSize().height)); |
825 |
p.setMinimumSize(p.getPreferredSize()); |
p.setMinimumSize(p.getPreferredSize()); |
826 |
p.setMaximumSize(p.getPreferredSize()); |
p.setMaximumSize(p.getPreferredSize()); |
827 |
|
|
838 |
installListeners(); |
installListeners(); |
839 |
} |
} |
840 |
|
|
841 |
|
protected void |
842 |
|
onDestroy() { timer.stop(); } |
843 |
|
|
844 |
private void |
private void |
845 |
createEngineMenu() { |
createEngineMenu() { |
846 |
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) { |
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) { |
847 |
JMenuItem mi = new JMenuItem(engine.getDescription()); |
JMenuItem mi = new JMenuItem(engine.getName() + " engine"); |
848 |
|
mi.setToolTipText(engine.getDescription()); |
849 |
|
|
850 |
mi.addActionListener(new ActionListener() { |
mi.addActionListener(new ActionListener() { |
851 |
public void |
public void |
865 |
actionPerformed(ActionEvent e) { loadInstrument(); } |
actionPerformed(ActionEvent e) { loadInstrument(); } |
866 |
}); |
}); |
867 |
|
|
868 |
|
btnEditInstr.addActionListener(new ActionListener() { |
869 |
|
public void |
870 |
|
actionPerformed(ActionEvent e) { |
871 |
|
CC.getSamplerModel().editBackendInstrument(channel.getChannelId()); |
872 |
|
} |
873 |
|
}); |
874 |
|
|
875 |
btnEngine.addActionListener(new ActionListener() { |
btnEngine.addActionListener(new ActionListener() { |
876 |
public void |
public void |
877 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
879 |
menuEngines.show(btnEngine, 0, y); |
menuEngines.show(btnEngine, 0, y); |
880 |
} |
} |
881 |
}); |
}); |
882 |
|
|
883 |
|
addMouseListener(getHandler()); |
884 |
|
addHierarchyListener(getHandler()); |
885 |
|
|
886 |
|
ActionListener l = new ActionListener() { |
887 |
|
public void |
888 |
|
actionPerformed(ActionEvent e) { |
889 |
|
if(getMousePosition(true) != null) { |
890 |
|
getHandler().mouseEntered(null); |
891 |
|
} else { |
892 |
|
getHandler().mouseExited(null); |
893 |
|
} |
894 |
|
} |
895 |
|
}; |
896 |
|
timer = new Timer(1000, l); |
897 |
|
timer.start(); |
898 |
} |
} |
899 |
|
|
900 |
private void |
private void |
901 |
loadInstrument() { |
loadInstrument() { |
902 |
JSInstrumentChooser dlg = new JSInstrumentChooser(CC.getMainFrame()); |
JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame()); |
903 |
dlg.setVisible(true); |
dlg.setVisible(true); |
904 |
|
|
905 |
if(!dlg.isCancelled()) { |
if(!dlg.isCancelled()) { |
921 |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
922 |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
923 |
} |
} |
924 |
|
|
925 |
|
instrumentPane.update(); |
926 |
|
|
927 |
if(sc.getEngine() != null) { |
if(sc.getEngine() != null) { |
928 |
String s = sc.getEngine().getDescription(); |
String s = sc.getEngine().getName(); |
929 |
if(!s.equals(btnEngine.getText())) btnEngine.setText(s); |
s += " engine"; |
930 |
|
if(!s.equals(btnEngine.getText())) { |
931 |
|
btnEngine.setText(s); |
932 |
|
btnEngine.setToolTipText(sc.getEngine().getDescription()); |
933 |
|
} |
934 |
} |
} |
935 |
|
|
936 |
} |
} |
937 |
|
|
938 |
protected void |
protected void |
939 |
updateVolumeInfo(int volume) { |
updateVolumeInfo(int volume) { |
940 |
lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume)); |
if(CC.getViewConfig().isMeasurementUnitDecibel()) { |
941 |
lVolume.setMinimumSize(dimVolume); |
String s = numberFormat.format(HF.percentsToDecibels(volume)); |
942 |
lVolume.setPreferredSize(dimVolume); |
btnVolume.setText(s + "dB"); |
943 |
|
} else { |
944 |
|
btnVolume.setText(String.valueOf(volume) + "%"); |
945 |
|
} |
946 |
} |
} |
947 |
|
|
948 |
/** |
/** |
973 |
lVoices.setMaximumSize(d); |
lVoices.setMaximumSize(d); |
974 |
} |
} |
975 |
|
|
976 |
|
class InstrumentPane extends JPanel { |
977 |
|
private final JPanel leftPane = new JPanel(); |
978 |
|
private final JPanel rightPane = new JPanel(); |
979 |
|
|
980 |
|
InstrumentPane() { |
981 |
|
setOpaque(false); |
982 |
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
983 |
|
add(leftPane); |
984 |
|
add(btnInstr); |
985 |
|
add(rightPane); |
986 |
|
add(sbbEditInstr); |
987 |
|
btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt")); |
988 |
|
sbbEditInstr.setVisible(false); |
989 |
|
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); |
990 |
|
|
991 |
|
update(); |
992 |
|
} |
993 |
|
|
994 |
|
public void |
995 |
|
update() { |
996 |
|
int a = btnInstr.getMinimumSize().width; |
997 |
|
int b = 0; |
998 |
|
if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width; |
999 |
|
|
1000 |
|
int max = 254 - b; |
1001 |
|
if(a > max) a = max; |
1002 |
|
|
1003 |
|
int h = btnInstr.getPreferredSize().height; |
1004 |
|
btnInstr.setPreferredSize(new Dimension(a, h)); |
1005 |
|
h = btnInstr.getMaximumSize().height; |
1006 |
|
btnInstr.setMaximumSize(new Dimension(a, h)); |
1007 |
|
|
1008 |
|
|
1009 |
|
int i = (254 - btnInstr.getPreferredSize().width) / 2; |
1010 |
|
|
1011 |
|
int j = i; |
1012 |
|
if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width; |
1013 |
|
if(i < 0 || j < 0) i = j = 0; |
1014 |
|
|
1015 |
|
Dimension d = new Dimension(i, 1); |
1016 |
|
leftPane.setMinimumSize(d); |
1017 |
|
leftPane.setPreferredSize(d); |
1018 |
|
leftPane.setMaximumSize(d); |
1019 |
|
|
1020 |
|
d = new Dimension(j, 1); |
1021 |
|
rightPane.setMinimumSize(d); |
1022 |
|
rightPane.setPreferredSize(d); |
1023 |
|
rightPane.setMaximumSize(d); |
1024 |
|
|
1025 |
|
validate(); |
1026 |
|
} |
1027 |
|
} |
1028 |
|
|
1029 |
class FxSendsPane extends JSFxSendsPane { |
class FxSendsPane extends JSFxSendsPane { |
1030 |
FxSendsPane(SamplerChannelModel model) { |
FxSendsPane(SamplerChannelModel model) { |
1031 |
super(model); |
super(model); |
1049 |
} |
} |
1050 |
} |
} |
1051 |
|
|
1052 |
static class ScreenButton extends JButton { |
static class ScreenButtonBg extends PixmapPane { |
1053 |
ScreenButton(String s) { |
ScreenButtonBg(JButton btn) { |
1054 |
super(s); |
super(Res.gfxScreenBtnBg); |
1055 |
setContentAreaFilled(false); |
setPixmapInsets(new Insets(4, 4, 4, 4)); |
1056 |
setFocusPainted(false); |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
1057 |
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7)); |
1058 |
setMargin(new Insets(0, 0, 0, 0)); |
add(btn); |
1059 |
|
setPreferredSize(new Dimension(getPreferredSize().width, 13)); |
1060 |
putClientProperty ( |
} |
1061 |
SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE |
|
1062 |
); |
public Dimension |
1063 |
|
getPreferredSize() { |
1064 |
putClientProperty ( |
return new Dimension(super.getPreferredSize().width, 13); |
1065 |
SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE |
} |
1066 |
); |
} |
1067 |
|
|
1068 |
putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE); |
|
1069 |
|
private final EventHandler eventHandler = new EventHandler(); |
1070 |
FadeConfigurationManager.getInstance().disallowFades(FadeKind.ROLLOVER, this); |
|
1071 |
|
private EventHandler |
1072 |
|
getHandler() { return eventHandler; } |
1073 |
|
|
1074 |
|
private class EventHandler extends MouseAdapter implements HierarchyListener { |
1075 |
|
public void |
1076 |
|
mouseEntered(MouseEvent e) { |
1077 |
|
if(channel.getChannelInfo().getInstrumentStatus() != 100) return; |
1078 |
|
|
1079 |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
if(!sbbEditInstr.isVisible()) { |
1080 |
setFont(Res.fontScreen); |
sbbEditInstr.setVisible(true); |
1081 |
setForeground(new java.awt.Color(0xFFA300)); |
instrumentPane.update(); |
1082 |
|
} |
1083 |
|
} |
1084 |
|
|
1085 |
|
public void |
1086 |
|
mouseExited(MouseEvent e) { |
1087 |
|
if(getMousePosition(true) != null) return; |
1088 |
|
if(sbbEditInstr.isVisible()) { |
1089 |
|
sbbEditInstr.setVisible(false); |
1090 |
|
instrumentPane.update(); |
1091 |
|
} |
1092 |
|
} |
1093 |
|
|
1094 |
|
/** Called when the hierarchy has been changed. */ |
1095 |
|
public void |
1096 |
|
hierarchyChanged(HierarchyEvent e) { |
1097 |
|
if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) { |
1098 |
|
if(getMousePosition() == null) mouseExited(null); |
1099 |
|
else mouseEntered(null); |
1100 |
|
} |
1101 |
} |
} |
1102 |
} |
} |
1103 |
} |
} |
1333 |
actionPerformed(ActionEvent e) { updateInstrumentMap(); } |
actionPerformed(ActionEvent e) { updateInstrumentMap(); } |
1334 |
}); |
}); |
1335 |
|
|
|
CC.getSamplerModel().addSamplerChannelListListener(getHandler()); |
|
1336 |
CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener); |
CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener); |
1337 |
|
|
1338 |
cbAudioDevice.addActionListener(new ActionListener() { |
cbAudioDevice.addActionListener(new ActionListener() { |
1566 |
private void |
private void |
1567 |
setUpdate(boolean b) { update = b; } |
setUpdate(boolean b) { update = b; } |
1568 |
|
|
1569 |
|
protected void |
1570 |
|
onDestroy() { |
1571 |
|
SamplerModel sm = CC.getSamplerModel(); |
1572 |
|
|
1573 |
|
sm.removeMidiDeviceListListener(getHandler()); |
1574 |
|
sm.removeAudioDeviceListListener(getHandler()); |
1575 |
|
sm.removeMidiInstrumentMapListListener(mapListListener); |
1576 |
|
sm.removeSamplerListener(samplerListener); |
1577 |
|
|
1578 |
|
if(midiDevice != null) { |
1579 |
|
midiDevice.removeMidiDeviceListener(getHandler()); |
1580 |
|
} |
1581 |
|
} |
1582 |
|
|
1583 |
private final Handler handler = new Handler(); |
private final Handler handler = new Handler(); |
1584 |
|
|
1585 |
private Handler |
private Handler |
1586 |
getHandler() { return handler; } |
getHandler() { return handler; } |
1587 |
|
|
1588 |
private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>, |
private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>, |
1589 |
SamplerChannelListListener, MidiDeviceListener { |
MidiDeviceListener { |
1590 |
/** |
/** |
1591 |
* Invoked when a new MIDI device is created. |
* Invoked when a new MIDI device is created. |
1592 |
* @param e A <code>MidiDeviceListEvent</code> |
* @param e A <code>MidiDeviceListEvent</code> |
1627 |
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo()); |
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo()); |
1628 |
} |
} |
1629 |
|
|
|
/** |
|
|
* 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()); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
1630 |
public void |
public void |
1631 |
settingsChanged(MidiDeviceEvent e) { |
settingsChanged(MidiDeviceEvent e) { |
1632 |
if(isUpdate()) { |
if(isUpdate()) { |