1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
24 |
|
|
25 |
import java.awt.Cursor; |
import java.awt.Cursor; |
26 |
import java.awt.Dimension; |
import java.awt.Dimension; |
27 |
|
import java.awt.Graphics; |
28 |
import java.awt.Insets; |
import java.awt.Insets; |
29 |
|
|
30 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
32 |
|
import java.awt.event.HierarchyEvent; |
33 |
|
import java.awt.event.HierarchyListener; |
34 |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
35 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
36 |
|
|
37 |
|
import java.beans.PropertyChangeEvent; |
38 |
|
import java.beans.PropertyChangeListener; |
39 |
|
|
40 |
import java.util.logging.Level; |
import java.util.logging.Level; |
41 |
|
|
42 |
|
import javax.swing.Action; |
43 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
44 |
import javax.swing.Box; |
import javax.swing.Box; |
45 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
47 |
import javax.swing.JButton; |
import javax.swing.JButton; |
48 |
import javax.swing.JComboBox; |
import javax.swing.JComboBox; |
49 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
50 |
|
import javax.swing.JMenuItem; |
51 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
52 |
|
import javax.swing.JPopupMenu; |
53 |
import javax.swing.JToggleButton; |
import javax.swing.JToggleButton; |
54 |
|
import javax.swing.JToolBar; |
55 |
import javax.swing.SwingConstants; |
import javax.swing.SwingConstants; |
56 |
|
import javax.swing.Timer; |
57 |
|
|
58 |
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeEvent; |
59 |
import javax.swing.event.ChangeListener; |
import javax.swing.event.ChangeListener; |
60 |
|
|
61 |
import net.sf.juife.Dial; |
import net.sf.juife.Dial; |
62 |
|
import net.sf.juife.InformationDialog; |
63 |
import net.sf.juife.JuifeUtils; |
import net.sf.juife.JuifeUtils; |
64 |
import net.sf.juife.TitleBar; |
import net.sf.juife.TitleBar; |
65 |
|
|
66 |
|
import org.jdesktop.swingx.JXCollapsiblePane; |
67 |
|
|
68 |
import org.jsampler.AudioDeviceModel; |
import org.jsampler.AudioDeviceModel; |
69 |
import org.jsampler.CC; |
import org.jsampler.CC; |
70 |
import org.jsampler.MidiDeviceModel; |
import org.jsampler.MidiDeviceModel; |
71 |
|
import org.jsampler.MidiInstrumentMap; |
72 |
import org.jsampler.SamplerChannelModel; |
import org.jsampler.SamplerChannelModel; |
73 |
import org.jsampler.SamplerModel; |
import org.jsampler.SamplerModel; |
74 |
|
|
75 |
import org.jsampler.event.ListEvent; |
import org.jsampler.event.ListEvent; |
76 |
import org.jsampler.event.ListListener; |
import org.jsampler.event.ListListener; |
77 |
|
import org.jsampler.event.MidiDeviceEvent; |
78 |
import org.jsampler.event.MidiDeviceListEvent; |
import org.jsampler.event.MidiDeviceListEvent; |
79 |
import org.jsampler.event.MidiDeviceListListener; |
import org.jsampler.event.MidiDeviceListListener; |
80 |
|
import org.jsampler.event.MidiDeviceListener; |
81 |
|
import org.jsampler.event.SamplerAdapter; |
82 |
import org.jsampler.event.SamplerChannelAdapter; |
import org.jsampler.event.SamplerChannelAdapter; |
83 |
import org.jsampler.event.SamplerChannelEvent; |
import org.jsampler.event.SamplerChannelEvent; |
84 |
|
import org.jsampler.event.SamplerChannelListEvent; |
85 |
|
import org.jsampler.event.SamplerChannelListListener; |
86 |
import org.jsampler.event.SamplerChannelListener; |
import org.jsampler.event.SamplerChannelListener; |
87 |
|
import org.jsampler.event.SamplerEvent; |
88 |
|
import org.jsampler.event.SamplerListener; |
89 |
|
|
90 |
|
import org.jsampler.view.std.JSChannelOutputRoutingDlg; |
91 |
|
import org.jsampler.view.std.JSFxSendsPane; |
92 |
|
import org.jsampler.view.std.JSInstrumentChooser; |
93 |
|
|
94 |
|
import org.jvnet.lafwidget.animation.FadeConfigurationManager; |
95 |
|
import org.jvnet.lafwidget.animation.FadeKind; |
96 |
|
|
97 |
|
import org.jvnet.substance.SubstanceImageCreator; |
98 |
|
import org.jvnet.substance.SubstanceLookAndFeel; |
99 |
|
|
100 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
101 |
import org.linuxsampler.lscp.MidiInputDevice; |
import org.linuxsampler.lscp.MidiInputDevice; |
104 |
import org.linuxsampler.lscp.SamplerEngine; |
import org.linuxsampler.lscp.SamplerEngine; |
105 |
|
|
106 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
107 |
|
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
108 |
|
|
109 |
|
|
110 |
/** |
/** |
112 |
* @author Grigor Iliev |
* @author Grigor Iliev |
113 |
*/ |
*/ |
114 |
public class Channel extends org.jsampler.view.JSChannel { |
public class Channel extends org.jsampler.view.JSChannel { |
115 |
|
private final JXCollapsiblePane mainPane; |
116 |
private final ChannelScreen screen = new ChannelScreen(this); |
private final ChannelScreen screen = new ChannelScreen(this); |
117 |
private final ChannelOptions optionsPane = new ChannelOptions(this); |
private final ChannelOptions optionsPane = new ChannelOptions(this); |
118 |
|
|
133 |
*/ |
*/ |
134 |
public |
public |
135 |
Channel(SamplerChannelModel model) { |
Channel(SamplerChannelModel model) { |
136 |
|
this(model, null); |
137 |
|
} |
138 |
|
|
139 |
|
/** |
140 |
|
* Creates a new instance of <code>Channel</code> using the specified |
141 |
|
* non-<code>null</code> channel model. |
142 |
|
* @param model The model to be used by this channel. |
143 |
|
* @param listener A listener which is notified when the newly created |
144 |
|
* channel is fully expanded on the screen. |
145 |
|
* @throws IllegalArgumentException If the model is <code>null</code>. |
146 |
|
*/ |
147 |
|
public |
148 |
|
Channel(SamplerChannelModel model, final ActionListener listener) { |
149 |
super(model); |
super(model); |
150 |
|
|
151 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
152 |
JPanel p = new JPanel(); |
ChannelPane p = new ChannelPane(); |
|
p.setName("Channel"); |
|
153 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
154 |
|
|
155 |
//p.add(Box.createRigidArea(new Dimension(3, 0))); |
//p.add(Box.createRigidArea(new Dimension(3, 0))); |
156 |
|
|
157 |
btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT); |
btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT); |
158 |
|
|
159 |
TitleBar tb = new TitleBar(); |
JPanel tb = new JPanel(); |
160 |
tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4)); |
tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4)); |
161 |
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
162 |
tb.setOpaque(false); |
tb.setOpaque(false); |
188 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
189 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
190 |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
191 |
p2.add(new JLabel(Res.iconMuteTitle)); |
p2.add(new JLabel(Res.gfxMuteTitle)); |
192 |
p2.add(btnMute); |
p2.add(btnMute); |
193 |
p2.add(new JLabel(Res.iconSoloTitle)); |
p2.add(new JLabel(Res.gfxSoloTitle)); |
194 |
p2.add(btnSolo); |
p2.add(btnSolo); |
195 |
|
|
196 |
p.add(p2); |
p.add(p2); |
202 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
203 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
204 |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
205 |
JLabel l = new JLabel(Res.iconVolumeTitle); |
JLabel l = new JLabel(Res.gfxVolumeTitle); |
206 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
207 |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
208 |
p2.add(l); |
p2.add(l); |
209 |
dialVolume.setDialPixmap(Res.iconVolumeDial, 30, 330); |
dialVolume.setDialPixmap(Res.gfxVolumeDial, 30, 330); |
210 |
dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
211 |
p2.add(dialVolume); |
p2.add(dialVolume); |
212 |
p.add(p2); |
p.add(p2); |
218 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
219 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
220 |
p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0)); |
p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0)); |
221 |
l = new JLabel(Res.iconOptionsTitle); |
l = new JLabel(Res.gfxOptionsTitle); |
222 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
223 |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
224 |
p2.add(l); |
p2.add(l); |
237 |
|
|
238 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
239 |
optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
|
add(p); |
|
|
add(optionsPane); |
|
240 |
|
|
241 |
setOpaque(true); |
mainPane = new JXCollapsiblePane(); |
242 |
|
mainPane.getContentPane().setLayout ( |
243 |
|
new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS) |
244 |
|
); |
245 |
|
|
246 |
|
mainPane.add(p); |
247 |
|
mainPane.add(optionsPane); |
248 |
|
|
249 |
|
setOpaque(false); |
250 |
|
|
251 |
|
int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
252 |
|
dialVolume.setMaximum(i); |
253 |
|
String mcv = MAXIMUM_CHANNEL_VOLUME; |
254 |
|
preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() { |
255 |
|
public void |
256 |
|
propertyChange(PropertyChangeEvent e) { |
257 |
|
int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
258 |
|
dialVolume.setMaximum(j); |
259 |
|
} |
260 |
|
}); |
261 |
|
|
262 |
getModel().addSamplerChannelListener(getHandler()); |
getModel().addSamplerChannelListener(getHandler()); |
263 |
|
|
264 |
updateChannelInfo(); |
updateChannelInfo(); |
265 |
|
|
266 |
|
add(mainPane); |
267 |
|
|
268 |
|
if(listener != null) { |
269 |
|
final String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
270 |
|
mainPane.addPropertyChangeListener(s, new PropertyChangeListener() { |
271 |
|
public void |
272 |
|
propertyChange(PropertyChangeEvent e) { |
273 |
|
if(e.getNewValue() == "expanded") { |
274 |
|
mainPane.removePropertyChangeListener(s, this); |
275 |
|
listener.actionPerformed(null); |
276 |
|
} |
277 |
|
} |
278 |
|
}); |
279 |
|
} |
280 |
|
|
281 |
|
mainPane.setAnimated(false); |
282 |
|
mainPane.setCollapsed(true); |
283 |
|
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
284 |
|
mainPane.setCollapsed(false); |
285 |
|
|
286 |
|
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
287 |
|
public void |
288 |
|
propertyChange(PropertyChangeEvent e) { |
289 |
|
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
290 |
|
} |
291 |
|
}); |
292 |
|
|
293 |
|
if(listener != null) { |
294 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
295 |
|
public void |
296 |
|
run() { listener.actionPerformed(null); } |
297 |
|
}); |
298 |
|
} |
299 |
|
|
300 |
|
CC.getSamplerModel().addSamplerChannelListListener(getHandler()); |
301 |
} |
} |
302 |
|
|
303 |
private JPanel |
private JPanel |
304 |
createVSeparator() { |
createVSeparator() { |
305 |
JPanel p = new JPanel(); |
PixmapPane p = new PixmapPane(Res.gfxVLine); |
|
p.setName("VSeparator"); |
|
|
p.setOpaque(false); |
|
306 |
p.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p.setAlignmentY(JPanel.TOP_ALIGNMENT); |
307 |
p.setPreferredSize(new Dimension(2, 60)); |
p.setPreferredSize(new Dimension(2, 60)); |
308 |
p.setMinimumSize(p.getPreferredSize()); |
p.setMinimumSize(p.getPreferredSize()); |
330 |
|
|
331 |
/** Shows the channel properties. */ |
/** Shows the channel properties. */ |
332 |
public void |
public void |
333 |
expandChannel() { if(!btnOptions.isSelected()) btnOptions.doClick(); } |
expandChannel() { expandChannel(optionsPane.isAnimated()); } |
334 |
|
|
335 |
|
/** Shows the channel properties. */ |
336 |
|
public void |
337 |
|
expandChannel(boolean animated) { |
338 |
|
if(btnOptions.isSelected()) return; |
339 |
|
|
340 |
|
boolean b = optionsPane.isAnimated(); |
341 |
|
optionsPane.setAnimated(animated); |
342 |
|
btnOptions.doClick(); |
343 |
|
optionsPane.setAnimated(b); |
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
/** Invoked when the user changes the volume */ |
/** Invoked when the user changes the volume */ |
377 |
screen.updateScreenInfo(sc); |
screen.updateScreenInfo(sc); |
378 |
updateMuteIcon(sc); |
updateMuteIcon(sc); |
379 |
|
|
380 |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.iconSoloOn); |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn); |
381 |
else btnSolo.setIcon(Res.iconSoloOff); |
else btnSolo.setIcon(Res.gfxSoloOff); |
382 |
|
|
383 |
dialVolume.setValue((int)(sc.getVolume() * 100)); |
dialVolume.setValue((int)(sc.getVolume() * 100)); |
384 |
|
|
396 |
*/ |
*/ |
397 |
private void |
private void |
398 |
updateMuteIcon(SamplerChannel channel) { |
updateMuteIcon(SamplerChannel channel) { |
399 |
if(channel.isMutedBySolo()) btnMute.setIcon(Res.iconMutedBySolo); |
if(channel.isMutedBySolo()) btnMute.setIcon(Res.gfxMutedBySolo); |
400 |
else if(channel.isMuted()) btnMute.setIcon(Res.iconMuteOn); |
else if(channel.isMuted()) btnMute.setIcon(Res.gfxMuteOn); |
401 |
else btnMute.setIcon(Res.iconMuteOff); |
else btnMute.setIcon(Res.gfxMuteOff); |
402 |
} |
} |
403 |
|
|
404 |
private class EnhancedDial extends Dial { |
private class EnhancedDial extends Dial { |
429 |
} |
} |
430 |
} |
} |
431 |
|
|
432 |
|
protected void |
433 |
|
onDestroy() { |
434 |
|
CC.getSamplerModel().removeSamplerChannelListListener(getHandler()); |
435 |
|
|
436 |
|
screen.onDestroy(); |
437 |
|
optionsPane.onDestroy(); |
438 |
|
} |
439 |
|
|
440 |
private final EventHandler eventHandler = new EventHandler(); |
private final EventHandler eventHandler = new EventHandler(); |
441 |
|
|
442 |
private EventHandler |
private EventHandler |
443 |
getHandler() { return eventHandler; } |
getHandler() { return eventHandler; } |
444 |
|
|
445 |
private class EventHandler implements SamplerChannelListener { |
private class EventHandler implements SamplerChannelListener, SamplerChannelListListener { |
446 |
/** |
/** |
447 |
* Invoked when changes are made to a sampler channel. |
* Invoked when changes are made to a sampler channel. |
448 |
* @param e A <code>SamplerChannelEvent</code> instance |
* @param e A <code>SamplerChannelEvent</code> instance |
470 |
voiceCountChanged(SamplerChannelEvent e) { |
voiceCountChanged(SamplerChannelEvent e) { |
471 |
screen.updateVoiceCount(getModel().getVoiceCount()); |
screen.updateVoiceCount(getModel().getVoiceCount()); |
472 |
} |
} |
473 |
|
|
474 |
|
/** |
475 |
|
* Invoked when a new sampler channel is created. |
476 |
|
* @param e A <code>SamplerChannelListEvent</code> |
477 |
|
* instance providing the event information. |
478 |
|
*/ |
479 |
|
public void |
480 |
|
channelAdded(SamplerChannelListEvent e) { } |
481 |
|
|
482 |
|
/** |
483 |
|
* Invoked when a sampler channel is removed. |
484 |
|
* @param e A <code>SamplerChannelListEvent</code> |
485 |
|
* instance providing the event information. |
486 |
|
*/ |
487 |
|
public void |
488 |
|
channelRemoved(SamplerChannelListEvent e) { |
489 |
|
// Some cleanup when the channel is removed. |
490 |
|
if(e.getChannelModel().getChannelId() == getChannelId()) { |
491 |
|
onDestroy(); |
492 |
|
} |
493 |
|
} |
494 |
} |
} |
495 |
|
|
496 |
|
|
497 |
private class PowerButton extends PixmapToggleButton implements ActionListener { |
private class PowerButton extends PixmapToggleButton |
498 |
|
implements ActionListener, PropertyChangeListener { |
499 |
|
|
500 |
PowerButton() { |
PowerButton() { |
501 |
super(Res.iconPowerOff, Res.iconPowerOn); |
super(Res.gfxPowerOff, Res.gfxPowerOn); |
502 |
|
|
503 |
setSelected(true); |
setSelected(true); |
504 |
addActionListener(this); |
addActionListener(this); |
506 |
|
|
507 |
public void |
public void |
508 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
509 |
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
if(!mainPane.isAnimated()) { |
510 |
|
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
511 |
|
return; |
512 |
|
} |
513 |
|
|
514 |
|
String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
515 |
|
mainPane.addPropertyChangeListener(s, this); |
516 |
|
mainPane.setCollapsed(true); |
517 |
|
} |
518 |
|
|
519 |
|
public void |
520 |
|
propertyChange(PropertyChangeEvent e) { |
521 |
|
if(e.getNewValue() == "collapsed") { |
522 |
|
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
523 |
|
} |
524 |
} |
} |
525 |
|
|
526 |
public boolean |
public boolean |
529 |
|
|
530 |
private class MuteButton extends PixmapButton implements ActionListener { |
private class MuteButton extends PixmapButton implements ActionListener { |
531 |
MuteButton() { |
MuteButton() { |
532 |
super(Res.iconMuteOff); |
super(Res.gfxMuteOff); |
533 |
setDisabledIcon(Res.iconMuteSoloDisabled); |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
534 |
|
setDisabledIcon ( |
535 |
|
SubstanceImageCreator.makeTransparent(this, Res.gfxMuteOff, 0.4) |
536 |
|
); |
537 |
addActionListener(this); |
addActionListener(this); |
538 |
} |
} |
539 |
|
|
550 |
b = false; |
b = false; |
551 |
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
552 |
|
|
553 |
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.iconMuteOff); |
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.gfxMuteOff); |
554 |
else setIcon(Res.iconMutedBySolo); |
else setIcon(Res.gfxMutedBySolo); |
555 |
} else setIcon(Res.iconMuteOn); |
} else setIcon(Res.gfxMuteOn); |
556 |
|
|
557 |
Channel.this.getModel().setBackendMute(b); |
Channel.this.getModel().setBackendMute(b); |
558 |
} |
} |
563 |
|
|
564 |
private class SoloButton extends PixmapButton implements ActionListener { |
private class SoloButton extends PixmapButton implements ActionListener { |
565 |
SoloButton() { |
SoloButton() { |
566 |
super(Res.iconSoloOff); |
super(Res.gfxSoloOff); |
567 |
setDisabledIcon(Res.iconMuteSoloDisabled); |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
568 |
|
setDisabledIcon ( |
569 |
|
SubstanceImageCreator.makeTransparent(this, Res.gfxSoloOff, 0.4) |
570 |
|
); |
571 |
addActionListener(this); |
addActionListener(this); |
572 |
} |
} |
573 |
|
|
581 |
* leaving the work to the notification mechanism of the LinuxSampler. |
* leaving the work to the notification mechanism of the LinuxSampler. |
582 |
*/ |
*/ |
583 |
if(b) { |
if(b) { |
584 |
setIcon(Res.iconSoloOn); |
setIcon(Res.gfxSoloOn); |
585 |
if(sc.isMutedBySolo()) btnMute.setIcon(Res.iconMuteOff); |
if(sc.isMutedBySolo()) btnMute.setIcon(Res.gfxMuteOff); |
586 |
} else { |
} else { |
587 |
setIcon(Res.iconSoloOff); |
setIcon(Res.gfxSoloOff); |
588 |
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
589 |
btnMute.setIcon(Res.iconMutedBySolo); |
btnMute.setIcon(Res.gfxMutedBySolo); |
590 |
} |
} |
591 |
|
|
592 |
Channel.this.getModel().setBackendSolo(b); |
Channel.this.getModel().setBackendSolo(b); |
598 |
|
|
599 |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
600 |
OptionsButton() { |
OptionsButton() { |
601 |
super(Res.iconOptionsOff, Res.iconOptionsOn); |
super(Res.gfxOptionsOff, Res.gfxOptionsOn); |
602 |
setRolloverIcon(Res.iconOptionsOffRO); |
setRolloverIcon(Res.gfxOptionsOffRO); |
603 |
this.setRolloverSelectedIcon(Res.iconOptionsOnRO); |
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
604 |
addActionListener(this); |
addActionListener(this); |
605 |
} |
} |
606 |
|
|
617 |
|
|
618 |
private void |
private void |
619 |
showOptionsPane(boolean show) { |
showOptionsPane(boolean show) { |
620 |
optionsPane.setVisible(show); |
optionsPane.setCollapsed(!show); |
|
MainFrame.repack(CC.getMainFrame()); |
|
621 |
} |
} |
622 |
|
|
623 |
public boolean |
public boolean |
625 |
} |
} |
626 |
} |
} |
627 |
|
|
628 |
class ChannelScreen extends JPanel { |
class ChannelPane extends PixmapPane { |
629 |
|
ChannelPane() { |
630 |
|
super(Res.gfxChannel); |
631 |
|
setPixmapInsets(new Insets(3, 3, 3, 3)); |
632 |
|
} |
633 |
|
} |
634 |
|
|
635 |
|
class ChannelScreen extends PixmapPane { |
636 |
private final Channel channel; |
private final Channel channel; |
637 |
|
|
638 |
|
private final InstrumentPane instrumentPane; |
639 |
private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
|
private JButton btnReset = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnReset")); |
|
|
private JButton btnDuplicate = |
|
|
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnDuplicate")); |
|
|
|
|
|
private final JLabel lVolume = new JLabel(); |
|
|
private final JLabel lStreams = new JLabel("--"); |
|
|
private final JLabel lVoices = new JLabel("--"); |
|
640 |
|
|
641 |
ChannelScreen(Channel channel) { |
private final JButton btnEditInstr = |
642 |
|
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
643 |
|
private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr); |
644 |
|
|
645 |
|
private final JButton btnFxSends = |
646 |
|
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends")); |
647 |
|
|
648 |
|
private final JButton btnEngine |
649 |
|
= new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine")); |
650 |
|
|
651 |
|
private final JPopupMenu menuEngines = new JPopupMenu(); |
652 |
|
|
653 |
|
private final JLabel lVolume = new Label(); |
654 |
|
private final JLabel lStreams = new Label("--"); |
655 |
|
private final JLabel lVoices = new Label("--"); |
656 |
|
|
657 |
|
private InformationDialog fxSendsDlg = null; |
658 |
|
|
659 |
|
private Dimension dimVolume; |
660 |
|
|
661 |
|
private Timer timer; |
662 |
|
|
663 |
|
class Label extends JLabel { |
664 |
|
Label() { this(""); } |
665 |
|
|
666 |
|
Label(String s) { |
667 |
|
super(s); |
668 |
|
setFont(Res.fontScreen); |
669 |
|
setForeground(new java.awt.Color(0xFFA300)); |
670 |
|
} |
671 |
|
} |
672 |
|
|
673 |
|
ChannelScreen(final Channel channel) { |
674 |
|
super(Res.gfxChannelScreen); |
675 |
|
setPixmapInsets(new Insets(6, 6, 6, 6)); |
676 |
|
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
677 |
|
|
678 |
this.channel = channel; |
this.channel = channel; |
679 |
|
|
680 |
setName("ChannelScreen"); |
setOpaque(false); |
|
setOpaque(true); |
|
681 |
|
|
682 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
683 |
|
|
|
btnInstr.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
|
684 |
btnInstr.setAlignmentX(CENTER_ALIGNMENT); |
btnInstr.setAlignmentX(CENTER_ALIGNMENT); |
685 |
|
btnInstr.setRolloverEnabled(false); |
686 |
|
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
687 |
|
|
688 |
add(btnInstr); |
instrumentPane = new InstrumentPane(); |
689 |
|
add(instrumentPane); |
690 |
|
|
691 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
|
p.setOpaque(false); |
|
692 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
693 |
p.setAlignmentX(CENTER_ALIGNMENT); |
p.setAlignmentX(CENTER_ALIGNMENT); |
694 |
p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
p.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); |
|
//lVolume.setFont(lVolume.getFont().deriveFont(java.awt.Font.PLAIN)); |
|
695 |
|
|
696 |
p.add(btnDuplicate); |
btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt")); |
697 |
|
btnFxSends.addActionListener(new ActionListener() { |
698 |
|
public void |
699 |
|
actionPerformed(ActionEvent e) { |
700 |
|
if(fxSendsDlg != null && fxSendsDlg.isVisible()) { |
701 |
|
fxSendsDlg.toFront(); |
702 |
|
return; |
703 |
|
} |
704 |
|
FxSendsPane p = new FxSendsPane(channel.getModel()); |
705 |
|
int id = channel.getModel().getChannelId(); |
706 |
|
fxSendsDlg = new InformationDialog(CC.getMainFrame(), p); |
707 |
|
fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id)); |
708 |
|
fxSendsDlg.setModal(false); |
709 |
|
fxSendsDlg.showCloseButton(false); |
710 |
|
fxSendsDlg.setVisible(true); |
711 |
|
} |
712 |
|
}); |
713 |
|
|
714 |
|
p.add(btnFxSends); |
715 |
|
|
716 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
717 |
|
|
718 |
p.add(new JLabel("|")); |
btnEngine.setIcon(Res.iconEngine12); |
719 |
|
p.add(btnEngine); |
720 |
|
//p.add(new Label("|")); |
721 |
|
|
722 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
723 |
|
|
724 |
p.add(btnReset); |
//p.add(btnReset); |
725 |
|
|
726 |
p.add(Box.createGlue()); |
p.add(Box.createGlue()); |
727 |
|
|
728 |
p.add(lStreams); |
p.add(lStreams); |
729 |
p.add(new JLabel("/")); |
p.add(new Label("/")); |
730 |
p.add(lVoices); |
p.add(lVoices); |
731 |
|
|
732 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
733 |
|
|
734 |
|
lVolume.setIcon(Res.iconVolume14); |
735 |
lVolume.setAlignmentX(RIGHT_ALIGNMENT); |
lVolume.setAlignmentX(RIGHT_ALIGNMENT); |
736 |
|
updateVolumeInfo(100); |
737 |
|
dimVolume = lVolume.getPreferredSize(); |
738 |
p.add(lVolume); |
p.add(lVolume); |
739 |
p.setPreferredSize(new Dimension(250, p.getPreferredSize().height)); |
p.setPreferredSize(new Dimension(250, p.getPreferredSize().height)); |
740 |
p.setMinimumSize(p.getPreferredSize()); |
p.setMinimumSize(p.getPreferredSize()); |
741 |
p.setMaximumSize(p.getPreferredSize()); |
p.setMaximumSize(p.getPreferredSize()); |
742 |
|
|
743 |
|
//btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
744 |
|
p.setOpaque(false); |
745 |
add(p); |
add(p); |
746 |
|
|
747 |
|
|
749 |
setMinimumSize(getPreferredSize()); |
setMinimumSize(getPreferredSize()); |
750 |
setMaximumSize(getPreferredSize()); |
setMaximumSize(getPreferredSize()); |
751 |
|
|
752 |
|
createEngineMenu(); |
753 |
installListeners(); |
installListeners(); |
754 |
} |
} |
755 |
|
|
756 |
|
protected void |
757 |
|
onDestroy() { timer.stop(); } |
758 |
|
|
759 |
|
private void |
760 |
|
createEngineMenu() { |
761 |
|
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) { |
762 |
|
JMenuItem mi = new JMenuItem(engine.getDescription()); |
763 |
|
|
764 |
|
mi.addActionListener(new ActionListener() { |
765 |
|
public void |
766 |
|
actionPerformed(ActionEvent e) { |
767 |
|
channel.getModel().setBackendEngineType(engine.getName()); |
768 |
|
} |
769 |
|
}); |
770 |
|
|
771 |
|
menuEngines.add(mi); |
772 |
|
} |
773 |
|
} |
774 |
|
|
775 |
private void |
private void |
776 |
installListeners() { |
installListeners() { |
777 |
btnInstr.addActionListener(new ActionListener() { |
btnInstr.addActionListener(new ActionListener() { |
778 |
public void |
public void |
779 |
actionPerformed(ActionEvent e) { loadInstrument(); } |
actionPerformed(ActionEvent e) { loadInstrument(); } |
780 |
}); |
}); |
781 |
|
|
782 |
btnReset.addActionListener(new ActionListener() { |
btnEditInstr.addActionListener(new ActionListener() { |
783 |
public void |
public void |
784 |
actionPerformed(ActionEvent e) { channel.getModel().resetBackendChannel(); } |
actionPerformed(ActionEvent e) { |
785 |
|
CC.getSamplerModel().editBackendInstrument(channel.getChannelId()); |
786 |
|
} |
787 |
}); |
}); |
788 |
|
|
789 |
btnDuplicate.addActionListener(new ActionListener() { |
btnEngine.addActionListener(new ActionListener() { |
790 |
public void |
public void |
791 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
792 |
channel.getModel().duplicateBackendChannel(); |
int y = btnEngine.getHeight() + 1; |
793 |
|
menuEngines.show(btnEngine, 0, y); |
794 |
} |
} |
795 |
}); |
}); |
796 |
|
|
797 |
|
addMouseListener(getHandler()); |
798 |
|
addHierarchyListener(getHandler()); |
799 |
|
|
800 |
|
ActionListener l = new ActionListener() { |
801 |
|
public void |
802 |
|
actionPerformed(ActionEvent e) { |
803 |
|
if(getMousePosition(true) != null) { |
804 |
|
getHandler().mouseEntered(null); |
805 |
|
} else { |
806 |
|
getHandler().mouseExited(null); |
807 |
|
} |
808 |
|
} |
809 |
|
}; |
810 |
|
timer = new Timer(1000, l); |
811 |
|
timer.start(); |
812 |
} |
} |
813 |
|
|
814 |
private void |
private void |
815 |
loadInstrument() { |
loadInstrument() { |
816 |
InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame()); |
JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame()); |
817 |
dlg.setVisible(true); |
dlg.setVisible(true); |
818 |
|
|
819 |
if(!dlg.isCancelled()) { |
if(!dlg.isCancelled()) { |
820 |
SamplerChannelModel m = channel.getModel(); |
SamplerChannelModel m = channel.getModel(); |
821 |
m.loadBackendInstrument(dlg.getFileName(), dlg.getInstrumentIndex()); |
m.loadBackendInstrument(dlg.getInstrumentFile(), dlg.getInstrumentIndex()); |
822 |
} |
} |
823 |
} |
} |
824 |
|
|
835 |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
836 |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
837 |
} |
} |
|
|
|
838 |
|
|
839 |
|
instrumentPane.update(); |
840 |
|
|
841 |
|
if(sc.getEngine() != null) { |
842 |
|
String s = sc.getEngine().getDescription(); |
843 |
|
if(!s.equals(btnEngine.getText())) btnEngine.setText(s); |
844 |
|
} |
845 |
|
|
846 |
} |
} |
847 |
|
|
848 |
protected void |
protected void |
849 |
updateVolumeInfo(int volume) { |
updateVolumeInfo(int volume) { |
850 |
lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume)); |
lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume)); |
851 |
|
lVolume.setMinimumSize(dimVolume); |
852 |
|
lVolume.setPreferredSize(dimVolume); |
853 |
|
|
854 |
} |
} |
855 |
|
|
881 |
lVoices.setMaximumSize(d); |
lVoices.setMaximumSize(d); |
882 |
} |
} |
883 |
|
|
884 |
|
class InstrumentPane extends JPanel { |
885 |
|
private final JPanel leftPane = new JPanel(); |
886 |
|
private final JPanel rightPane = new JPanel(); |
887 |
|
|
888 |
|
InstrumentPane() { |
889 |
|
setOpaque(false); |
890 |
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
891 |
|
add(leftPane); |
892 |
|
add(btnInstr); |
893 |
|
add(rightPane); |
894 |
|
add(sbbEditInstr); |
895 |
|
btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt")); |
896 |
|
sbbEditInstr.setVisible(false); |
897 |
|
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); |
898 |
|
|
899 |
|
update(); |
900 |
|
} |
901 |
|
|
902 |
|
public void |
903 |
|
update() { |
904 |
|
int a = btnInstr.getMinimumSize().width; |
905 |
|
int b = 0; |
906 |
|
if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width; |
907 |
|
|
908 |
|
int max = 254 - b; |
909 |
|
if(a > max) a = max; |
910 |
|
|
911 |
|
int h = btnInstr.getPreferredSize().height; |
912 |
|
btnInstr.setPreferredSize(new Dimension(a, h)); |
913 |
|
h = btnInstr.getMaximumSize().height; |
914 |
|
btnInstr.setMaximumSize(new Dimension(a, h)); |
915 |
|
|
916 |
|
|
917 |
|
int i = (254 - btnInstr.getPreferredSize().width) / 2; |
918 |
|
|
919 |
|
int j = i; |
920 |
|
if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width; |
921 |
|
if(i < 0 || j < 0) i = j = 0; |
922 |
|
|
923 |
|
Dimension d = new Dimension(i, 1); |
924 |
|
leftPane.setMinimumSize(d); |
925 |
|
leftPane.setPreferredSize(d); |
926 |
|
leftPane.setMaximumSize(d); |
927 |
|
|
928 |
|
d = new Dimension(j, 1); |
929 |
|
rightPane.setMinimumSize(d); |
930 |
|
rightPane.setPreferredSize(d); |
931 |
|
rightPane.setMaximumSize(d); |
932 |
|
|
933 |
|
validate(); |
934 |
|
} |
935 |
|
} |
936 |
|
|
937 |
|
class FxSendsPane extends JSFxSendsPane { |
938 |
|
FxSendsPane(SamplerChannelModel model) { |
939 |
|
super(model); |
940 |
|
|
941 |
|
actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16); |
942 |
|
actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16); |
943 |
|
} |
944 |
|
|
945 |
|
protected JToolBar |
946 |
|
createToolBar() { |
947 |
|
JToolBar tb = new JToolBar(); |
948 |
|
Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height); |
949 |
|
tb.setMaximumSize(d); |
950 |
|
tb.setFloatable(false); |
951 |
|
tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT); |
952 |
|
|
953 |
|
tb.add(new ToolbarButton(actionAddFxSend)); |
954 |
|
tb.add(new ToolbarButton(actionRemoveFxSend)); |
955 |
|
|
956 |
|
return tb; |
957 |
|
} |
958 |
|
} |
959 |
|
|
960 |
static class ScreenButton extends JButton { |
static class ScreenButton extends JButton { |
961 |
ScreenButton(String s) { |
ScreenButton(String s) { |
962 |
super(s); |
super(s); |
964 |
setFocusPainted(false); |
setFocusPainted(false); |
965 |
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
966 |
setMargin(new Insets(0, 0, 0, 0)); |
setMargin(new Insets(0, 0, 0, 0)); |
967 |
|
|
968 |
|
putClientProperty ( |
969 |
|
SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE |
970 |
|
); |
971 |
|
|
972 |
|
putClientProperty ( |
973 |
|
SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE |
974 |
|
); |
975 |
|
|
976 |
|
putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE); |
977 |
|
|
978 |
|
FadeConfigurationManager.getInstance().disallowFades(FadeKind.ROLLOVER, this); |
979 |
|
|
980 |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
981 |
|
setFont(Res.fontScreen); |
982 |
|
setForeground(new java.awt.Color(0xFFA300)); |
983 |
|
} |
984 |
|
} |
985 |
|
|
986 |
|
static class ScreenButtonBg extends PixmapPane { |
987 |
|
ScreenButtonBg(JButton btn) { |
988 |
|
super(Res.gfxScreenBtnBg); |
989 |
|
setPixmapInsets(new Insets(4, 4, 4, 4)); |
990 |
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
991 |
|
setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7)); |
992 |
|
add(btn); |
993 |
|
setPreferredSize(new Dimension(getPreferredSize().width, 13)); |
994 |
|
} |
995 |
|
|
996 |
|
public Dimension |
997 |
|
getPreferredSize() { |
998 |
|
return new Dimension(super.getPreferredSize().width, 13); |
999 |
|
} |
1000 |
|
} |
1001 |
|
|
1002 |
|
private final EventHandler eventHandler = new EventHandler(); |
1003 |
|
|
1004 |
|
private EventHandler |
1005 |
|
getHandler() { return eventHandler; } |
1006 |
|
|
1007 |
|
private class EventHandler extends MouseAdapter implements HierarchyListener { |
1008 |
|
public void |
1009 |
|
mouseEntered(MouseEvent e) { |
1010 |
|
if(channel.getChannelInfo().getInstrumentStatus() != 100) return; |
1011 |
|
|
1012 |
|
if(!sbbEditInstr.isVisible()) { |
1013 |
|
sbbEditInstr.setVisible(true); |
1014 |
|
instrumentPane.update(); |
1015 |
|
} |
1016 |
|
} |
1017 |
|
|
1018 |
|
public void |
1019 |
|
mouseExited(MouseEvent e) { |
1020 |
|
if(getMousePosition(true) != null) return; |
1021 |
|
if(sbbEditInstr.isVisible()) { |
1022 |
|
sbbEditInstr.setVisible(false); |
1023 |
|
instrumentPane.update(); |
1024 |
|
} |
1025 |
|
} |
1026 |
|
|
1027 |
|
/** Called when the hierarchy has been changed. */ |
1028 |
|
public void |
1029 |
|
hierarchyChanged(HierarchyEvent e) { |
1030 |
|
if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) { |
1031 |
|
if(getMousePosition() == null) mouseExited(null); |
1032 |
|
else mouseEntered(null); |
1033 |
|
} |
1034 |
} |
} |
1035 |
} |
} |
1036 |
} |
} |
1037 |
|
|
1038 |
class ChannelOptions extends JPanel { |
class ChannelOptions extends JXCollapsiblePane { |
1039 |
private final Channel channel; |
private final Channel channel; |
1040 |
|
private MidiDeviceModel midiDevice = null; |
1041 |
|
|
1042 |
private final JComboBox cbMidiDevice = new JComboBox(); |
private final JComboBox cbMidiDevice = new FantasiaComboBox(); |
1043 |
private final JComboBox cbMidiPort = new JComboBox(); |
private final JComboBox cbMidiPort = new FantasiaComboBox(); |
1044 |
private final JComboBox cbMidiChannel = new JComboBox(); |
private final JComboBox cbMidiChannel = new FantasiaComboBox(); |
1045 |
private final JComboBox cbEngine = new JComboBox(); |
private final JComboBox cbInstrumentMap = new FantasiaComboBox(); |
1046 |
private final JComboBox cbAudioDevice = new JComboBox(); |
private final JComboBox cbAudioDevice = new FantasiaComboBox(); |
1047 |
|
|
1048 |
|
private final PixmapButton btnChannelRouting; |
1049 |
|
|
1050 |
private boolean update = false; |
private boolean update = false; |
1051 |
|
|
1052 |
ChannelOptions(Channel channel) { |
private final SamplerListener samplerListener; |
1053 |
|
private final MapListListener mapListListener = new MapListListener(); |
1054 |
|
|
1055 |
|
private class NoMap { |
1056 |
|
public String |
1057 |
|
toString() { return "[None]"; } |
1058 |
|
} |
1059 |
|
|
1060 |
|
private NoMap noMap = new NoMap(); |
1061 |
|
|
1062 |
|
private class DefaultMap { |
1063 |
|
public String |
1064 |
|
toString() { return "[Default]"; } |
1065 |
|
} |
1066 |
|
|
1067 |
|
private DefaultMap defaultMap = new DefaultMap(); |
1068 |
|
|
1069 |
|
ChannelOptions(final Channel channel) { |
1070 |
|
setAnimated(false); |
1071 |
|
setCollapsed(true); |
1072 |
|
setAnimated(preferences().getBoolProperty(ANIMATED)); |
1073 |
|
|
1074 |
|
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
1075 |
|
public void |
1076 |
|
propertyChange(PropertyChangeEvent e) { |
1077 |
|
setAnimated(preferences().getBoolProperty(ANIMATED)); |
1078 |
|
} |
1079 |
|
}); |
1080 |
|
|
1081 |
|
PixmapPane bgp = new PixmapPane(Res.gfxChannelOptions); |
1082 |
|
bgp.setPixmapInsets(new Insets(1, 1, 1, 1)); |
1083 |
|
|
1084 |
this.channel = channel; |
this.channel = channel; |
1085 |
|
|
1086 |
setName("ChannelOptions"); |
bgp.setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4)); |
1087 |
setVisible(false); |
bgp.setLayout(new BoxLayout(bgp, BoxLayout.X_AXIS)); |
|
setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4)); |
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
|
1088 |
|
|
1089 |
setPreferredSize(new Dimension(420, 44)); |
bgp.setPreferredSize(new Dimension(420, 44)); |
1090 |
setMinimumSize(getPreferredSize()); |
bgp.setMinimumSize(getPreferredSize()); |
1091 |
setMaximumSize(getPreferredSize()); |
bgp.setMaximumSize(getPreferredSize()); |
1092 |
|
|
1093 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
|
p.setOpaque(true); |
|
1094 |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
1095 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
1096 |
JLabel l = new JLabel(Res.iconMidiInputTitle); |
JLabel l = new JLabel(Res.gfxMidiInputTitle); |
1097 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1098 |
p.add(l); |
p.add(l); |
1099 |
|
|
1114 |
o = cbMidiPort.getRenderer(); |
o = cbMidiPort.getRenderer(); |
1115 |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER); |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER); |
1116 |
|
|
1117 |
cbMidiPort.setPreferredSize(new Dimension(67, 18)); |
cbMidiPort.setPreferredSize(new Dimension(62, 18)); |
1118 |
cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize()); |
cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize()); |
1119 |
cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize()); |
cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize()); |
1120 |
p2.add(cbMidiPort); |
p2.add(cbMidiPort); |
1132 |
|
|
1133 |
p2.add(cbMidiChannel); |
p2.add(cbMidiChannel); |
1134 |
p2.setAlignmentX(LEFT_ALIGNMENT); |
p2.setAlignmentX(LEFT_ALIGNMENT); |
1135 |
|
p2.setOpaque(false); |
1136 |
p.add(p2); |
p.add(p2); |
1137 |
|
p.setBackground(new java.awt.Color(0x818181)); |
1138 |
|
|
1139 |
add(p); |
bgp.add(p); |
1140 |
|
|
1141 |
add(Box.createRigidArea(new Dimension(4, 0))); |
bgp.add(Box.createRigidArea(new Dimension(4, 0))); |
1142 |
|
|
1143 |
p = new JPanel(); |
p = new JPanel(); |
1144 |
p.setOpaque(true); |
p.setOpaque(true); |
1145 |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
1146 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
1147 |
l = new JLabel(Res.iconEngineTitle); |
l = new JLabel(Res.gfxInstrumentMapTitle); |
1148 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1149 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1150 |
p.add(l); |
p.add(l); |
1151 |
|
|
1152 |
p.add(Box.createRigidArea(new Dimension(0, 3))); |
p.add(Box.createRigidArea(new Dimension(0, 3))); |
1153 |
|
|
1154 |
o = cbEngine.getRenderer(); |
//o = cbInstrumentMap.getRenderer(); |
1155 |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER); |
//if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
|
for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e); |
|
|
cbEngine.setPreferredSize(new Dimension(125, 18)); |
|
|
cbEngine.setMinimumSize(cbEngine.getPreferredSize()); |
|
|
cbEngine.setMaximumSize(cbEngine.getPreferredSize()); |
|
|
cbEngine.setAlignmentX(LEFT_ALIGNMENT); |
|
|
p.add(cbEngine); |
|
1156 |
|
|
1157 |
add(p); |
cbInstrumentMap.setPreferredSize(new Dimension(126, 18)); |
1158 |
|
cbInstrumentMap.setMinimumSize(cbInstrumentMap.getPreferredSize()); |
1159 |
|
cbInstrumentMap.setMaximumSize(cbInstrumentMap.getPreferredSize()); |
1160 |
|
cbInstrumentMap.setAlignmentX(LEFT_ALIGNMENT); |
1161 |
|
p.add(cbInstrumentMap); |
1162 |
|
p.setBackground(new java.awt.Color(0x818181)); |
1163 |
|
bgp.add(p); |
1164 |
|
|
1165 |
add(Box.createRigidArea(new Dimension(4, 0))); |
bgp.add(Box.createRigidArea(new Dimension(4, 0))); |
1166 |
|
|
1167 |
p = new JPanel(); |
p = new JPanel(); |
1168 |
p.setOpaque(true); |
p.setOpaque(true); |
1169 |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
1170 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
1171 |
l = new JLabel(Res.iconAudioOutputTitle); |
l = new JLabel(Res.gfxAudioOutputTitle); |
|
l.setAlignmentX(LEFT_ALIGNMENT); |
|
1172 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1173 |
p.add(l); |
p.add(l); |
1174 |
|
|
1175 |
p.add(Box.createRigidArea(new Dimension(0, 3))); |
//p.add(Box.createRigidArea(new Dimension(0, 3))); |
1176 |
|
|
1177 |
|
p2 = new JPanel(); |
1178 |
|
p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
1179 |
|
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
1180 |
|
p2.setOpaque(false); |
1181 |
|
p2.setAlignmentX(LEFT_ALIGNMENT); |
1182 |
|
|
1183 |
o = cbAudioDevice.getRenderer(); |
o = cbAudioDevice.getRenderer(); |
1184 |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT); |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT); |
1185 |
|
|
1186 |
cbAudioDevice.setPreferredSize(new Dimension(61, 18)); |
cbAudioDevice.setPreferredSize(new Dimension(40, 18)); |
1187 |
cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize()); |
cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize()); |
1188 |
cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize()); |
cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize()); |
|
cbAudioDevice.setAlignmentX(LEFT_ALIGNMENT); |
|
|
p.add(cbAudioDevice); |
|
1189 |
|
|
1190 |
add(p); |
p2.add(cbAudioDevice); |
1191 |
|
p2.add(Box.createRigidArea(new Dimension(3, 0))); |
1192 |
|
btnChannelRouting = new PixmapButton(Res.gfxBtnCr, Res.gfxBtnCrRO); |
1193 |
|
btnChannelRouting.setPressedIcon(Res.gfxBtnCrRO); |
1194 |
|
btnChannelRouting.setEnabled(false); |
1195 |
|
btnChannelRouting.setToolTipText(i18n.getLabel("ChannelOptions.routing")); |
1196 |
|
|
1197 |
|
btnChannelRouting.addActionListener(new ActionListener() { |
1198 |
|
public void |
1199 |
|
actionPerformed(ActionEvent e) { |
1200 |
|
SamplerChannel c = channel.getChannelInfo(); |
1201 |
|
new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true); |
1202 |
|
|
1203 |
|
} |
1204 |
|
}); |
1205 |
|
|
1206 |
|
p2.add(btnChannelRouting); |
1207 |
|
|
1208 |
|
p.add(p2); |
1209 |
|
p.setBackground(new java.awt.Color(0x818181)); |
1210 |
|
p2 = new JPanel(); |
1211 |
|
p2.setLayout(new java.awt.BorderLayout()); |
1212 |
|
p.add(p2); |
1213 |
|
bgp.add(p); |
1214 |
|
|
1215 |
|
setContentPane(bgp); |
1216 |
|
|
1217 |
cbMidiDevice.addActionListener(new ActionListener() { |
cbMidiDevice.addActionListener(new ActionListener() { |
1218 |
public void |
public void |
1229 |
actionPerformed(ActionEvent e) { setMidiChannel(); } |
actionPerformed(ActionEvent e) { setMidiChannel(); } |
1230 |
}); |
}); |
1231 |
|
|
1232 |
cbEngine.addActionListener(new ActionListener() { |
samplerListener = new SamplerAdapter() { |
1233 |
|
/** Invoked when the default MIDI instrument map is changed. */ |
1234 |
|
public void |
1235 |
|
defaultMapChanged(SamplerEvent e) { |
1236 |
|
updateCbInstrumentMapToolTipText(); |
1237 |
|
|
1238 |
|
} |
1239 |
|
}; |
1240 |
|
|
1241 |
|
CC.getSamplerModel().addSamplerListener(samplerListener); |
1242 |
|
|
1243 |
|
cbInstrumentMap.addItem(noMap); |
1244 |
|
cbInstrumentMap.addItem(defaultMap); |
1245 |
|
for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) { |
1246 |
|
cbInstrumentMap.addItem(map); |
1247 |
|
} |
1248 |
|
|
1249 |
|
int map = channel.getModel().getChannelInfo().getMidiInstrumentMapId(); |
1250 |
|
cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map)); |
1251 |
|
if(cbInstrumentMap.getSelectedItem() == null) { |
1252 |
|
if(map == -1) cbInstrumentMap.setSelectedItem(noMap); |
1253 |
|
else if(map == -2) { |
1254 |
|
cbInstrumentMap.setSelectedItem(defaultMap); |
1255 |
|
} |
1256 |
|
} |
1257 |
|
|
1258 |
|
updateCbInstrumentMapToolTipText(); |
1259 |
|
|
1260 |
|
if(channel.getModel().getChannelInfo().getEngine() == null) { |
1261 |
|
cbInstrumentMap.setEnabled(false); |
1262 |
|
} |
1263 |
|
|
1264 |
|
cbInstrumentMap.addActionListener(new ActionListener() { |
1265 |
public void |
public void |
1266 |
actionPerformed(ActionEvent e) { setEngineType(); } |
actionPerformed(ActionEvent e) { updateInstrumentMap(); } |
1267 |
}); |
}); |
1268 |
|
|
1269 |
|
CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener); |
1270 |
|
|
1271 |
cbAudioDevice.addActionListener(new ActionListener() { |
cbAudioDevice.addActionListener(new ActionListener() { |
1272 |
public void |
public void |
1273 |
actionPerformed(ActionEvent e) { setBackendAudioDevice(); } |
actionPerformed(ActionEvent e) { setBackendAudioDevice(); } |
1295 |
SamplerModel sm = CC.getSamplerModel(); |
SamplerModel sm = CC.getSamplerModel(); |
1296 |
SamplerChannel sc = channel.getModel().getChannelInfo(); |
SamplerChannel sc = channel.getModel().getChannelInfo(); |
1297 |
|
|
1298 |
MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice()); |
MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice()); |
1299 |
AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice()); |
AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice()); |
1300 |
|
|
1301 |
if(isUpdate()) CC.getLogger().warning("Unexpected update state!"); |
if(isUpdate()) CC.getLogger().warning("Unexpected update state!"); |
1302 |
|
|
1305 |
try { |
try { |
1306 |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
1307 |
|
|
|
cbEngine.setSelectedItem(sc.getEngine()); |
|
|
|
|
1308 |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
1309 |
|
btnChannelRouting.setEnabled(am != null); |
1310 |
} catch(Exception x) { |
} catch(Exception x) { |
1311 |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
1312 |
} |
} |
1313 |
|
|
1314 |
|
if(sc.getEngine() != null) { |
1315 |
|
cbInstrumentMap.setEnabled(true); |
1316 |
|
int id = sc.getMidiInstrumentMapId(); |
1317 |
|
Object o; |
1318 |
|
if(id == -2) o = defaultMap; |
1319 |
|
else if(id == -1) o = noMap; |
1320 |
|
else o = CC.getSamplerModel().getMidiInstrumentMapById(id); |
1321 |
|
|
1322 |
|
if(cbInstrumentMap.getSelectedItem() != o) { |
1323 |
|
cbInstrumentMap.setSelectedItem(o); |
1324 |
|
} |
1325 |
|
} else { |
1326 |
|
cbInstrumentMap.setSelectedItem(noMap); |
1327 |
|
cbInstrumentMap.setEnabled(false); |
1328 |
|
} |
1329 |
|
|
1330 |
setUpdate(false); |
setUpdate(false); |
1331 |
} |
} |
1332 |
|
|
1343 |
try { |
try { |
1344 |
cbMidiDevice.removeAllItems(); |
cbMidiDevice.removeAllItems(); |
1345 |
|
|
1346 |
for(MidiDeviceModel m : sm.getMidiDeviceModels()) |
for(MidiDeviceModel m : sm.getMidiDevices()) |
1347 |
cbMidiDevice.addItem(m.getDeviceInfo()); |
cbMidiDevice.addItem(m.getDeviceInfo()); |
1348 |
|
|
1349 |
MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice()); |
MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice()); |
1350 |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
1351 |
} catch(Exception x) { |
} catch(Exception x) { |
1352 |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
1355 |
setUpdate(false); |
setUpdate(false); |
1356 |
} |
} |
1357 |
|
|
1358 |
|
|
1359 |
|
private void |
1360 |
|
updateInstrumentMap() { |
1361 |
|
updateCbInstrumentMapToolTipText(); |
1362 |
|
|
1363 |
|
int id = channel.getModel().getChannelInfo().getMidiInstrumentMapId(); |
1364 |
|
Object o = cbInstrumentMap.getSelectedItem(); |
1365 |
|
if(o == null && id == -1) return; |
1366 |
|
|
1367 |
|
int cbId; |
1368 |
|
if(o == null || o == noMap) cbId = -1; |
1369 |
|
else if(o == defaultMap) cbId = -2; |
1370 |
|
else cbId = ((MidiInstrumentMap)o).getMapId(); |
1371 |
|
|
1372 |
|
if(cbId == id) return; |
1373 |
|
|
1374 |
|
channel.getModel().setBackendMidiInstrumentMap(cbId); |
1375 |
|
} |
1376 |
|
|
1377 |
|
private void |
1378 |
|
updateCbInstrumentMapToolTipText() { |
1379 |
|
if(cbInstrumentMap.getSelectedItem() != defaultMap) { |
1380 |
|
cbInstrumentMap.setToolTipText(null); |
1381 |
|
return; |
1382 |
|
} |
1383 |
|
|
1384 |
|
MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap(); |
1385 |
|
if(m != null) { |
1386 |
|
String s = i18n.getLabel("Channel.ttDefault", m.getName()); |
1387 |
|
cbInstrumentMap.setToolTipText(s); |
1388 |
|
} else { |
1389 |
|
cbInstrumentMap.setToolTipText(null); |
1390 |
|
} |
1391 |
|
} |
1392 |
|
|
1393 |
/** |
/** |
1394 |
* Updates the audio device list. |
* Updates the audio device list. |
1395 |
*/ |
*/ |
1403 |
try { |
try { |
1404 |
cbAudioDevice.removeAllItems(); |
cbAudioDevice.removeAllItems(); |
1405 |
|
|
1406 |
for(AudioDeviceModel m : sm.getAudioDeviceModels()) |
for(AudioDeviceModel m : sm.getAudioDevices()) |
1407 |
cbAudioDevice.addItem(m.getDeviceInfo()); |
cbAudioDevice.addItem(m.getDeviceInfo()); |
1408 |
|
|
1409 |
AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice()); |
AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice()); |
1410 |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
1411 |
} catch(Exception x) { |
} catch(Exception x) { |
1412 |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
1427 |
return; |
return; |
1428 |
} |
} |
1429 |
|
|
1430 |
|
if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler()); |
1431 |
|
|
1432 |
cbMidiPort.removeAllItems(); |
cbMidiPort.removeAllItems(); |
1433 |
|
|
1434 |
if(mid == null) { |
if(mid == null) { |
1435 |
|
midiDevice = null; |
1436 |
cbMidiPort.setEnabled(false); |
cbMidiPort.setEnabled(false); |
1437 |
|
|
1438 |
cbMidiChannel.setSelectedItem(null); |
cbMidiChannel.setSelectedItem(null); |
1439 |
cbMidiChannel.setEnabled(false); |
cbMidiChannel.setEnabled(false); |
1440 |
} else { |
} else { |
1441 |
|
midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId()); |
1442 |
|
if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler()); |
1443 |
|
|
1444 |
cbMidiPort.setEnabled(true); |
cbMidiPort.setEnabled(true); |
1445 |
|
|
1446 |
MidiPort[] ports = mid.getMidiPorts(); |
MidiPort[] ports = mid.getMidiPorts(); |
1475 |
channel.getModel().setBackendMidiInputChannel(c); |
channel.getModel().setBackendMidiInputChannel(c); |
1476 |
} |
} |
1477 |
|
|
|
/** Invoked when the user selects an engine. */ |
|
|
private void |
|
|
setEngineType() { |
|
|
Object oldEngine = channel.getModel().getChannelInfo().getEngine(); |
|
|
SamplerEngine newEngine = (SamplerEngine)cbEngine.getSelectedItem(); |
|
|
|
|
|
if(oldEngine != null) { if(oldEngine.equals(newEngine)) return; } |
|
|
else if(newEngine == null) return; |
|
|
|
|
|
channel.getModel().setBackendEngineType(newEngine.getName()); |
|
|
|
|
|
} |
|
|
|
|
1478 |
private void |
private void |
1479 |
setBackendAudioDevice() { |
setBackendAudioDevice() { |
1480 |
if(isUpdate()) return; |
if(isUpdate()) return; |
1499 |
private void |
private void |
1500 |
setUpdate(boolean b) { update = b; } |
setUpdate(boolean b) { update = b; } |
1501 |
|
|
1502 |
|
protected void |
1503 |
|
onDestroy() { |
1504 |
|
SamplerModel sm = CC.getSamplerModel(); |
1505 |
|
|
1506 |
|
sm.removeMidiDeviceListListener(getHandler()); |
1507 |
|
sm.removeAudioDeviceListListener(getHandler()); |
1508 |
|
sm.removeMidiInstrumentMapListListener(mapListListener); |
1509 |
|
sm.removeSamplerListener(samplerListener); |
1510 |
|
|
1511 |
|
if(midiDevice != null) { |
1512 |
|
midiDevice.removeMidiDeviceListener(getHandler()); |
1513 |
|
} |
1514 |
|
} |
1515 |
|
|
1516 |
private final Handler handler = new Handler(); |
private final Handler handler = new Handler(); |
1517 |
|
|
1518 |
private Handler |
private Handler |
1519 |
getHandler() { return handler; } |
getHandler() { return handler; } |
1520 |
|
|
1521 |
private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel> { |
private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>, |
1522 |
|
MidiDeviceListener { |
1523 |
/** |
/** |
1524 |
* Invoked when a new MIDI device is created. |
* Invoked when a new MIDI device is created. |
1525 |
* @param e A <code>MidiDeviceListEvent</code> |
* @param e A <code>MidiDeviceListEvent</code> |
1559 |
entryRemoved(ListEvent<AudioDeviceModel> e) { |
entryRemoved(ListEvent<AudioDeviceModel> e) { |
1560 |
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo()); |
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo()); |
1561 |
} |
} |
1562 |
|
|
1563 |
|
public void |
1564 |
|
settingsChanged(MidiDeviceEvent e) { |
1565 |
|
if(isUpdate()) { |
1566 |
|
CC.getLogger().warning("Invalid update state"); |
1567 |
|
return; |
1568 |
|
} |
1569 |
|
|
1570 |
|
setUpdate(true); |
1571 |
|
int idx = cbMidiPort.getSelectedIndex(); |
1572 |
|
MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo(); |
1573 |
|
|
1574 |
|
cbMidiPort.removeAllItems(); |
1575 |
|
for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port); |
1576 |
|
|
1577 |
|
if(idx >= cbMidiPort.getModel().getSize()) idx = 0; |
1578 |
|
|
1579 |
|
setUpdate(false); |
1580 |
|
|
1581 |
|
if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx); |
1582 |
|
} |
1583 |
|
} |
1584 |
|
|
1585 |
|
private class MapListListener implements ListListener<MidiInstrumentMap> { |
1586 |
|
/** Invoked when a new MIDI instrument map is added to a list. */ |
1587 |
|
public void |
1588 |
|
entryAdded(ListEvent<MidiInstrumentMap> e) { |
1589 |
|
cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount()); |
1590 |
|
boolean b = channel.getModel().getChannelInfo().getEngine() != null; |
1591 |
|
if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true); |
1592 |
|
} |
1593 |
|
|
1594 |
|
/** Invoked when a new MIDI instrument map is removed from a list. */ |
1595 |
|
public void |
1596 |
|
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
1597 |
|
cbInstrumentMap.removeItem(e.getEntry()); |
1598 |
|
if(cbInstrumentMap.getItemCount() == 0) { // TODO: ? |
1599 |
|
cbInstrumentMap.setSelectedItem(noMap); |
1600 |
|
cbInstrumentMap.setEnabled(false); |
1601 |
|
} |
1602 |
|
} |
1603 |
} |
} |
1604 |
} |
} |