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 |
* |
* |
23 |
package org.jsampler.view.fantasia; |
package org.jsampler.view.fantasia; |
24 |
|
|
25 |
import java.awt.Container; |
import java.awt.Container; |
|
import java.awt.Cursor; |
|
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; |
import java.awt.Rectangle; |
31 |
|
|
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; |
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 |
/** |
/** |
254 |
|
|
255 |
setOpaque(false); |
setOpaque(false); |
256 |
|
|
257 |
int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
String vmud = VOL_MEASUREMENT_UNIT_DECIBEL; |
258 |
dialVolume.setMaximum(i); |
preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() { |
|
String mcv = MAXIMUM_CHANNEL_VOLUME; |
|
|
preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() { |
|
259 |
public void |
public void |
260 |
propertyChange(PropertyChangeEvent e) { |
propertyChange(PropertyChangeEvent e) { |
261 |
int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
boolean b; |
262 |
dialVolume.setMaximum(j); |
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
263 |
|
screen.updateVolumeInfo(dialVolume.getValue()); |
264 |
} |
} |
265 |
}); |
}); |
266 |
|
|
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) { |
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 |
} |
} |
686 |
private final Channel channel; |
private final Channel channel; |
687 |
|
|
688 |
private final InstrumentPane instrumentPane; |
private final InstrumentPane instrumentPane; |
689 |
private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
|
690 |
|
private JButton btnInstr = |
691 |
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
692 |
|
|
693 |
private final JButton btnEditInstr = |
private final JButton btnEditInstr = |
694 |
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
695 |
private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr); |
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; |
|
private final JLabel lVoices = new Label("--"); |
|
707 |
|
|
708 |
private InformationDialog fxSendsDlg = null; |
private final JLabel lStreams = createScreenLabel(" --"); |
709 |
|
private final JLabel lVoices = createScreenLabel("-- "); |
710 |
|
|
711 |
private Dimension dimVolume; |
private InformationDialog fxSendsDlg = null; |
712 |
|
|
713 |
private Timer timer; |
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 |
|
|
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 |
lVolume.setIcon(Res.iconVolume14); |
lVoices.setFont(Res.fontScreenMono); |
789 |
lVolume.setAlignmentX(RIGHT_ALIGNMENT); |
lVoices.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
790 |
|
p.add(lVoices); |
791 |
|
|
792 |
|
btnVolume.setIcon(Res.iconVolume14); |
793 |
|
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 |
|
|
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 |
925 |
instrumentPane.update(); |
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 |
/** |
/** |
1049 |
} |
} |
1050 |
} |
} |
1051 |
|
|
|
static class ScreenButton extends JButton { |
|
|
ScreenButton(String s) { |
|
|
super(s); |
|
|
setContentAreaFilled(false); |
|
|
setFocusPainted(false); |
|
|
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
|
setMargin(new Insets(0, 0, 0, 0)); |
|
|
|
|
|
putClientProperty ( |
|
|
SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE |
|
|
); |
|
|
|
|
|
putClientProperty ( |
|
|
SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE |
|
|
); |
|
|
|
|
|
putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE); |
|
|
|
|
|
FadeConfigurationManager.getInstance().disallowFades(FadeKind.ROLLOVER, this); |
|
|
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
|
|
setFont(Res.fontScreen); |
|
|
setForeground(new java.awt.Color(0xFFA300)); |
|
|
} |
|
|
} |
|
|
|
|
1052 |
static class ScreenButtonBg extends PixmapPane { |
static class ScreenButtonBg extends PixmapPane { |
1053 |
ScreenButtonBg(JButton btn) { |
ScreenButtonBg(JButton btn) { |
1054 |
super(Res.gfxScreenBtnBg); |
super(Res.gfxScreenBtnBg); |
1065 |
} |
} |
1066 |
} |
} |
1067 |
|
|
1068 |
|
|
1069 |
private final EventHandler eventHandler = new EventHandler(); |
private final EventHandler eventHandler = new EventHandler(); |
1070 |
|
|
1071 |
private EventHandler |
private EventHandler |