1 |
iliev |
1730 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
2288 |
* Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
1730 |
* |
6 |
|
|
* This file is part of JSampler. |
7 |
|
|
* |
8 |
|
|
* JSampler is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License version 2 |
10 |
|
|
* as published by the Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* JSampler is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with JSampler; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
|
* MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
package org.jsampler.view.fantasia; |
24 |
|
|
|
25 |
iliev |
1818 |
import java.awt.Color; |
26 |
iliev |
1730 |
import java.awt.Dimension; |
27 |
iliev |
1818 |
import java.awt.Graphics; |
28 |
|
|
import java.awt.Graphics2D; |
29 |
iliev |
1730 |
import java.awt.Insets; |
30 |
|
|
|
31 |
|
|
import java.awt.event.ActionEvent; |
32 |
|
|
import java.awt.event.ActionListener; |
33 |
|
|
import java.awt.event.HierarchyEvent; |
34 |
|
|
import java.awt.event.HierarchyListener; |
35 |
|
|
import java.awt.event.MouseAdapter; |
36 |
|
|
import java.awt.event.MouseEvent; |
37 |
iliev |
1734 |
import java.awt.event.MouseListener; |
38 |
iliev |
1730 |
|
39 |
|
|
import java.beans.PropertyChangeEvent; |
40 |
|
|
import java.beans.PropertyChangeListener; |
41 |
|
|
|
42 |
iliev |
1734 |
import java.util.Vector; |
43 |
|
|
|
44 |
iliev |
1730 |
import javax.swing.BorderFactory; |
45 |
|
|
import javax.swing.Box; |
46 |
|
|
import javax.swing.BoxLayout; |
47 |
|
|
import javax.swing.JButton; |
48 |
|
|
import javax.swing.JComponent; |
49 |
|
|
import javax.swing.JLabel; |
50 |
|
|
import javax.swing.JMenuItem; |
51 |
|
|
import javax.swing.JPanel; |
52 |
|
|
import javax.swing.JPopupMenu; |
53 |
|
|
|
54 |
|
|
import javax.swing.event.ChangeEvent; |
55 |
|
|
import javax.swing.event.ChangeListener; |
56 |
|
|
|
57 |
iliev |
2288 |
import net.sf.juife.swing.Dial; |
58 |
iliev |
1730 |
|
59 |
|
|
import org.jsampler.CC; |
60 |
iliev |
1818 |
import org.jsampler.view.fantasia.basic.*; |
61 |
iliev |
2288 |
import org.jsampler.view.swing.SHF; |
62 |
iliev |
1730 |
|
63 |
iliev |
2146 |
import org.pushingpixels.substance.internal.utils.SubstanceImageCreator; |
64 |
iliev |
1730 |
|
65 |
|
|
import org.linuxsampler.lscp.SamplerChannel; |
66 |
|
|
import org.linuxsampler.lscp.SamplerEngine; |
67 |
|
|
|
68 |
|
|
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
69 |
|
|
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
70 |
|
|
import static org.jsampler.view.fantasia.FantasiaUtils.*; |
71 |
|
|
|
72 |
|
|
/** |
73 |
|
|
* |
74 |
|
|
* @author Grigor Iliev |
75 |
|
|
*/ |
76 |
iliev |
1818 |
public class NormalChannelView extends JPanel implements ChannelView { |
77 |
iliev |
1730 |
private final Channel channel; |
78 |
iliev |
1737 |
private ChannelOptionsView channelOptionsView = null; |
79 |
iliev |
1730 |
|
80 |
|
|
private final EnhancedDial dialVolume = new EnhancedDial(); |
81 |
|
|
private final ChannelScreen screen; |
82 |
|
|
|
83 |
iliev |
1732 |
private final Channel.PowerButton btnPower; |
84 |
iliev |
1730 |
private final MuteButton btnMute = new MuteButton(); |
85 |
|
|
private final SoloButton btnSolo = new SoloButton(); |
86 |
iliev |
1732 |
private final Channel.OptionsButton btnOptions; |
87 |
iliev |
1730 |
|
88 |
iliev |
1734 |
private final Vector<JComponent> components = new Vector<JComponent>(); |
89 |
iliev |
1730 |
|
90 |
iliev |
1734 |
|
91 |
iliev |
1730 |
/** Creates a new instance of <code>NormalChannelView</code> */ |
92 |
|
|
public |
93 |
|
|
NormalChannelView(Channel channel) { |
94 |
iliev |
1734 |
components.add(this); |
95 |
|
|
|
96 |
iliev |
1730 |
this.channel = channel; |
97 |
|
|
|
98 |
iliev |
1732 |
btnPower = new Channel.PowerButton(channel); |
99 |
iliev |
1734 |
components.add(btnPower); |
100 |
iliev |
1732 |
btnOptions = new Channel.OptionsButton(channel); |
101 |
iliev |
1734 |
components.add(btnOptions); |
102 |
iliev |
1732 |
|
103 |
iliev |
1730 |
screen = new ChannelScreen(channel); |
104 |
iliev |
1734 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
105 |
iliev |
1730 |
|
106 |
|
|
btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT); |
107 |
|
|
|
108 |
|
|
JPanel tb = new JPanel(); |
109 |
iliev |
1734 |
components.add(tb); |
110 |
iliev |
1730 |
tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4)); |
111 |
|
|
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
112 |
|
|
tb.setOpaque(false); |
113 |
|
|
tb.setAlignmentY(JPanel.TOP_ALIGNMENT); |
114 |
|
|
tb.add(btnPower); |
115 |
|
|
tb.setPreferredSize(new Dimension(tb.getPreferredSize().width, 58)); |
116 |
|
|
tb.setMinimumSize(tb.getPreferredSize()); |
117 |
|
|
tb.setMaximumSize(tb.getPreferredSize()); |
118 |
iliev |
1734 |
add(tb); |
119 |
iliev |
1730 |
|
120 |
|
|
//p.add(Box.createRigidArea(new Dimension(4, 0))); |
121 |
|
|
|
122 |
iliev |
1734 |
add(createVSeparator()); |
123 |
iliev |
1730 |
|
124 |
|
|
//p.add(Box.createRigidArea(new Dimension(3, 0))); |
125 |
|
|
|
126 |
|
|
JPanel p2 = new JPanel(); |
127 |
iliev |
1734 |
components.add(p2); |
128 |
iliev |
1730 |
p2.setOpaque(false); |
129 |
|
|
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
130 |
|
|
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
131 |
|
|
p2.setBorder(BorderFactory.createEmptyBorder(5, 3, 0, 2)); |
132 |
|
|
p2.add(screen); |
133 |
iliev |
1734 |
add(p2); |
134 |
iliev |
1730 |
|
135 |
iliev |
1734 |
add(createVSeparator()); |
136 |
iliev |
1730 |
|
137 |
|
|
p2 = new JPanel(); |
138 |
iliev |
1734 |
components.add(p2); |
139 |
iliev |
1730 |
p2.setOpaque(false); |
140 |
|
|
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
141 |
|
|
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
142 |
|
|
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
143 |
iliev |
1734 |
|
144 |
|
|
JLabel l = new JLabel(Res.gfxMuteTitle); |
145 |
|
|
components.add(l); |
146 |
|
|
p2.add(l); |
147 |
|
|
components.add(btnMute); |
148 |
iliev |
1730 |
p2.add(btnMute); |
149 |
iliev |
1734 |
|
150 |
|
|
l = new JLabel(Res.gfxSoloTitle); |
151 |
|
|
components.add(l); |
152 |
|
|
p2.add(l); |
153 |
|
|
|
154 |
|
|
components.add(btnSolo); |
155 |
iliev |
1730 |
p2.add(btnSolo); |
156 |
|
|
|
157 |
iliev |
1734 |
add(p2); |
158 |
iliev |
1730 |
|
159 |
iliev |
1734 |
add(createVSeparator()); |
160 |
iliev |
1730 |
|
161 |
|
|
p2 = new JPanel(); |
162 |
iliev |
1734 |
components.add(p2); |
163 |
iliev |
1730 |
p2.setOpaque(false); |
164 |
|
|
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
165 |
|
|
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
166 |
|
|
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
167 |
iliev |
1734 |
l = new JLabel(Res.gfxVolumeTitle); |
168 |
|
|
components.add(l); |
169 |
iliev |
1730 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
170 |
|
|
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
171 |
|
|
p2.add(l); |
172 |
iliev |
1734 |
|
173 |
|
|
components.add(dialVolume); |
174 |
iliev |
1730 |
dialVolume.setDialPixmap(Res.gfxVolumeDial, 30, 330); |
175 |
|
|
dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
176 |
|
|
p2.add(dialVolume); |
177 |
iliev |
1734 |
add(p2); |
178 |
iliev |
1730 |
|
179 |
iliev |
1734 |
add(createVSeparator()); |
180 |
iliev |
1730 |
|
181 |
|
|
p2 = new JPanel(); |
182 |
iliev |
1734 |
components.add(p2); |
183 |
iliev |
1730 |
p2.setOpaque(false); |
184 |
|
|
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
185 |
|
|
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
186 |
|
|
p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0)); |
187 |
|
|
l = new JLabel(Res.gfxOptionsTitle); |
188 |
iliev |
1734 |
components.add(l); |
189 |
iliev |
1730 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
190 |
|
|
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
191 |
|
|
p2.add(l); |
192 |
|
|
|
193 |
|
|
p2.add(Box.createRigidArea(new Dimension(0, 3))); |
194 |
|
|
|
195 |
|
|
btnOptions.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
196 |
|
|
p2.add(btnOptions); |
197 |
iliev |
1734 |
add(p2); |
198 |
iliev |
1730 |
|
199 |
|
|
|
200 |
iliev |
1734 |
setPreferredSize(new Dimension(420, 60)); |
201 |
|
|
setMinimumSize(getPreferredSize()); |
202 |
|
|
setMaximumSize(getPreferredSize()); |
203 |
iliev |
1730 |
//p.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); |
204 |
|
|
|
205 |
iliev |
1734 |
setAlignmentX(JPanel.CENTER_ALIGNMENT); |
206 |
iliev |
1730 |
|
207 |
|
|
installView(); |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
////////////////////////////////////////////// |
211 |
|
|
// Implementation of the ChannelView interface |
212 |
|
|
////////////////////////////////////////////// |
213 |
|
|
|
214 |
iliev |
1785 |
@Override |
215 |
iliev |
1734 |
public Type |
216 |
|
|
getType() { return Type.NORMAL; } |
217 |
|
|
|
218 |
iliev |
1785 |
@Override |
219 |
iliev |
1730 |
public JComponent |
220 |
|
|
getComponent() { return this; } |
221 |
|
|
|
222 |
iliev |
1785 |
@Override |
223 |
iliev |
1730 |
public void |
224 |
|
|
installView() { |
225 |
|
|
String vmud = VOL_MEASUREMENT_UNIT_DECIBEL; |
226 |
|
|
preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() { |
227 |
|
|
public void |
228 |
|
|
propertyChange(PropertyChangeEvent e) { |
229 |
|
|
boolean b; |
230 |
|
|
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
231 |
|
|
screen.updateVolumeInfo(dialVolume.getValue()); |
232 |
|
|
} |
233 |
|
|
}); |
234 |
iliev |
1734 |
|
235 |
|
|
screen.installListeners(); |
236 |
iliev |
1735 |
|
237 |
|
|
addEnhancedMouseListener(channel.getContextMenu()); |
238 |
iliev |
1776 |
addEnhancedMouseListener(getHandler()); |
239 |
iliev |
1730 |
} |
240 |
|
|
|
241 |
iliev |
1785 |
@Override |
242 |
iliev |
1730 |
public void |
243 |
|
|
uninstallView() { |
244 |
|
|
screen.onDestroy(); |
245 |
iliev |
1737 |
btnOptions.onDestroy(); |
246 |
|
|
uninstallChannelOptionsView(); |
247 |
iliev |
1735 |
//removeEnhancedMouseListener(channel.getContextMenu()); |
248 |
iliev |
1776 |
removeEnhancedMouseListener(getHandler()); |
249 |
iliev |
1730 |
} |
250 |
|
|
|
251 |
iliev |
1785 |
@Override |
252 |
iliev |
1737 |
public void |
253 |
|
|
installChannelOptionsView() { |
254 |
|
|
if(channelOptionsView != null) return; |
255 |
|
|
|
256 |
|
|
channelOptionsView = new NormalChannelOptionsView(channel); |
257 |
|
|
channelOptionsView.installView(); |
258 |
|
|
|
259 |
|
|
} |
260 |
|
|
|
261 |
iliev |
1785 |
@Override |
262 |
iliev |
1737 |
public void |
263 |
|
|
uninstallChannelOptionsView() { |
264 |
|
|
if(channelOptionsView == null) return; |
265 |
|
|
channelOptionsView.uninstallView(); |
266 |
|
|
channelOptionsView = null; |
267 |
|
|
} |
268 |
|
|
|
269 |
iliev |
1785 |
@Override |
270 |
iliev |
1730 |
public ChannelOptionsView |
271 |
|
|
getChannelOptionsView() { return channelOptionsView; } |
272 |
|
|
|
273 |
iliev |
1785 |
@Override |
274 |
iliev |
1730 |
public void |
275 |
|
|
updateChannelInfo() { |
276 |
|
|
SamplerChannel sc = channel.getChannelInfo(); |
277 |
|
|
|
278 |
|
|
screen.updateScreenInfo(sc); |
279 |
iliev |
1732 |
float f = sc.getVolume() * 100.0f; |
280 |
|
|
screen.updateVolumeInfo((int)f); |
281 |
iliev |
1730 |
updateMuteIcon(sc); |
282 |
|
|
|
283 |
|
|
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn); |
284 |
|
|
else btnSolo.setIcon(Res.gfxSoloOff); |
285 |
|
|
dialVolume.setValue((int)(sc.getVolume() * 100)); |
286 |
|
|
|
287 |
|
|
boolean b = sc.getEngine() != null; |
288 |
|
|
dialVolume.setEnabled(b); |
289 |
|
|
btnSolo.setEnabled(b); |
290 |
|
|
btnMute.setEnabled(b); |
291 |
iliev |
1737 |
|
292 |
|
|
if(getChannelOptionsView() != null) getChannelOptionsView().updateChannelInfo(); |
293 |
iliev |
1730 |
} |
294 |
|
|
|
295 |
iliev |
1785 |
@Override |
296 |
iliev |
1730 |
public void |
297 |
|
|
updateStreamCount(int count) { screen.updateStreamCount(count); } |
298 |
|
|
|
299 |
iliev |
1785 |
@Override |
300 |
iliev |
1730 |
public void |
301 |
|
|
updateVoiceCount(int count) { screen.updateVoiceCount(count); } |
302 |
|
|
|
303 |
iliev |
1785 |
@Override |
304 |
iliev |
1730 |
public void |
305 |
|
|
expandChannel() { |
306 |
|
|
if(btnOptions.isSelected()) return; |
307 |
|
|
btnOptions.doClick(); |
308 |
|
|
} |
309 |
|
|
|
310 |
iliev |
1785 |
@Override |
311 |
iliev |
1734 |
public boolean |
312 |
|
|
isOptionsButtonSelected() { return btnOptions.isSelected(); } |
313 |
|
|
|
314 |
iliev |
1785 |
@Override |
315 |
iliev |
1734 |
public void |
316 |
|
|
setOptionsButtonSelected(boolean b) { |
317 |
|
|
btnOptions.setSelected(b); |
318 |
|
|
} |
319 |
|
|
|
320 |
iliev |
1785 |
@Override |
321 |
iliev |
1734 |
public void |
322 |
|
|
addEnhancedMouseListener(MouseListener l) { |
323 |
|
|
removeEnhancedMouseListener(l); |
324 |
|
|
|
325 |
|
|
for(JComponent c : components) c.addMouseListener(l); |
326 |
|
|
screen.addEnhancedMouseListener(l); |
327 |
|
|
} |
328 |
|
|
|
329 |
iliev |
1785 |
@Override |
330 |
iliev |
1734 |
public void |
331 |
|
|
removeEnhancedMouseListener(MouseListener l) { |
332 |
|
|
for(JComponent c : components) c.removeMouseListener(l); |
333 |
|
|
screen.removeEnhancedMouseListener(l); |
334 |
|
|
} |
335 |
|
|
|
336 |
iliev |
1730 |
////////////////////////////////////////////// |
337 |
|
|
|
338 |
iliev |
1818 |
@Override |
339 |
|
|
protected void |
340 |
|
|
paintComponent(Graphics g) { |
341 |
|
|
if(isOpaque()) super.paintComponent(g); |
342 |
|
|
|
343 |
|
|
double h = getSize().getHeight(); |
344 |
|
|
double w = getSize().getWidth(); |
345 |
|
|
|
346 |
|
|
Color c1 = channel.isSelected() ? new Color(0x555555) : FantasiaPainter.color6; |
347 |
|
|
Color c2 = channel.isSelected() ? new Color(0x606060) : FantasiaPainter.color4; |
348 |
|
|
|
349 |
|
|
Graphics2D g2 = (Graphics2D)g; |
350 |
|
|
FantasiaPainter.paintGradient(g2, 0, 0, w - 1, h - 1, c1, c2); |
351 |
|
|
FantasiaPainter.paintOuterBorder(g2, 0, 0, w - 1, h - 1, false, 0.27f, 0.11f, 0.64f, 0.20f); |
352 |
|
|
} |
353 |
iliev |
1730 |
|
354 |
iliev |
1818 |
|
355 |
iliev |
1730 |
/** |
356 |
|
|
* Updates the mute button with the proper icon regarding to information obtained |
357 |
|
|
* from <code>channel</code>. |
358 |
|
|
* @param channel A <code>SamplerChannel</code> instance containing the new settings |
359 |
|
|
* for this channel. |
360 |
|
|
*/ |
361 |
|
|
private void |
362 |
|
|
updateMuteIcon(SamplerChannel channel) { |
363 |
|
|
if(channel.isMutedBySolo()) btnMute.setIcon(Res.gfxMutedBySolo); |
364 |
|
|
else if(channel.isMuted()) btnMute.setIcon(Res.gfxMuteOn); |
365 |
|
|
else btnMute.setIcon(Res.gfxMuteOff); |
366 |
|
|
} |
367 |
|
|
|
368 |
|
|
/** Invoked when the user changes the volume */ |
369 |
|
|
private void |
370 |
|
|
setVolume() { |
371 |
|
|
screen.updateVolumeInfo(dialVolume.getValue()); |
372 |
|
|
|
373 |
|
|
if(dialVolume.getValueIsAdjusting()) return; |
374 |
|
|
|
375 |
|
|
int vol = (int)(channel.getChannelInfo().getVolume() * 100); |
376 |
|
|
|
377 |
|
|
if(vol == dialVolume.getValue()) return; |
378 |
|
|
|
379 |
|
|
/* |
380 |
|
|
* If the model's volume is not equal to the dial knob |
381 |
|
|
* value we assume that the change is due to user input. |
382 |
|
|
* So we must update the volume at the backend too. |
383 |
|
|
*/ |
384 |
|
|
float volume = dialVolume.getValue(); |
385 |
|
|
volume /= 100; |
386 |
|
|
channel.getModel().setBackendVolume(volume); |
387 |
|
|
} |
388 |
|
|
|
389 |
|
|
private JPanel |
390 |
|
|
createVSeparator() { |
391 |
|
|
PixmapPane p = new PixmapPane(Res.gfxVLine); |
392 |
|
|
p.setAlignmentY(JPanel.TOP_ALIGNMENT); |
393 |
|
|
p.setPreferredSize(new Dimension(2, 60)); |
394 |
|
|
p.setMinimumSize(p.getPreferredSize()); |
395 |
|
|
p.setMaximumSize(p.getPreferredSize()); |
396 |
|
|
return p; |
397 |
|
|
} |
398 |
|
|
|
399 |
|
|
private class EnhancedDial extends Dial { |
400 |
|
|
EnhancedDial() { |
401 |
|
|
super(0, 100, 0); |
402 |
|
|
|
403 |
|
|
setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP); |
404 |
|
|
|
405 |
|
|
int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
406 |
|
|
setMaximum(i); |
407 |
|
|
String mcv = MAXIMUM_CHANNEL_VOLUME; |
408 |
|
|
preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() { |
409 |
|
|
public void |
410 |
|
|
propertyChange(PropertyChangeEvent e) { |
411 |
|
|
int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
412 |
|
|
setMaximum(j); |
413 |
|
|
} |
414 |
|
|
}); |
415 |
|
|
|
416 |
|
|
addMouseListener(new MouseAdapter() { |
417 |
|
|
public void |
418 |
|
|
mouseClicked(MouseEvent e) { |
419 |
|
|
if(e.getButton() == e.BUTTON3) { |
420 |
|
|
setValue(getMaximum() / 2); |
421 |
|
|
return; |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
if(e.getButton() != e.BUTTON1) return; |
425 |
|
|
|
426 |
|
|
if(e.getClickCount() < 2) return; |
427 |
|
|
setValue(getValueByPoint(e.getPoint())); |
428 |
|
|
} |
429 |
|
|
}); |
430 |
|
|
|
431 |
|
|
addChangeListener(new ChangeListener() { |
432 |
|
|
public void |
433 |
|
|
stateChanged(ChangeEvent e) { setVolume(); } |
434 |
|
|
}); |
435 |
|
|
} |
436 |
|
|
} |
437 |
|
|
|
438 |
|
|
|
439 |
|
|
private class MuteButton extends PixmapButton implements ActionListener { |
440 |
|
|
MuteButton() { |
441 |
|
|
super(Res.gfxMuteOff); |
442 |
|
|
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
443 |
|
|
setDisabledIcon ( |
444 |
|
|
SubstanceImageCreator.makeTransparent(this, Res.gfxMuteOff, 0.4) |
445 |
|
|
); |
446 |
|
|
addActionListener(this); |
447 |
|
|
} |
448 |
|
|
|
449 |
iliev |
1785 |
@Override |
450 |
iliev |
1730 |
public void |
451 |
|
|
actionPerformed(ActionEvent e) { |
452 |
|
|
SamplerChannel sc = channel.getChannelInfo(); |
453 |
|
|
boolean b = true; |
454 |
|
|
|
455 |
|
|
/* |
456 |
|
|
* Changing the mute button icon now instead of |
457 |
|
|
* leaving the work to the notification mechanism of the LinuxSampler. |
458 |
|
|
*/ |
459 |
|
|
if(sc.isMuted() && !sc.isMutedBySolo()) { |
460 |
|
|
b = false; |
461 |
|
|
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
462 |
|
|
|
463 |
|
|
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.gfxMuteOff); |
464 |
|
|
else setIcon(Res.gfxMutedBySolo); |
465 |
|
|
} else setIcon(Res.gfxMuteOn); |
466 |
|
|
|
467 |
|
|
channel.getModel().setBackendMute(b); |
468 |
|
|
} |
469 |
|
|
|
470 |
iliev |
1785 |
@Override |
471 |
iliev |
1730 |
public boolean |
472 |
|
|
contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
473 |
|
|
} |
474 |
|
|
|
475 |
|
|
private class SoloButton extends PixmapButton implements ActionListener { |
476 |
|
|
SoloButton() { |
477 |
|
|
super(Res.gfxSoloOff); |
478 |
|
|
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
479 |
|
|
setDisabledIcon ( |
480 |
|
|
SubstanceImageCreator.makeTransparent(this, Res.gfxSoloOff, 0.4) |
481 |
|
|
); |
482 |
|
|
addActionListener(this); |
483 |
|
|
} |
484 |
|
|
|
485 |
iliev |
1785 |
@Override |
486 |
iliev |
1730 |
public void |
487 |
|
|
actionPerformed(ActionEvent e) { |
488 |
|
|
SamplerChannel sc = channel.getChannelInfo(); |
489 |
|
|
boolean b = !sc.isSoloChannel(); |
490 |
|
|
|
491 |
|
|
/* |
492 |
|
|
* Changing the solo button icon (and related) now instead of |
493 |
|
|
* leaving the work to the notification mechanism of the LinuxSampler. |
494 |
|
|
*/ |
495 |
|
|
if(b) { |
496 |
|
|
setIcon(Res.gfxSoloOn); |
497 |
|
|
if(sc.isMutedBySolo()) btnMute.setIcon(Res.gfxMuteOff); |
498 |
|
|
} else { |
499 |
|
|
setIcon(Res.gfxSoloOff); |
500 |
|
|
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
501 |
|
|
btnMute.setIcon(Res.gfxMutedBySolo); |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
channel.getModel().setBackendSolo(b); |
505 |
|
|
} |
506 |
|
|
|
507 |
iliev |
1785 |
@Override |
508 |
iliev |
1730 |
public boolean |
509 |
|
|
contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
510 |
|
|
} |
511 |
iliev |
1776 |
|
512 |
|
|
private final EventHandler eventHandler = new EventHandler(); |
513 |
|
|
|
514 |
|
|
private EventHandler |
515 |
|
|
getHandler() { return eventHandler; } |
516 |
|
|
|
517 |
|
|
private class EventHandler extends MouseAdapter { |
518 |
iliev |
1785 |
@Override |
519 |
iliev |
1776 |
public void |
520 |
iliev |
1818 |
mousePressed(MouseEvent e) { |
521 |
iliev |
1776 |
// TAG: channel selection system |
522 |
iliev |
1818 |
if(e.getButton() == MouseEvent.BUTTON3 && channel.isSelected()) return; |
523 |
|
|
|
524 |
|
|
CC.getMainFrame().getSelectedChannelsPane().processChannelSelection ( |
525 |
|
|
channel, e.isControlDown(), e.isShiftDown() |
526 |
|
|
); |
527 |
iliev |
1776 |
/////// |
528 |
|
|
} |
529 |
|
|
} |
530 |
iliev |
1730 |
} |
531 |
|
|
|
532 |
|
|
|
533 |
|
|
class ChannelScreen extends PixmapPane { |
534 |
|
|
private final Channel channel; |
535 |
|
|
|
536 |
|
|
private final InstrumentPane instrumentPane; |
537 |
|
|
|
538 |
iliev |
1732 |
private final Channel.StreamVoiceCountPane streamVoiceCountPane; |
539 |
|
|
|
540 |
|
|
private final Channel.VolumePane volumePane; |
541 |
|
|
|
542 |
iliev |
1730 |
private JButton btnInstr = |
543 |
|
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
544 |
|
|
|
545 |
|
|
private final JButton btnEditInstr = |
546 |
|
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
547 |
|
|
private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr); |
548 |
|
|
|
549 |
|
|
private final JButton btnFxSends = |
550 |
|
|
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends")); |
551 |
|
|
|
552 |
|
|
private final JButton btnEngine |
553 |
|
|
= createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine")); |
554 |
|
|
|
555 |
|
|
private final JPopupMenu menuEngines = new JPopupMenu(); |
556 |
|
|
|
557 |
iliev |
1734 |
private final ActionListener guiListener; |
558 |
iliev |
1730 |
|
559 |
iliev |
1734 |
private final Vector<JComponent> components = new Vector<JComponent>(); |
560 |
|
|
|
561 |
iliev |
1730 |
ChannelScreen(final Channel channel) { |
562 |
|
|
super(Res.gfxChannelScreen); |
563 |
|
|
setPixmapInsets(new Insets(6, 6, 6, 6)); |
564 |
|
|
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
565 |
|
|
|
566 |
iliev |
1734 |
components.add(this); |
567 |
|
|
|
568 |
iliev |
1730 |
this.channel = channel; |
569 |
iliev |
1734 |
|
570 |
iliev |
1732 |
streamVoiceCountPane = new Channel.StreamVoiceCountPane(channel); |
571 |
iliev |
1734 |
components.add(streamVoiceCountPane); |
572 |
|
|
|
573 |
iliev |
1732 |
volumePane = new Channel.VolumePane(channel); |
574 |
iliev |
1734 |
components.add(volumePane); |
575 |
iliev |
1730 |
|
576 |
|
|
setOpaque(false); |
577 |
|
|
|
578 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
579 |
|
|
|
580 |
|
|
btnInstr.setAlignmentX(CENTER_ALIGNMENT); |
581 |
|
|
btnInstr.setRolloverEnabled(false); |
582 |
|
|
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
583 |
iliev |
1734 |
components.add(btnInstr); |
584 |
iliev |
1730 |
|
585 |
|
|
instrumentPane = new InstrumentPane(); |
586 |
iliev |
1734 |
components.add(instrumentPane); |
587 |
iliev |
1730 |
add(instrumentPane); |
588 |
|
|
|
589 |
iliev |
1743 |
add(Box.createRigidArea(new Dimension(0, 3))); |
590 |
|
|
|
591 |
iliev |
1730 |
JPanel p = new JPanel(); |
592 |
iliev |
1734 |
components.add(p); |
593 |
iliev |
1730 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
594 |
|
|
p.setAlignmentX(CENTER_ALIGNMENT); |
595 |
|
|
p.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 0)); |
596 |
|
|
|
597 |
iliev |
1734 |
components.add(btnFxSends); |
598 |
iliev |
1730 |
btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt")); |
599 |
|
|
btnFxSends.addActionListener(new ActionListener() { |
600 |
|
|
public void |
601 |
|
|
actionPerformed(ActionEvent e) { |
602 |
iliev |
1732 |
channel.showFxSendsDialog(); |
603 |
iliev |
1730 |
} |
604 |
|
|
}); |
605 |
|
|
|
606 |
|
|
p.add(btnFxSends); |
607 |
|
|
|
608 |
|
|
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
609 |
|
|
p.add(Box.createGlue()); |
610 |
|
|
|
611 |
iliev |
1734 |
components.add(btnEngine); |
612 |
iliev |
1730 |
btnEngine.setIcon(Res.iconEngine12); |
613 |
|
|
btnEngine.setIconTextGap(1); |
614 |
|
|
p.add(btnEngine); |
615 |
|
|
//p.add(new Label("|")); |
616 |
|
|
|
617 |
|
|
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
618 |
|
|
|
619 |
|
|
//p.add(btnReset); |
620 |
|
|
|
621 |
|
|
p.add(Box.createGlue()); |
622 |
|
|
|
623 |
iliev |
1732 |
p.add(streamVoiceCountPane); |
624 |
|
|
p.add(volumePane); |
625 |
iliev |
1730 |
|
626 |
|
|
p.setPreferredSize(new Dimension(260, p.getPreferredSize().height)); |
627 |
|
|
p.setMinimumSize(p.getPreferredSize()); |
628 |
|
|
p.setMaximumSize(p.getPreferredSize()); |
629 |
|
|
|
630 |
|
|
//btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
631 |
|
|
p.setOpaque(false); |
632 |
|
|
add(p); |
633 |
|
|
|
634 |
|
|
|
635 |
|
|
setPreferredSize(new Dimension(270, 48)); |
636 |
|
|
setMinimumSize(getPreferredSize()); |
637 |
|
|
setMaximumSize(getPreferredSize()); |
638 |
|
|
|
639 |
|
|
createEngineMenu(); |
640 |
iliev |
1734 |
|
641 |
|
|
guiListener = new ActionListener() { |
642 |
|
|
public void |
643 |
|
|
actionPerformed(ActionEvent e) { |
644 |
|
|
if(getMousePosition(true) != null) { |
645 |
|
|
getHandler().mouseEntered(null); |
646 |
|
|
} else { |
647 |
|
|
getHandler().mouseExited(null); |
648 |
|
|
} |
649 |
|
|
} |
650 |
|
|
}; |
651 |
iliev |
1730 |
} |
652 |
|
|
|
653 |
iliev |
1734 |
public void |
654 |
|
|
addEnhancedMouseListener(MouseListener l) { |
655 |
|
|
removeEnhancedMouseListener(l); |
656 |
|
|
for(JComponent c : components) c.addMouseListener(l); |
657 |
|
|
} |
658 |
|
|
|
659 |
|
|
public void |
660 |
|
|
removeEnhancedMouseListener(MouseListener l) { |
661 |
|
|
for(JComponent c : components) c.removeMouseListener(l); |
662 |
|
|
} |
663 |
|
|
|
664 |
iliev |
1730 |
protected void |
665 |
iliev |
1734 |
onDestroy() { uninstallListeners(); } |
666 |
iliev |
1730 |
|
667 |
|
|
private void |
668 |
|
|
createEngineMenu() { |
669 |
|
|
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) { |
670 |
|
|
JMenuItem mi = new JMenuItem(engine.getName() + " engine"); |
671 |
|
|
mi.setToolTipText(engine.getDescription()); |
672 |
|
|
|
673 |
|
|
mi.addActionListener(new ActionListener() { |
674 |
|
|
public void |
675 |
|
|
actionPerformed(ActionEvent e) { |
676 |
|
|
channel.getModel().setBackendEngineType(engine.getName()); |
677 |
|
|
} |
678 |
|
|
}); |
679 |
|
|
|
680 |
|
|
menuEngines.add(mi); |
681 |
|
|
} |
682 |
|
|
} |
683 |
|
|
|
684 |
iliev |
1734 |
protected void |
685 |
iliev |
1730 |
installListeners() { |
686 |
|
|
btnInstr.addActionListener(new ActionListener() { |
687 |
|
|
public void |
688 |
iliev |
1732 |
actionPerformed(ActionEvent e) { channel.loadInstrument(); } |
689 |
iliev |
1730 |
}); |
690 |
|
|
|
691 |
|
|
btnEditInstr.addActionListener(new ActionListener() { |
692 |
|
|
public void |
693 |
|
|
actionPerformed(ActionEvent e) { |
694 |
|
|
CC.getSamplerModel().editBackendInstrument(channel.getChannelId()); |
695 |
|
|
} |
696 |
|
|
}); |
697 |
|
|
|
698 |
|
|
btnEngine.addActionListener(new ActionListener() { |
699 |
|
|
public void |
700 |
|
|
actionPerformed(ActionEvent e) { |
701 |
|
|
int y = btnEngine.getHeight() + 1; |
702 |
|
|
menuEngines.show(btnEngine, 0, y); |
703 |
|
|
} |
704 |
|
|
}); |
705 |
|
|
|
706 |
|
|
addMouseListener(getHandler()); |
707 |
|
|
addHierarchyListener(getHandler()); |
708 |
|
|
|
709 |
iliev |
2288 |
((MainFrame)SHF.getMainFrame()).getGuiTimer().addActionListener(guiListener); |
710 |
iliev |
1730 |
} |
711 |
|
|
|
712 |
iliev |
1734 |
private void |
713 |
|
|
uninstallListeners() { |
714 |
iliev |
2288 |
((MainFrame)SHF.getMainFrame()).getGuiTimer().removeActionListener(guiListener); |
715 |
iliev |
1734 |
} |
716 |
|
|
|
717 |
iliev |
1730 |
protected void |
718 |
|
|
updateScreenInfo(SamplerChannel sc) { |
719 |
iliev |
1743 |
String s = btnInstr.getToolTipText(); |
720 |
|
|
|
721 |
iliev |
1730 |
int status = sc.getInstrumentStatus(); |
722 |
|
|
if(status >= 0 && status < 100) { |
723 |
|
|
btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status)); |
724 |
iliev |
1743 |
if(s != null) btnInstr.setToolTipText(null); |
725 |
iliev |
1730 |
} else if(status == -1) { |
726 |
|
|
btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
727 |
iliev |
1743 |
if(s != null) btnInstr.setToolTipText(null); |
728 |
iliev |
1730 |
} else if(status < -1) { |
729 |
|
|
btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument")); |
730 |
iliev |
1743 |
if(s != null) btnInstr.setToolTipText(null); |
731 |
iliev |
1730 |
} else { |
732 |
|
|
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
733 |
|
|
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
734 |
iliev |
1743 |
|
735 |
|
|
btnInstr.setToolTipText(sc.getInstrumentName()); |
736 |
iliev |
1730 |
} |
737 |
|
|
|
738 |
|
|
instrumentPane.update(); |
739 |
|
|
|
740 |
|
|
if(sc.getEngine() != null) { |
741 |
iliev |
1743 |
s = sc.getEngine().getName(); |
742 |
iliev |
1730 |
s += " engine"; |
743 |
|
|
if(!s.equals(btnEngine.getText())) { |
744 |
|
|
btnEngine.setText(s); |
745 |
|
|
btnEngine.setToolTipText(sc.getEngine().getDescription()); |
746 |
|
|
} |
747 |
|
|
} |
748 |
|
|
|
749 |
|
|
} |
750 |
|
|
|
751 |
|
|
protected void |
752 |
|
|
updateVolumeInfo(int volume) { |
753 |
iliev |
1732 |
volumePane.updateVolumeInfo(volume); |
754 |
iliev |
1730 |
} |
755 |
|
|
|
756 |
|
|
/** |
757 |
|
|
* Updates the number of active disk streams. |
758 |
|
|
* @param count The new number of active disk streams. |
759 |
|
|
*/ |
760 |
|
|
protected void |
761 |
|
|
updateStreamCount(int count) { |
762 |
iliev |
1732 |
streamVoiceCountPane.updateStreamCount(count); |
763 |
iliev |
1730 |
} |
764 |
|
|
|
765 |
|
|
/** |
766 |
|
|
* Updates the number of active voices. |
767 |
|
|
* @param count The new number of active voices. |
768 |
|
|
*/ |
769 |
|
|
protected void |
770 |
|
|
updateVoiceCount(int count) { |
771 |
iliev |
1732 |
streamVoiceCountPane.updateVoiceCount(count); |
772 |
iliev |
1730 |
} |
773 |
|
|
|
774 |
|
|
class InstrumentPane extends JPanel { |
775 |
|
|
private final JPanel leftPane = new JPanel(); |
776 |
|
|
private final JPanel rightPane = new JPanel(); |
777 |
|
|
|
778 |
|
|
InstrumentPane() { |
779 |
|
|
setOpaque(false); |
780 |
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
781 |
|
|
add(leftPane); |
782 |
|
|
add(btnInstr); |
783 |
|
|
add(rightPane); |
784 |
|
|
add(sbbEditInstr); |
785 |
|
|
btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt")); |
786 |
|
|
sbbEditInstr.setVisible(false); |
787 |
|
|
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); |
788 |
|
|
|
789 |
|
|
update(); |
790 |
|
|
} |
791 |
|
|
|
792 |
|
|
public void |
793 |
|
|
update() { |
794 |
|
|
int a = btnInstr.getMinimumSize().width; |
795 |
|
|
int b = 0; |
796 |
|
|
if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width; |
797 |
|
|
|
798 |
|
|
int max = 254 - b; |
799 |
|
|
if(a > max) a = max; |
800 |
|
|
|
801 |
|
|
int h = btnInstr.getPreferredSize().height; |
802 |
|
|
btnInstr.setPreferredSize(new Dimension(a, h)); |
803 |
|
|
h = btnInstr.getMaximumSize().height; |
804 |
|
|
btnInstr.setMaximumSize(new Dimension(a, h)); |
805 |
|
|
|
806 |
|
|
|
807 |
|
|
int i = (254 - btnInstr.getPreferredSize().width) / 2; |
808 |
|
|
|
809 |
|
|
int j = i; |
810 |
|
|
if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width; |
811 |
|
|
if(i < 0 || j < 0) i = j = 0; |
812 |
|
|
|
813 |
|
|
Dimension d = new Dimension(i, 1); |
814 |
|
|
leftPane.setMinimumSize(d); |
815 |
|
|
leftPane.setPreferredSize(d); |
816 |
|
|
leftPane.setMaximumSize(d); |
817 |
|
|
|
818 |
|
|
d = new Dimension(j, 1); |
819 |
|
|
rightPane.setMinimumSize(d); |
820 |
|
|
rightPane.setPreferredSize(d); |
821 |
|
|
rightPane.setMaximumSize(d); |
822 |
|
|
|
823 |
|
|
validate(); |
824 |
|
|
} |
825 |
|
|
} |
826 |
|
|
|
827 |
|
|
static class ScreenButtonBg extends PixmapPane { |
828 |
|
|
ScreenButtonBg(JButton btn) { |
829 |
|
|
super(Res.gfxScreenBtnBg); |
830 |
|
|
setPixmapInsets(new Insets(4, 4, 4, 4)); |
831 |
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
832 |
|
|
setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7)); |
833 |
|
|
add(btn); |
834 |
|
|
setPreferredSize(new Dimension(getPreferredSize().width, 13)); |
835 |
|
|
} |
836 |
|
|
|
837 |
iliev |
1785 |
@Override |
838 |
iliev |
1730 |
public Dimension |
839 |
|
|
getPreferredSize() { |
840 |
|
|
return new Dimension(super.getPreferredSize().width, 13); |
841 |
|
|
} |
842 |
|
|
} |
843 |
|
|
|
844 |
|
|
|
845 |
|
|
private final EventHandler eventHandler = new EventHandler(); |
846 |
|
|
|
847 |
|
|
private EventHandler |
848 |
|
|
getHandler() { return eventHandler; } |
849 |
|
|
|
850 |
|
|
private class EventHandler extends MouseAdapter implements HierarchyListener { |
851 |
iliev |
1785 |
@Override |
852 |
iliev |
1730 |
public void |
853 |
|
|
mouseEntered(MouseEvent e) { |
854 |
|
|
if(channel.getChannelInfo().getInstrumentStatus() != 100) return; |
855 |
|
|
|
856 |
|
|
if(!sbbEditInstr.isVisible()) { |
857 |
|
|
sbbEditInstr.setVisible(true); |
858 |
|
|
instrumentPane.update(); |
859 |
|
|
} |
860 |
|
|
} |
861 |
|
|
|
862 |
iliev |
1785 |
@Override |
863 |
iliev |
1730 |
public void |
864 |
|
|
mouseExited(MouseEvent e) { |
865 |
|
|
if(getMousePosition(true) != null) return; |
866 |
|
|
if(sbbEditInstr.isVisible()) { |
867 |
|
|
sbbEditInstr.setVisible(false); |
868 |
|
|
instrumentPane.update(); |
869 |
|
|
} |
870 |
|
|
} |
871 |
|
|
|
872 |
|
|
/** Called when the hierarchy has been changed. */ |
873 |
iliev |
1785 |
@Override |
874 |
iliev |
1730 |
public void |
875 |
|
|
hierarchyChanged(HierarchyEvent e) { |
876 |
|
|
if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) { |
877 |
|
|
if(getMousePosition() == null) mouseExited(null); |
878 |
|
|
else mouseEntered(null); |
879 |
|
|
} |
880 |
|
|
} |
881 |
|
|
} |
882 |
|
|
} |