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 |
* |
* |
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; |
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; |
40 |
|
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; |
47 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
48 |
import javax.swing.Box; |
import javax.swing.Box; |
49 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
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; |
56 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
57 |
|
import javax.swing.JPopupMenu; |
58 |
|
import javax.swing.JScrollPane; |
59 |
import javax.swing.JToggleButton; |
import javax.swing.JToggleButton; |
60 |
|
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; |
66 |
|
|
67 |
import net.sf.juife.Dial; |
import net.sf.juife.Dial; |
68 |
|
import net.sf.juife.InformationDialog; |
69 |
import net.sf.juife.JuifeUtils; |
import net.sf.juife.JuifeUtils; |
70 |
import net.sf.juife.TitleBar; |
import net.sf.juife.TitleBar; |
71 |
|
|
72 |
|
import org.jdesktop.swingx.JXCollapsiblePane; |
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; |
79 |
import org.jsampler.SamplerChannelModel; |
import org.jsampler.SamplerChannelModel; |
80 |
import org.jsampler.SamplerModel; |
import org.jsampler.SamplerModel; |
81 |
|
|
82 |
import org.jsampler.event.ListEvent; |
import org.jsampler.event.ListEvent; |
83 |
import org.jsampler.event.ListListener; |
import org.jsampler.event.ListListener; |
84 |
|
import org.jsampler.event.MidiDeviceEvent; |
85 |
import org.jsampler.event.MidiDeviceListEvent; |
import org.jsampler.event.MidiDeviceListEvent; |
86 |
import org.jsampler.event.MidiDeviceListListener; |
import org.jsampler.event.MidiDeviceListListener; |
87 |
|
import org.jsampler.event.MidiDeviceListener; |
88 |
|
import org.jsampler.event.SamplerAdapter; |
89 |
import org.jsampler.event.SamplerChannelAdapter; |
import org.jsampler.event.SamplerChannelAdapter; |
90 |
import org.jsampler.event.SamplerChannelEvent; |
import org.jsampler.event.SamplerChannelEvent; |
91 |
|
import org.jsampler.event.SamplerChannelListEvent; |
92 |
|
import org.jsampler.event.SamplerChannelListListener; |
93 |
import org.jsampler.event.SamplerChannelListener; |
import org.jsampler.event.SamplerChannelListener; |
94 |
|
import org.jsampler.event.SamplerEvent; |
95 |
|
import org.jsampler.event.SamplerListener; |
96 |
|
|
97 |
|
import org.jsampler.view.std.JSChannelOutputRoutingDlg; |
98 |
|
import org.jsampler.view.std.JSFxSendsPane; |
99 |
|
import org.jsampler.view.std.JSInstrumentChooser; |
100 |
|
import org.jsampler.view.std.JSVolumeEditorPopup; |
101 |
|
|
102 |
|
import org.jvnet.substance.SubstanceImageCreator; |
103 |
|
|
104 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
105 |
import org.linuxsampler.lscp.MidiInputDevice; |
import org.linuxsampler.lscp.MidiInputDevice; |
108 |
import org.linuxsampler.lscp.SamplerEngine; |
import org.linuxsampler.lscp.SamplerEngine; |
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.*; |
112 |
|
import static org.jsampler.view.fantasia.FantasiaUtils.*; |
113 |
|
import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType; |
114 |
|
|
115 |
|
|
116 |
/** |
/** |
118 |
* @author Grigor Iliev |
* @author Grigor Iliev |
119 |
*/ |
*/ |
120 |
public class Channel extends org.jsampler.view.JSChannel { |
public class Channel extends org.jsampler.view.JSChannel { |
121 |
|
private final JXCollapsiblePane mainPane; |
122 |
private final ChannelScreen screen = new ChannelScreen(this); |
private final ChannelScreen screen = new ChannelScreen(this); |
123 |
private final ChannelOptions optionsPane = new ChannelOptions(this); |
private final ChannelOptions optionsPane = new ChannelOptions(this); |
124 |
|
|
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)); |
158 |
JPanel p = new JPanel(); |
ChannelPane p = new ChannelPane(); |
|
p.setName("Channel"); |
|
159 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
160 |
|
|
161 |
//p.add(Box.createRigidArea(new Dimension(3, 0))); |
//p.add(Box.createRigidArea(new Dimension(3, 0))); |
162 |
|
|
163 |
btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT); |
btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT); |
164 |
|
|
165 |
TitleBar tb = new TitleBar(); |
JPanel tb = new JPanel(); |
166 |
tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4)); |
tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4)); |
167 |
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
168 |
tb.setOpaque(false); |
tb.setOpaque(false); |
194 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
195 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
196 |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
197 |
p2.add(new JLabel(Res.iconMuteTitle)); |
p2.add(new JLabel(Res.gfxMuteTitle)); |
198 |
p2.add(btnMute); |
p2.add(btnMute); |
199 |
p2.add(new JLabel(Res.iconSoloTitle)); |
p2.add(new JLabel(Res.gfxSoloTitle)); |
200 |
p2.add(btnSolo); |
p2.add(btnSolo); |
201 |
|
|
202 |
p.add(p2); |
p.add(p2); |
208 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
209 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
210 |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
211 |
JLabel l = new JLabel(Res.iconVolumeTitle); |
JLabel l = new JLabel(Res.gfxVolumeTitle); |
212 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
213 |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
214 |
p2.add(l); |
p2.add(l); |
215 |
dialVolume.setDialPixmap(Res.iconVolumeDial, 30, 330); |
dialVolume.setDialPixmap(Res.gfxVolumeDial, 30, 330); |
216 |
dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
217 |
p2.add(dialVolume); |
p2.add(dialVolume); |
218 |
p.add(p2); |
p.add(p2); |
224 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
225 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
226 |
p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0)); |
p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0)); |
227 |
l = new JLabel(Res.iconOptionsTitle); |
l = new JLabel(Res.gfxOptionsTitle); |
228 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
229 |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
230 |
p2.add(l); |
p2.add(l); |
243 |
|
|
244 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
245 |
optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
|
add(p); |
|
|
add(optionsPane); |
|
246 |
|
|
247 |
setOpaque(true); |
mainPane = new JXCollapsiblePane(); |
248 |
|
mainPane.getContentPane().setLayout ( |
249 |
|
new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS) |
250 |
|
); |
251 |
|
|
252 |
|
mainPane.add(p); |
253 |
|
mainPane.add(optionsPane); |
254 |
|
|
255 |
|
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); |
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); |
292 |
|
mainPane.setCollapsed(true); |
293 |
|
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
294 |
|
mainPane.setCollapsed(false); |
295 |
|
|
296 |
|
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
297 |
|
public void |
298 |
|
propertyChange(PropertyChangeEvent e) { |
299 |
|
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 |
330 |
createVSeparator() { |
createVSeparator() { |
331 |
JPanel p = new JPanel(); |
PixmapPane p = new PixmapPane(Res.gfxVLine); |
|
p.setName("VSeparator"); |
|
|
p.setOpaque(false); |
|
332 |
p.setAlignmentY(JPanel.TOP_ALIGNMENT); |
p.setAlignmentY(JPanel.TOP_ALIGNMENT); |
333 |
p.setPreferredSize(new Dimension(2, 60)); |
p.setPreferredSize(new Dimension(2, 60)); |
334 |
p.setMinimumSize(p.getPreferredSize()); |
p.setMinimumSize(p.getPreferredSize()); |
356 |
|
|
357 |
/** Shows the channel properties. */ |
/** Shows the channel properties. */ |
358 |
public void |
public void |
359 |
expandChannel() { if(!btnOptions.isSelected()) btnOptions.doClick(); } |
expandChannel() { expandChannel(optionsPane.isAnimated()); } |
360 |
|
|
361 |
|
/** Shows the channel properties. */ |
362 |
|
public void |
363 |
|
expandChannel(boolean animated) { |
364 |
|
if(btnOptions.isSelected()) return; |
365 |
|
|
366 |
|
boolean b = optionsPane.isAnimated(); |
367 |
|
optionsPane.setAnimated(animated); |
368 |
|
btnOptions.doClick(); |
369 |
|
optionsPane.setAnimated(b); |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
/** Invoked when the user changes the volume */ |
/** Invoked when the user changes the volume */ |
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. |
402 |
screen.updateScreenInfo(sc); |
screen.updateScreenInfo(sc); |
403 |
updateMuteIcon(sc); |
updateMuteIcon(sc); |
404 |
|
|
405 |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.iconSoloOn); |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn); |
406 |
else btnSolo.setIcon(Res.iconSoloOff); |
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; |
420 |
*/ |
*/ |
421 |
private void |
private void |
422 |
updateMuteIcon(SamplerChannel channel) { |
updateMuteIcon(SamplerChannel channel) { |
423 |
if(channel.isMutedBySolo()) btnMute.setIcon(Res.iconMutedBySolo); |
if(channel.isMutedBySolo()) btnMute.setIcon(Res.gfxMutedBySolo); |
424 |
else if(channel.isMuted()) btnMute.setIcon(Res.iconMuteOn); |
else if(channel.isMuted()) btnMute.setIcon(Res.gfxMuteOn); |
425 |
else btnMute.setIcon(Res.iconMuteOff); |
else btnMute.setIcon(Res.gfxMuteOff); |
426 |
} |
} |
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 |
|
|
532 |
private class PowerButton extends PixmapToggleButton implements ActionListener { |
private class PowerButton extends PixmapToggleButton |
533 |
|
implements ActionListener, PropertyChangeListener { |
534 |
|
|
535 |
PowerButton() { |
PowerButton() { |
536 |
super(Res.iconPowerOff, Res.iconPowerOn); |
super(Res.gfxPowerOff, Res.gfxPowerOn); |
537 |
|
|
538 |
setSelected(true); |
setSelected(true); |
539 |
addActionListener(this); |
addActionListener(this); |
541 |
|
|
542 |
public void |
public void |
543 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
544 |
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
if(!mainPane.isAnimated()) { |
545 |
|
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
546 |
|
return; |
547 |
|
} |
548 |
|
|
549 |
|
String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
550 |
|
mainPane.addPropertyChangeListener(s, this); |
551 |
|
mainPane.setCollapsed(true); |
552 |
|
} |
553 |
|
|
554 |
|
public void |
555 |
|
propertyChange(PropertyChangeEvent e) { |
556 |
|
if(e.getNewValue() == "collapsed") { |
557 |
|
CC.getSamplerModel().removeBackendChannel(getChannelId()); |
558 |
|
} |
559 |
} |
} |
560 |
|
|
561 |
public boolean |
public boolean |
564 |
|
|
565 |
private class MuteButton extends PixmapButton implements ActionListener { |
private class MuteButton extends PixmapButton implements ActionListener { |
566 |
MuteButton() { |
MuteButton() { |
567 |
super(Res.iconMuteOff); |
super(Res.gfxMuteOff); |
568 |
setDisabledIcon(Res.iconMuteSoloDisabled); |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
569 |
|
setDisabledIcon ( |
570 |
|
SubstanceImageCreator.makeTransparent(this, Res.gfxMuteOff, 0.4) |
571 |
|
); |
572 |
addActionListener(this); |
addActionListener(this); |
573 |
} |
} |
574 |
|
|
585 |
b = false; |
b = false; |
586 |
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
587 |
|
|
588 |
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.iconMuteOff); |
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.gfxMuteOff); |
589 |
else setIcon(Res.iconMutedBySolo); |
else setIcon(Res.gfxMutedBySolo); |
590 |
} else setIcon(Res.iconMuteOn); |
} else setIcon(Res.gfxMuteOn); |
591 |
|
|
592 |
Channel.this.getModel().setBackendMute(b); |
Channel.this.getModel().setBackendMute(b); |
593 |
} |
} |
598 |
|
|
599 |
private class SoloButton extends PixmapButton implements ActionListener { |
private class SoloButton extends PixmapButton implements ActionListener { |
600 |
SoloButton() { |
SoloButton() { |
601 |
super(Res.iconSoloOff); |
super(Res.gfxSoloOff); |
602 |
setDisabledIcon(Res.iconMuteSoloDisabled); |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
603 |
|
setDisabledIcon ( |
604 |
|
SubstanceImageCreator.makeTransparent(this, Res.gfxSoloOff, 0.4) |
605 |
|
); |
606 |
addActionListener(this); |
addActionListener(this); |
607 |
} |
} |
608 |
|
|
616 |
* leaving the work to the notification mechanism of the LinuxSampler. |
* leaving the work to the notification mechanism of the LinuxSampler. |
617 |
*/ |
*/ |
618 |
if(b) { |
if(b) { |
619 |
setIcon(Res.iconSoloOn); |
setIcon(Res.gfxSoloOn); |
620 |
if(sc.isMutedBySolo()) btnMute.setIcon(Res.iconMuteOff); |
if(sc.isMutedBySolo()) btnMute.setIcon(Res.gfxMuteOff); |
621 |
} else { |
} else { |
622 |
setIcon(Res.iconSoloOff); |
setIcon(Res.gfxSoloOff); |
623 |
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
624 |
btnMute.setIcon(Res.iconMutedBySolo); |
btnMute.setIcon(Res.gfxMutedBySolo); |
625 |
} |
} |
626 |
|
|
627 |
Channel.this.getModel().setBackendSolo(b); |
Channel.this.getModel().setBackendSolo(b); |
633 |
|
|
634 |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
635 |
OptionsButton() { |
OptionsButton() { |
636 |
super(Res.iconOptionsOff, Res.iconOptionsOn); |
super(Res.gfxOptionsOff, Res.gfxOptionsOn); |
637 |
setRolloverIcon(Res.iconOptionsOffRO); |
setRolloverIcon(Res.gfxOptionsOffRO); |
638 |
this.setRolloverSelectedIcon(Res.iconOptionsOnRO); |
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
639 |
addActionListener(this); |
addActionListener(this); |
640 |
} |
} |
641 |
|
|
652 |
|
|
653 |
private void |
private void |
654 |
showOptionsPane(boolean show) { |
showOptionsPane(boolean show) { |
655 |
optionsPane.setVisible(show); |
optionsPane.setCollapsed(!show); |
|
MainFrame.repack(CC.getMainFrame()); |
|
656 |
} |
} |
657 |
|
|
658 |
public boolean |
public boolean |
660 |
} |
} |
661 |
} |
} |
662 |
|
|
663 |
class ChannelScreen extends JPanel { |
class ChannelPane extends PixmapPane { |
664 |
|
ChannelPane() { |
665 |
|
super(Res.gfxChannel); |
666 |
|
setPixmapInsets(new Insets(3, 3, 3, 3)); |
667 |
|
} |
668 |
|
} |
669 |
|
|
670 |
|
class ChannelScreen extends PixmapPane { |
671 |
private final Channel channel; |
private final Channel channel; |
|
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("--"); |
|
672 |
|
|
673 |
ChannelScreen(Channel channel) { |
private final InstrumentPane instrumentPane; |
674 |
|
|
675 |
|
private JButton btnInstr = |
676 |
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
677 |
|
|
678 |
|
private final JButton btnEditInstr = |
679 |
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
680 |
|
private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr); |
681 |
|
|
682 |
|
private final JButton btnFxSends = |
683 |
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends")); |
684 |
|
|
685 |
|
private final JButton btnEngine |
686 |
|
= createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine")); |
687 |
|
|
688 |
|
private final JPopupMenu menuEngines = new JPopupMenu(); |
689 |
|
|
690 |
|
private final JButton btnVolume = createScreenButton(""); |
691 |
|
private JSVolumeEditorPopup popupVolume; |
692 |
|
|
693 |
|
private final JLabel lStreams = createScreenLabel(" --"); |
694 |
|
private final JLabel lVoices = createScreenLabel("-- "); |
695 |
|
|
696 |
|
private InformationDialog fxSendsDlg = null; |
697 |
|
|
698 |
|
private Timer timer; |
699 |
|
|
700 |
|
private static NumberFormat numberFormat = NumberFormat.getInstance(); |
701 |
|
static { |
702 |
|
numberFormat.setMaximumFractionDigits(1); |
703 |
|
} |
704 |
|
|
705 |
|
ChannelScreen(final Channel channel) { |
706 |
|
super(Res.gfxChannelScreen); |
707 |
|
setPixmapInsets(new Insets(6, 6, 6, 6)); |
708 |
|
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
709 |
|
|
710 |
this.channel = channel; |
this.channel = channel; |
711 |
|
popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.CHANNEL); |
712 |
|
|
713 |
setName("ChannelScreen"); |
setOpaque(false); |
|
setOpaque(true); |
|
714 |
|
|
715 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
716 |
|
|
|
btnInstr.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
|
717 |
btnInstr.setAlignmentX(CENTER_ALIGNMENT); |
btnInstr.setAlignmentX(CENTER_ALIGNMENT); |
718 |
|
btnInstr.setRolloverEnabled(false); |
719 |
|
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
720 |
|
|
721 |
add(btnInstr); |
instrumentPane = new InstrumentPane(); |
722 |
|
add(instrumentPane); |
723 |
|
|
724 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
|
p.setOpaque(false); |
|
725 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
726 |
p.setAlignmentX(CENTER_ALIGNMENT); |
p.setAlignmentX(CENTER_ALIGNMENT); |
727 |
p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
p.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 0)); |
728 |
//lVolume.setFont(lVolume.getFont().deriveFont(java.awt.Font.PLAIN)); |
|
729 |
|
btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt")); |
730 |
|
btnFxSends.addActionListener(new ActionListener() { |
731 |
|
public void |
732 |
|
actionPerformed(ActionEvent e) { |
733 |
|
if(fxSendsDlg != null && fxSendsDlg.isVisible()) { |
734 |
|
fxSendsDlg.toFront(); |
735 |
|
return; |
736 |
|
} |
737 |
|
FxSendsPane p = new FxSendsPane(channel.getModel()); |
738 |
|
int id = channel.getModel().getChannelId(); |
739 |
|
fxSendsDlg = new InformationDialog(CC.getMainFrame(), p); |
740 |
|
fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id)); |
741 |
|
fxSendsDlg.setModal(false); |
742 |
|
fxSendsDlg.showCloseButton(false); |
743 |
|
fxSendsDlg.setVisible(true); |
744 |
|
} |
745 |
|
}); |
746 |
|
|
747 |
p.add(btnDuplicate); |
p.add(btnFxSends); |
748 |
|
|
749 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
750 |
|
p.add(Box.createGlue()); |
751 |
|
|
752 |
p.add(new JLabel("|")); |
btnEngine.setIcon(Res.iconEngine12); |
753 |
|
btnEngine.setIconTextGap(1); |
754 |
|
p.add(btnEngine); |
755 |
|
//p.add(new Label("|")); |
756 |
|
|
757 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
758 |
|
|
759 |
p.add(btnReset); |
//p.add(btnReset); |
760 |
|
|
761 |
p.add(Box.createGlue()); |
p.add(Box.createGlue()); |
762 |
|
|
763 |
|
lStreams.setFont(Res.fontScreenMono); |
764 |
|
lStreams.setHorizontalAlignment(JLabel.RIGHT); |
765 |
|
lStreams.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
766 |
p.add(lStreams); |
p.add(lStreams); |
767 |
p.add(new JLabel("/")); |
|
768 |
|
JLabel l = createScreenLabel("/"); |
769 |
|
l.setFont(Res.fontScreenMono); |
770 |
|
l.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
771 |
|
p.add(l); |
772 |
|
|
773 |
|
lVoices.setFont(Res.fontScreenMono); |
774 |
|
lVoices.setToolTipText(i18n.getLabel("ChannelScreen.streamVoiceCount")); |
775 |
p.add(lVoices); |
p.add(lVoices); |
776 |
|
|
777 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
btnVolume.setIcon(Res.iconVolume14); |
778 |
|
btnVolume.setIconTextGap(2); |
779 |
|
btnVolume.setAlignmentX(RIGHT_ALIGNMENT); |
780 |
|
btnVolume.setHorizontalAlignment(btnVolume.LEFT); |
781 |
|
updateVolumeInfo(100); |
782 |
|
Dimension d = btnVolume.getPreferredSize(); |
783 |
|
d.width = 60; |
784 |
|
btnVolume.setPreferredSize(d); |
785 |
|
btnVolume.setMinimumSize(d); |
786 |
|
|
787 |
|
btnVolume.addActionListener(new ActionListener() { |
788 |
|
public void |
789 |
|
actionPerformed(ActionEvent e) { |
790 |
|
if(popupVolume.isVisible()) { |
791 |
|
popupVolume.commit(); |
792 |
|
popupVolume.hide(); |
793 |
|
} else { |
794 |
|
float vol = channel.getModel().getChannelInfo().getVolume(); |
795 |
|
popupVolume.setCurrentVolume(vol); |
796 |
|
popupVolume.show(); |
797 |
|
} |
798 |
|
} |
799 |
|
}); |
800 |
|
|
801 |
|
popupVolume.addActionListener(new ActionListener() { |
802 |
|
public void |
803 |
|
actionPerformed(ActionEvent e) { |
804 |
|
channel.getModel().setBackendVolume(popupVolume.getVolumeFactor()); |
805 |
|
} |
806 |
|
}); |
807 |
|
|
808 |
lVolume.setAlignmentX(RIGHT_ALIGNMENT); |
p.add(btnVolume); |
809 |
p.add(lVolume); |
p.setPreferredSize(new Dimension(260, p.getPreferredSize().height)); |
|
p.setPreferredSize(new Dimension(250, p.getPreferredSize().height)); |
|
810 |
p.setMinimumSize(p.getPreferredSize()); |
p.setMinimumSize(p.getPreferredSize()); |
811 |
p.setMaximumSize(p.getPreferredSize()); |
p.setMaximumSize(p.getPreferredSize()); |
812 |
|
|
813 |
|
//btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
814 |
|
p.setOpaque(false); |
815 |
add(p); |
add(p); |
816 |
|
|
817 |
|
|
819 |
setMinimumSize(getPreferredSize()); |
setMinimumSize(getPreferredSize()); |
820 |
setMaximumSize(getPreferredSize()); |
setMaximumSize(getPreferredSize()); |
821 |
|
|
822 |
|
createEngineMenu(); |
823 |
installListeners(); |
installListeners(); |
824 |
} |
} |
825 |
|
|
826 |
|
protected void |
827 |
|
onDestroy() { timer.stop(); } |
828 |
|
|
829 |
|
private void |
830 |
|
createEngineMenu() { |
831 |
|
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) { |
832 |
|
JMenuItem mi = new JMenuItem(engine.getName() + " engine"); |
833 |
|
mi.setToolTipText(engine.getDescription()); |
834 |
|
|
835 |
|
mi.addActionListener(new ActionListener() { |
836 |
|
public void |
837 |
|
actionPerformed(ActionEvent e) { |
838 |
|
channel.getModel().setBackendEngineType(engine.getName()); |
839 |
|
} |
840 |
|
}); |
841 |
|
|
842 |
|
menuEngines.add(mi); |
843 |
|
} |
844 |
|
} |
845 |
|
|
846 |
private void |
private void |
847 |
installListeners() { |
installListeners() { |
848 |
btnInstr.addActionListener(new ActionListener() { |
btnInstr.addActionListener(new ActionListener() { |
849 |
public void |
public void |
850 |
actionPerformed(ActionEvent e) { loadInstrument(); } |
actionPerformed(ActionEvent e) { loadInstrument(); } |
851 |
}); |
}); |
852 |
|
|
853 |
btnReset.addActionListener(new ActionListener() { |
btnEditInstr.addActionListener(new ActionListener() { |
854 |
public void |
public void |
855 |
actionPerformed(ActionEvent e) { channel.getModel().resetBackendChannel(); } |
actionPerformed(ActionEvent e) { |
856 |
|
CC.getSamplerModel().editBackendInstrument(channel.getChannelId()); |
857 |
|
} |
858 |
}); |
}); |
859 |
|
|
860 |
btnDuplicate.addActionListener(new ActionListener() { |
btnEngine.addActionListener(new ActionListener() { |
861 |
public void |
public void |
862 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
863 |
channel.getModel().duplicateBackendChannel(); |
int y = btnEngine.getHeight() + 1; |
864 |
|
menuEngines.show(btnEngine, 0, y); |
865 |
} |
} |
866 |
}); |
}); |
867 |
|
|
868 |
|
addMouseListener(getHandler()); |
869 |
|
addHierarchyListener(getHandler()); |
870 |
|
|
871 |
|
ActionListener l = new ActionListener() { |
872 |
|
public void |
873 |
|
actionPerformed(ActionEvent e) { |
874 |
|
if(getMousePosition(true) != null) { |
875 |
|
getHandler().mouseEntered(null); |
876 |
|
} else { |
877 |
|
getHandler().mouseExited(null); |
878 |
|
} |
879 |
|
} |
880 |
|
}; |
881 |
|
timer = new Timer(1000, l); |
882 |
|
timer.start(); |
883 |
} |
} |
884 |
|
|
885 |
private void |
private void |
886 |
loadInstrument() { |
loadInstrument() { |
887 |
InstrumentChooser dlg = new InstrumentChooser(CC.getMainFrame()); |
JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame()); |
888 |
dlg.setVisible(true); |
dlg.setVisible(true); |
889 |
|
|
890 |
if(!dlg.isCancelled()) { |
if(!dlg.isCancelled()) { |
891 |
SamplerChannelModel m = channel.getModel(); |
SamplerChannelModel m = channel.getModel(); |
892 |
m.loadBackendInstrument(dlg.getFileName(), dlg.getInstrumentIndex()); |
m.loadBackendInstrument(dlg.getInstrumentFile(), dlg.getInstrumentIndex()); |
893 |
} |
} |
894 |
} |
} |
895 |
|
|
906 |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
907 |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
908 |
} |
} |
|
|
|
909 |
|
|
910 |
|
instrumentPane.update(); |
911 |
|
|
912 |
|
if(sc.getEngine() != null) { |
913 |
|
String s = sc.getEngine().getName(); |
914 |
|
s += " engine"; |
915 |
|
if(!s.equals(btnEngine.getText())) { |
916 |
|
btnEngine.setText(s); |
917 |
|
btnEngine.setToolTipText(sc.getEngine().getDescription()); |
918 |
|
} |
919 |
|
} |
920 |
|
|
921 |
} |
} |
922 |
|
|
923 |
protected void |
protected void |
924 |
updateVolumeInfo(int volume) { |
updateVolumeInfo(int volume) { |
925 |
lVolume.setText(i18n.getLabel("ChannelScreen.volume", volume)); |
if(CC.getViewConfig().isMeasurementUnitDecibel()) { |
926 |
|
String s = numberFormat.format(HF.percentsToDecibels(volume)); |
927 |
|
btnVolume.setText(s + "dB"); |
928 |
|
} else { |
929 |
|
btnVolume.setText(String.valueOf(volume) + "%"); |
930 |
|
} |
931 |
} |
} |
932 |
|
|
933 |
/** |
/** |
958 |
lVoices.setMaximumSize(d); |
lVoices.setMaximumSize(d); |
959 |
} |
} |
960 |
|
|
961 |
static class ScreenButton extends JButton { |
class InstrumentPane extends JPanel { |
962 |
ScreenButton(String s) { |
private final JPanel leftPane = new JPanel(); |
963 |
super(s); |
private final JPanel rightPane = new JPanel(); |
964 |
setContentAreaFilled(false); |
|
965 |
setFocusPainted(false); |
InstrumentPane() { |
966 |
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
setOpaque(false); |
967 |
setMargin(new Insets(0, 0, 0, 0)); |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
968 |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
add(leftPane); |
969 |
|
add(btnInstr); |
970 |
|
add(rightPane); |
971 |
|
add(sbbEditInstr); |
972 |
|
btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt")); |
973 |
|
sbbEditInstr.setVisible(false); |
974 |
|
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); |
975 |
|
|
976 |
|
update(); |
977 |
|
} |
978 |
|
|
979 |
|
public void |
980 |
|
update() { |
981 |
|
int a = btnInstr.getMinimumSize().width; |
982 |
|
int b = 0; |
983 |
|
if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width; |
984 |
|
|
985 |
|
int max = 254 - b; |
986 |
|
if(a > max) a = max; |
987 |
|
|
988 |
|
int h = btnInstr.getPreferredSize().height; |
989 |
|
btnInstr.setPreferredSize(new Dimension(a, h)); |
990 |
|
h = btnInstr.getMaximumSize().height; |
991 |
|
btnInstr.setMaximumSize(new Dimension(a, h)); |
992 |
|
|
993 |
|
|
994 |
|
int i = (254 - btnInstr.getPreferredSize().width) / 2; |
995 |
|
|
996 |
|
int j = i; |
997 |
|
if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width; |
998 |
|
if(i < 0 || j < 0) i = j = 0; |
999 |
|
|
1000 |
|
Dimension d = new Dimension(i, 1); |
1001 |
|
leftPane.setMinimumSize(d); |
1002 |
|
leftPane.setPreferredSize(d); |
1003 |
|
leftPane.setMaximumSize(d); |
1004 |
|
|
1005 |
|
d = new Dimension(j, 1); |
1006 |
|
rightPane.setMinimumSize(d); |
1007 |
|
rightPane.setPreferredSize(d); |
1008 |
|
rightPane.setMaximumSize(d); |
1009 |
|
|
1010 |
|
validate(); |
1011 |
|
} |
1012 |
|
} |
1013 |
|
|
1014 |
|
class FxSendsPane extends JSFxSendsPane { |
1015 |
|
FxSendsPane(SamplerChannelModel model) { |
1016 |
|
super(model); |
1017 |
|
|
1018 |
|
actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16); |
1019 |
|
actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16); |
1020 |
|
} |
1021 |
|
|
1022 |
|
protected JToolBar |
1023 |
|
createToolBar() { |
1024 |
|
JToolBar tb = new JToolBar(); |
1025 |
|
Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height); |
1026 |
|
tb.setMaximumSize(d); |
1027 |
|
tb.setFloatable(false); |
1028 |
|
tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT); |
1029 |
|
|
1030 |
|
tb.add(new ToolbarButton(actionAddFxSend)); |
1031 |
|
tb.add(new ToolbarButton(actionRemoveFxSend)); |
1032 |
|
|
1033 |
|
return tb; |
1034 |
|
} |
1035 |
|
} |
1036 |
|
|
1037 |
|
static class ScreenButtonBg extends PixmapPane { |
1038 |
|
ScreenButtonBg(JButton btn) { |
1039 |
|
super(Res.gfxScreenBtnBg); |
1040 |
|
setPixmapInsets(new Insets(4, 4, 4, 4)); |
1041 |
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
1042 |
|
setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7)); |
1043 |
|
add(btn); |
1044 |
|
setPreferredSize(new Dimension(getPreferredSize().width, 13)); |
1045 |
|
} |
1046 |
|
|
1047 |
|
public Dimension |
1048 |
|
getPreferredSize() { |
1049 |
|
return new Dimension(super.getPreferredSize().width, 13); |
1050 |
|
} |
1051 |
|
} |
1052 |
|
|
1053 |
|
|
1054 |
|
private final EventHandler eventHandler = new EventHandler(); |
1055 |
|
|
1056 |
|
private EventHandler |
1057 |
|
getHandler() { return eventHandler; } |
1058 |
|
|
1059 |
|
private class EventHandler extends MouseAdapter implements HierarchyListener { |
1060 |
|
public void |
1061 |
|
mouseEntered(MouseEvent e) { |
1062 |
|
if(channel.getChannelInfo().getInstrumentStatus() != 100) return; |
1063 |
|
|
1064 |
|
if(!sbbEditInstr.isVisible()) { |
1065 |
|
sbbEditInstr.setVisible(true); |
1066 |
|
instrumentPane.update(); |
1067 |
|
} |
1068 |
|
} |
1069 |
|
|
1070 |
|
public void |
1071 |
|
mouseExited(MouseEvent e) { |
1072 |
|
if(getMousePosition(true) != null) return; |
1073 |
|
if(sbbEditInstr.isVisible()) { |
1074 |
|
sbbEditInstr.setVisible(false); |
1075 |
|
instrumentPane.update(); |
1076 |
|
} |
1077 |
|
} |
1078 |
|
|
1079 |
|
/** Called when the hierarchy has been changed. */ |
1080 |
|
public void |
1081 |
|
hierarchyChanged(HierarchyEvent e) { |
1082 |
|
if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) { |
1083 |
|
if(getMousePosition() == null) mouseExited(null); |
1084 |
|
else mouseEntered(null); |
1085 |
|
} |
1086 |
} |
} |
1087 |
} |
} |
1088 |
} |
} |
1089 |
|
|
1090 |
class ChannelOptions extends JPanel { |
class ChannelOptions extends JXCollapsiblePane { |
1091 |
private final Channel channel; |
private final Channel channel; |
1092 |
|
private MidiDeviceModel midiDevice = null; |
1093 |
|
|
1094 |
|
private final JComboBox cbMidiDevice = new FantasiaComboBox(); |
1095 |
|
private final JComboBox cbMidiPort = new FantasiaComboBox(); |
1096 |
|
private final JComboBox cbMidiChannel = new FantasiaComboBox(); |
1097 |
|
private final JComboBox cbInstrumentMap = new FantasiaComboBox(); |
1098 |
|
private final JComboBox cbAudioDevice = new FantasiaComboBox(); |
1099 |
|
|
1100 |
private final JComboBox cbMidiDevice = new JComboBox(); |
private final PixmapButton btnChannelRouting; |
|
private final JComboBox cbMidiPort = new JComboBox(); |
|
|
private final JComboBox cbMidiChannel = new JComboBox(); |
|
|
private final JComboBox cbEngine = new JComboBox(); |
|
|
private final JComboBox cbAudioDevice = new JComboBox(); |
|
1101 |
|
|
1102 |
private boolean update = false; |
private boolean update = false; |
1103 |
|
|
1104 |
ChannelOptions(Channel channel) { |
private final SamplerListener samplerListener; |
1105 |
|
private final MapListListener mapListListener = new MapListListener(); |
1106 |
|
|
1107 |
|
private class NoMap { |
1108 |
|
public String |
1109 |
|
toString() { return "[None]"; } |
1110 |
|
} |
1111 |
|
|
1112 |
|
private NoMap noMap = new NoMap(); |
1113 |
|
|
1114 |
|
private class DefaultMap { |
1115 |
|
public String |
1116 |
|
toString() { return "[Default]"; } |
1117 |
|
} |
1118 |
|
|
1119 |
|
private DefaultMap defaultMap = new DefaultMap(); |
1120 |
|
|
1121 |
|
ChannelOptions(final Channel channel) { |
1122 |
|
setAnimated(false); |
1123 |
|
setCollapsed(true); |
1124 |
|
setAnimated(preferences().getBoolProperty(ANIMATED)); |
1125 |
|
|
1126 |
|
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
1127 |
|
public void |
1128 |
|
propertyChange(PropertyChangeEvent e) { |
1129 |
|
setAnimated(preferences().getBoolProperty(ANIMATED)); |
1130 |
|
} |
1131 |
|
}); |
1132 |
|
|
1133 |
|
PixmapPane bgp = new PixmapPane(Res.gfxChannelOptions); |
1134 |
|
bgp.setPixmapInsets(new Insets(1, 1, 1, 1)); |
1135 |
|
|
1136 |
this.channel = channel; |
this.channel = channel; |
1137 |
|
|
1138 |
setName("ChannelOptions"); |
bgp.setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4)); |
1139 |
setVisible(false); |
bgp.setLayout(new BoxLayout(bgp, BoxLayout.X_AXIS)); |
|
setBorder(BorderFactory.createEmptyBorder(5, 4, 5, 4)); |
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
|
1140 |
|
|
1141 |
setPreferredSize(new Dimension(420, 44)); |
bgp.setPreferredSize(new Dimension(420, 44)); |
1142 |
setMinimumSize(getPreferredSize()); |
bgp.setMinimumSize(getPreferredSize()); |
1143 |
setMaximumSize(getPreferredSize()); |
bgp.setMaximumSize(getPreferredSize()); |
1144 |
|
|
1145 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
|
p.setOpaque(true); |
|
1146 |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
1147 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
1148 |
JLabel l = new JLabel(Res.iconMidiInputTitle); |
JLabel l = new JLabel(Res.gfxMidiInputTitle); |
1149 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1150 |
p.add(l); |
p.add(l); |
1151 |
|
|
1166 |
o = cbMidiPort.getRenderer(); |
o = cbMidiPort.getRenderer(); |
1167 |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER); |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.CENTER); |
1168 |
|
|
1169 |
cbMidiPort.setPreferredSize(new Dimension(67, 18)); |
cbMidiPort.setPreferredSize(new Dimension(62, 18)); |
1170 |
cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize()); |
cbMidiPort.setMinimumSize(cbMidiPort.getPreferredSize()); |
1171 |
cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize()); |
cbMidiPort.setMaximumSize(cbMidiPort.getPreferredSize()); |
1172 |
p2.add(cbMidiPort); |
p2.add(cbMidiPort); |
1184 |
|
|
1185 |
p2.add(cbMidiChannel); |
p2.add(cbMidiChannel); |
1186 |
p2.setAlignmentX(LEFT_ALIGNMENT); |
p2.setAlignmentX(LEFT_ALIGNMENT); |
1187 |
|
p2.setOpaque(false); |
1188 |
p.add(p2); |
p.add(p2); |
1189 |
|
p.setBackground(new java.awt.Color(0x818181)); |
1190 |
|
|
1191 |
add(p); |
bgp.add(p); |
1192 |
|
|
1193 |
add(Box.createRigidArea(new Dimension(4, 0))); |
bgp.add(Box.createRigidArea(new Dimension(4, 0))); |
1194 |
|
|
1195 |
p = new JPanel(); |
p = new JPanel(); |
1196 |
p.setOpaque(true); |
p.setOpaque(true); |
1197 |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
1198 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
1199 |
l = new JLabel(Res.iconEngineTitle); |
l = new JLabel(Res.gfxInstrumentMapTitle); |
1200 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1201 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1202 |
p.add(l); |
p.add(l); |
1203 |
|
|
1204 |
p.add(Box.createRigidArea(new Dimension(0, 3))); |
p.add(Box.createRigidArea(new Dimension(0, 3))); |
1205 |
|
|
1206 |
o = cbEngine.getRenderer(); |
//o = cbInstrumentMap.getRenderer(); |
1207 |
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); |
|
1208 |
|
|
1209 |
add(p); |
cbInstrumentMap.setPreferredSize(new Dimension(126, 18)); |
1210 |
|
cbInstrumentMap.setMinimumSize(cbInstrumentMap.getPreferredSize()); |
1211 |
|
cbInstrumentMap.setMaximumSize(cbInstrumentMap.getPreferredSize()); |
1212 |
|
cbInstrumentMap.setAlignmentX(LEFT_ALIGNMENT); |
1213 |
|
p.add(cbInstrumentMap); |
1214 |
|
p.setBackground(new java.awt.Color(0x818181)); |
1215 |
|
bgp.add(p); |
1216 |
|
|
1217 |
add(Box.createRigidArea(new Dimension(4, 0))); |
bgp.add(Box.createRigidArea(new Dimension(4, 0))); |
1218 |
|
|
1219 |
p = new JPanel(); |
p = new JPanel(); |
1220 |
p.setOpaque(true); |
p.setOpaque(true); |
1221 |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
p.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 4)); |
1222 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
1223 |
l = new JLabel(Res.iconAudioOutputTitle); |
l = new JLabel(Res.gfxAudioOutputTitle); |
|
l.setAlignmentX(LEFT_ALIGNMENT); |
|
1224 |
l.setAlignmentX(LEFT_ALIGNMENT); |
l.setAlignmentX(LEFT_ALIGNMENT); |
1225 |
p.add(l); |
p.add(l); |
1226 |
|
|
1227 |
p.add(Box.createRigidArea(new Dimension(0, 3))); |
//p.add(Box.createRigidArea(new Dimension(0, 3))); |
1228 |
|
|
1229 |
|
p2 = new JPanel(); |
1230 |
|
p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
1231 |
|
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
1232 |
|
p2.setOpaque(false); |
1233 |
|
p2.setAlignmentX(LEFT_ALIGNMENT); |
1234 |
|
|
1235 |
o = cbAudioDevice.getRenderer(); |
o = cbAudioDevice.getRenderer(); |
1236 |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT); |
if(o instanceof JLabel) ((JLabel )o).setHorizontalAlignment(SwingConstants.RIGHT); |
1237 |
|
|
1238 |
cbAudioDevice.setPreferredSize(new Dimension(61, 18)); |
cbAudioDevice.setPreferredSize(new Dimension(40, 18)); |
1239 |
cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize()); |
cbAudioDevice.setMinimumSize(cbAudioDevice.getPreferredSize()); |
1240 |
cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize()); |
cbAudioDevice.setMaximumSize(cbAudioDevice.getPreferredSize()); |
|
cbAudioDevice.setAlignmentX(LEFT_ALIGNMENT); |
|
|
p.add(cbAudioDevice); |
|
1241 |
|
|
1242 |
add(p); |
p2.add(cbAudioDevice); |
1243 |
|
p2.add(Box.createRigidArea(new Dimension(3, 0))); |
1244 |
|
btnChannelRouting = new PixmapButton(Res.gfxBtnCr, Res.gfxBtnCrRO); |
1245 |
|
btnChannelRouting.setPressedIcon(Res.gfxBtnCrRO); |
1246 |
|
btnChannelRouting.setEnabled(false); |
1247 |
|
btnChannelRouting.setToolTipText(i18n.getLabel("ChannelOptions.routing")); |
1248 |
|
|
1249 |
|
btnChannelRouting.addActionListener(new ActionListener() { |
1250 |
|
public void |
1251 |
|
actionPerformed(ActionEvent e) { |
1252 |
|
SamplerChannel c = channel.getChannelInfo(); |
1253 |
|
new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true); |
1254 |
|
|
1255 |
|
} |
1256 |
|
}); |
1257 |
|
|
1258 |
|
p2.add(btnChannelRouting); |
1259 |
|
|
1260 |
|
p.add(p2); |
1261 |
|
p.setBackground(new java.awt.Color(0x818181)); |
1262 |
|
p2 = new JPanel(); |
1263 |
|
p2.setLayout(new java.awt.BorderLayout()); |
1264 |
|
p.add(p2); |
1265 |
|
bgp.add(p); |
1266 |
|
|
1267 |
|
setContentPane(bgp); |
1268 |
|
|
1269 |
cbMidiDevice.addActionListener(new ActionListener() { |
cbMidiDevice.addActionListener(new ActionListener() { |
1270 |
public void |
public void |
1281 |
actionPerformed(ActionEvent e) { setMidiChannel(); } |
actionPerformed(ActionEvent e) { setMidiChannel(); } |
1282 |
}); |
}); |
1283 |
|
|
1284 |
cbEngine.addActionListener(new ActionListener() { |
samplerListener = new SamplerAdapter() { |
1285 |
|
/** Invoked when the default MIDI instrument map is changed. */ |
1286 |
|
public void |
1287 |
|
defaultMapChanged(SamplerEvent e) { |
1288 |
|
updateCbInstrumentMapToolTipText(); |
1289 |
|
|
1290 |
|
} |
1291 |
|
}; |
1292 |
|
|
1293 |
|
CC.getSamplerModel().addSamplerListener(samplerListener); |
1294 |
|
|
1295 |
|
cbInstrumentMap.addItem(noMap); |
1296 |
|
cbInstrumentMap.addItem(defaultMap); |
1297 |
|
for(MidiInstrumentMap map : CC.getSamplerModel().getMidiInstrumentMaps()) { |
1298 |
|
cbInstrumentMap.addItem(map); |
1299 |
|
} |
1300 |
|
|
1301 |
|
int map = channel.getModel().getChannelInfo().getMidiInstrumentMapId(); |
1302 |
|
cbInstrumentMap.setSelectedItem(CC.getSamplerModel().getMidiInstrumentMapById(map)); |
1303 |
|
if(cbInstrumentMap.getSelectedItem() == null) { |
1304 |
|
if(map == -1) cbInstrumentMap.setSelectedItem(noMap); |
1305 |
|
else if(map == -2) { |
1306 |
|
cbInstrumentMap.setSelectedItem(defaultMap); |
1307 |
|
} |
1308 |
|
} |
1309 |
|
|
1310 |
|
updateCbInstrumentMapToolTipText(); |
1311 |
|
|
1312 |
|
if(channel.getModel().getChannelInfo().getEngine() == null) { |
1313 |
|
cbInstrumentMap.setEnabled(false); |
1314 |
|
} |
1315 |
|
|
1316 |
|
cbInstrumentMap.addActionListener(new ActionListener() { |
1317 |
public void |
public void |
1318 |
actionPerformed(ActionEvent e) { setEngineType(); } |
actionPerformed(ActionEvent e) { updateInstrumentMap(); } |
1319 |
}); |
}); |
1320 |
|
|
1321 |
|
CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener); |
1322 |
|
|
1323 |
cbAudioDevice.addActionListener(new ActionListener() { |
cbAudioDevice.addActionListener(new ActionListener() { |
1324 |
public void |
public void |
1325 |
actionPerformed(ActionEvent e) { setBackendAudioDevice(); } |
actionPerformed(ActionEvent e) { setBackendAudioDevice(); } |
1347 |
SamplerModel sm = CC.getSamplerModel(); |
SamplerModel sm = CC.getSamplerModel(); |
1348 |
SamplerChannel sc = channel.getModel().getChannelInfo(); |
SamplerChannel sc = channel.getModel().getChannelInfo(); |
1349 |
|
|
1350 |
MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice()); |
MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice()); |
1351 |
AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice()); |
AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice()); |
1352 |
|
|
1353 |
if(isUpdate()) CC.getLogger().warning("Unexpected update state!"); |
if(isUpdate()) CC.getLogger().warning("Unexpected update state!"); |
1354 |
|
|
1357 |
try { |
try { |
1358 |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
1359 |
|
|
|
cbEngine.setSelectedItem(sc.getEngine()); |
|
|
|
|
1360 |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
1361 |
|
btnChannelRouting.setEnabled(am != null); |
1362 |
} catch(Exception x) { |
} catch(Exception x) { |
1363 |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
1364 |
} |
} |
1365 |
|
|
1366 |
|
if(sc.getEngine() != null) { |
1367 |
|
cbInstrumentMap.setEnabled(true); |
1368 |
|
int id = sc.getMidiInstrumentMapId(); |
1369 |
|
Object o; |
1370 |
|
if(id == -2) o = defaultMap; |
1371 |
|
else if(id == -1) o = noMap; |
1372 |
|
else o = CC.getSamplerModel().getMidiInstrumentMapById(id); |
1373 |
|
|
1374 |
|
if(cbInstrumentMap.getSelectedItem() != o) { |
1375 |
|
cbInstrumentMap.setSelectedItem(o); |
1376 |
|
} |
1377 |
|
} else { |
1378 |
|
cbInstrumentMap.setSelectedItem(noMap); |
1379 |
|
cbInstrumentMap.setEnabled(false); |
1380 |
|
} |
1381 |
|
|
1382 |
setUpdate(false); |
setUpdate(false); |
1383 |
} |
} |
1384 |
|
|
1395 |
try { |
try { |
1396 |
cbMidiDevice.removeAllItems(); |
cbMidiDevice.removeAllItems(); |
1397 |
|
|
1398 |
for(MidiDeviceModel m : sm.getMidiDeviceModels()) |
for(MidiDeviceModel m : sm.getMidiDevices()) |
1399 |
cbMidiDevice.addItem(m.getDeviceInfo()); |
cbMidiDevice.addItem(m.getDeviceInfo()); |
1400 |
|
|
1401 |
MidiDeviceModel mm = sm.getMidiDeviceModel(sc.getMidiInputDevice()); |
MidiDeviceModel mm = sm.getMidiDeviceById(sc.getMidiInputDevice()); |
1402 |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
cbMidiDevice.setSelectedItem(mm == null ? null : mm.getDeviceInfo()); |
1403 |
} catch(Exception x) { |
} catch(Exception x) { |
1404 |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
1407 |
setUpdate(false); |
setUpdate(false); |
1408 |
} |
} |
1409 |
|
|
1410 |
|
|
1411 |
|
private void |
1412 |
|
updateInstrumentMap() { |
1413 |
|
updateCbInstrumentMapToolTipText(); |
1414 |
|
|
1415 |
|
int id = channel.getModel().getChannelInfo().getMidiInstrumentMapId(); |
1416 |
|
Object o = cbInstrumentMap.getSelectedItem(); |
1417 |
|
if(o == null && id == -1) return; |
1418 |
|
|
1419 |
|
int cbId; |
1420 |
|
if(o == null || o == noMap) cbId = -1; |
1421 |
|
else if(o == defaultMap) cbId = -2; |
1422 |
|
else cbId = ((MidiInstrumentMap)o).getMapId(); |
1423 |
|
|
1424 |
|
if(cbId == id) return; |
1425 |
|
|
1426 |
|
channel.getModel().setBackendMidiInstrumentMap(cbId); |
1427 |
|
} |
1428 |
|
|
1429 |
|
private void |
1430 |
|
updateCbInstrumentMapToolTipText() { |
1431 |
|
if(cbInstrumentMap.getSelectedItem() != defaultMap) { |
1432 |
|
cbInstrumentMap.setToolTipText(null); |
1433 |
|
return; |
1434 |
|
} |
1435 |
|
|
1436 |
|
MidiInstrumentMap m = CC.getSamplerModel().getDefaultMidiInstrumentMap(); |
1437 |
|
if(m != null) { |
1438 |
|
String s = i18n.getLabel("Channel.ttDefault", m.getName()); |
1439 |
|
cbInstrumentMap.setToolTipText(s); |
1440 |
|
} else { |
1441 |
|
cbInstrumentMap.setToolTipText(null); |
1442 |
|
} |
1443 |
|
} |
1444 |
|
|
1445 |
/** |
/** |
1446 |
* Updates the audio device list. |
* Updates the audio device list. |
1447 |
*/ |
*/ |
1455 |
try { |
try { |
1456 |
cbAudioDevice.removeAllItems(); |
cbAudioDevice.removeAllItems(); |
1457 |
|
|
1458 |
for(AudioDeviceModel m : sm.getAudioDeviceModels()) |
for(AudioDeviceModel m : sm.getAudioDevices()) |
1459 |
cbAudioDevice.addItem(m.getDeviceInfo()); |
cbAudioDevice.addItem(m.getDeviceInfo()); |
1460 |
|
|
1461 |
AudioDeviceModel am = sm.getAudioDeviceModel(sc.getAudioOutputDevice()); |
AudioDeviceModel am = sm.getAudioDeviceById(sc.getAudioOutputDevice()); |
1462 |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
cbAudioDevice.setSelectedItem(am == null ? null : am.getDeviceInfo()); |
1463 |
} catch(Exception x) { |
} catch(Exception x) { |
1464 |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
CC.getLogger().log(Level.WARNING, "Unkown error", x); |
1479 |
return; |
return; |
1480 |
} |
} |
1481 |
|
|
1482 |
|
if(midiDevice != null) midiDevice.removeMidiDeviceListener(getHandler()); |
1483 |
|
|
1484 |
cbMidiPort.removeAllItems(); |
cbMidiPort.removeAllItems(); |
1485 |
|
|
1486 |
if(mid == null) { |
if(mid == null) { |
1487 |
|
midiDevice = null; |
1488 |
cbMidiPort.setEnabled(false); |
cbMidiPort.setEnabled(false); |
1489 |
|
|
1490 |
cbMidiChannel.setSelectedItem(null); |
cbMidiChannel.setSelectedItem(null); |
1491 |
cbMidiChannel.setEnabled(false); |
cbMidiChannel.setEnabled(false); |
1492 |
} else { |
} else { |
1493 |
|
midiDevice = CC.getSamplerModel().getMidiDeviceById(mid.getDeviceId()); |
1494 |
|
if(midiDevice != null) midiDevice.addMidiDeviceListener(getHandler()); |
1495 |
|
|
1496 |
cbMidiPort.setEnabled(true); |
cbMidiPort.setEnabled(true); |
1497 |
|
|
1498 |
MidiPort[] ports = mid.getMidiPorts(); |
MidiPort[] ports = mid.getMidiPorts(); |
1527 |
channel.getModel().setBackendMidiInputChannel(c); |
channel.getModel().setBackendMidiInputChannel(c); |
1528 |
} |
} |
1529 |
|
|
|
/** 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()); |
|
|
|
|
|
} |
|
|
|
|
1530 |
private void |
private void |
1531 |
setBackendAudioDevice() { |
setBackendAudioDevice() { |
1532 |
if(isUpdate()) return; |
if(isUpdate()) return; |
1551 |
private void |
private void |
1552 |
setUpdate(boolean b) { update = b; } |
setUpdate(boolean b) { update = b; } |
1553 |
|
|
1554 |
|
protected void |
1555 |
|
onDestroy() { |
1556 |
|
SamplerModel sm = CC.getSamplerModel(); |
1557 |
|
|
1558 |
|
sm.removeMidiDeviceListListener(getHandler()); |
1559 |
|
sm.removeAudioDeviceListListener(getHandler()); |
1560 |
|
sm.removeMidiInstrumentMapListListener(mapListListener); |
1561 |
|
sm.removeSamplerListener(samplerListener); |
1562 |
|
|
1563 |
|
if(midiDevice != null) { |
1564 |
|
midiDevice.removeMidiDeviceListener(getHandler()); |
1565 |
|
} |
1566 |
|
} |
1567 |
|
|
1568 |
private final Handler handler = new Handler(); |
private final Handler handler = new Handler(); |
1569 |
|
|
1570 |
private Handler |
private Handler |
1571 |
getHandler() { return handler; } |
getHandler() { return handler; } |
1572 |
|
|
1573 |
private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel> { |
private class Handler implements MidiDeviceListListener, ListListener<AudioDeviceModel>, |
1574 |
|
MidiDeviceListener { |
1575 |
/** |
/** |
1576 |
* Invoked when a new MIDI device is created. |
* Invoked when a new MIDI device is created. |
1577 |
* @param e A <code>MidiDeviceListEvent</code> |
* @param e A <code>MidiDeviceListEvent</code> |
1611 |
entryRemoved(ListEvent<AudioDeviceModel> e) { |
entryRemoved(ListEvent<AudioDeviceModel> e) { |
1612 |
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo()); |
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo()); |
1613 |
} |
} |
1614 |
|
|
1615 |
|
public void |
1616 |
|
settingsChanged(MidiDeviceEvent e) { |
1617 |
|
if(isUpdate()) { |
1618 |
|
CC.getLogger().warning("Invalid update state"); |
1619 |
|
return; |
1620 |
|
} |
1621 |
|
|
1622 |
|
setUpdate(true); |
1623 |
|
int idx = cbMidiPort.getSelectedIndex(); |
1624 |
|
MidiInputDevice d = e.getMidiDeviceModel().getDeviceInfo(); |
1625 |
|
|
1626 |
|
cbMidiPort.removeAllItems(); |
1627 |
|
for(MidiPort port : d.getMidiPorts()) cbMidiPort.addItem(port); |
1628 |
|
|
1629 |
|
if(idx >= cbMidiPort.getModel().getSize()) idx = 0; |
1630 |
|
|
1631 |
|
setUpdate(false); |
1632 |
|
|
1633 |
|
if(cbMidiPort.getModel().getSize() > 0) cbMidiPort.setSelectedIndex(idx); |
1634 |
|
} |
1635 |
|
} |
1636 |
|
|
1637 |
|
private class MapListListener implements ListListener<MidiInstrumentMap> { |
1638 |
|
/** Invoked when a new MIDI instrument map is added to a list. */ |
1639 |
|
public void |
1640 |
|
entryAdded(ListEvent<MidiInstrumentMap> e) { |
1641 |
|
cbInstrumentMap.insertItemAt(e.getEntry(), cbInstrumentMap.getItemCount()); |
1642 |
|
boolean b = channel.getModel().getChannelInfo().getEngine() != null; |
1643 |
|
if(b && !cbInstrumentMap.isEnabled()) cbInstrumentMap.setEnabled(true); |
1644 |
|
} |
1645 |
|
|
1646 |
|
/** Invoked when a new MIDI instrument map is removed from a list. */ |
1647 |
|
public void |
1648 |
|
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
1649 |
|
cbInstrumentMap.removeItem(e.getEntry()); |
1650 |
|
if(cbInstrumentMap.getItemCount() == 0) { // TODO: ? |
1651 |
|
cbInstrumentMap.setSelectedItem(noMap); |
1652 |
|
cbInstrumentMap.setEnabled(false); |
1653 |
|
} |
1654 |
|
} |
1655 |
} |
} |
1656 |
} |
} |