1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
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 |
import java.awt.Dimension; |
26 |
import java.awt.Insets; |
27 |
|
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
|
31 |
import java.beans.PropertyChangeEvent; |
32 |
import java.beans.PropertyChangeListener; |
33 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.Box; |
36 |
import javax.swing.BoxLayout; |
37 |
import javax.swing.JButton; |
38 |
import javax.swing.JComponent; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JPanel; |
41 |
|
42 |
import org.jsampler.CC; |
43 |
|
44 |
import org.jvnet.substance.SubstanceImageCreator; |
45 |
|
46 |
import org.linuxsampler.lscp.SamplerChannel; |
47 |
|
48 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
49 |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
50 |
import static org.jsampler.view.fantasia.FantasiaUtils.*; |
51 |
|
52 |
|
53 |
/** |
54 |
* |
55 |
* @author Grigor Iliev |
56 |
*/ |
57 |
public class SmallChannelView extends PixmapPane implements ChannelView { |
58 |
private final Channel channel; |
59 |
private final ChannelOptionsView channelOptionsView; |
60 |
|
61 |
private final ChannelScreen screen; |
62 |
private final Channel.PowerButton btnPower; |
63 |
private final MuteButton btnMute = new MuteButton(); |
64 |
private final SoloButton btnSolo = new SoloButton(); |
65 |
private final Channel.OptionsButton btnOptions; |
66 |
|
67 |
/** Creates a new instance of <code>SmallChannelView</code> */ |
68 |
public |
69 |
SmallChannelView(Channel channel) { |
70 |
this(channel, new NormalChannelOptionsView(channel)); |
71 |
} |
72 |
|
73 |
/** Creates a new instance of <code>SmallChannelView</code> */ |
74 |
public |
75 |
SmallChannelView(Channel channel, ChannelOptionsView channelOptionsView) { |
76 |
super(Res.gfxDeviceBg); |
77 |
|
78 |
setPixmapInsets(new Insets(1, 1, 1, 1)); |
79 |
|
80 |
this.channel = channel; |
81 |
this.channelOptionsView = channelOptionsView; |
82 |
|
83 |
addMouseListener(channel.getContextMenu()); |
84 |
|
85 |
screen = new ChannelScreen(channel); |
86 |
btnPower = new Channel.PowerButton(channel); |
87 |
btnOptions = new Channel.OptionsButton(channel); |
88 |
|
89 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
90 |
|
91 |
setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 11)); |
92 |
|
93 |
add(btnPower); |
94 |
add(Box.createRigidArea(new Dimension(4, 0))); |
95 |
|
96 |
add(createVSeparator()); |
97 |
add(Box.createRigidArea(new Dimension(3, 0))); |
98 |
|
99 |
add(screen); |
100 |
|
101 |
add(Box.createRigidArea(new Dimension(2, 0))); |
102 |
add(createVSeparator()); |
103 |
add(new FxSendsButton()); |
104 |
|
105 |
add(createVSeparator()); |
106 |
add(Box.createRigidArea(new Dimension(1, 0))); |
107 |
|
108 |
add(btnMute); |
109 |
add(btnSolo); |
110 |
|
111 |
add(Box.createRigidArea(new Dimension(1, 0))); |
112 |
add(createVSeparator()); |
113 |
add(Box.createRigidArea(new Dimension(8, 0))); |
114 |
|
115 |
add(btnOptions); |
116 |
|
117 |
setPreferredSize(new Dimension(420, 22)); |
118 |
setMinimumSize(getPreferredSize()); |
119 |
setMaximumSize(getPreferredSize()); |
120 |
|
121 |
installView(); |
122 |
} |
123 |
|
124 |
////////////////////////////////////////////// |
125 |
// Implementation of the ChannelView interface |
126 |
////////////////////////////////////////////// |
127 |
|
128 |
public JComponent |
129 |
getComponent() { return this; } |
130 |
|
131 |
public void |
132 |
installView() { |
133 |
String vmud = VOL_MEASUREMENT_UNIT_DECIBEL; |
134 |
preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() { |
135 |
public void |
136 |
propertyChange(PropertyChangeEvent e) { |
137 |
boolean b; |
138 |
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
139 |
screen.updateVolumeInfo(); |
140 |
} |
141 |
}); |
142 |
} |
143 |
|
144 |
public void |
145 |
uninstallView() { |
146 |
|
147 |
} |
148 |
|
149 |
public ChannelOptionsView |
150 |
getChannelOptionsView() { return channelOptionsView; } |
151 |
|
152 |
public void |
153 |
updateChannelInfo() { |
154 |
SamplerChannel sc = channel.getChannelInfo(); |
155 |
|
156 |
screen.updateScreenInfo(sc); |
157 |
screen.updateVolumeInfo(); |
158 |
updateMuteIcon(sc); |
159 |
|
160 |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloSmallOn); |
161 |
else btnSolo.setIcon(Res.gfxSoloSmallOff); |
162 |
|
163 |
boolean b = sc.getEngine() != null; |
164 |
btnSolo.setEnabled(b); |
165 |
btnMute.setEnabled(b); |
166 |
} |
167 |
|
168 |
public void |
169 |
updateStreamCount(int count) { screen.updateStreamCount(count); } |
170 |
|
171 |
public void |
172 |
updateVoiceCount(int count) { screen.updateVoiceCount(count); } |
173 |
|
174 |
public void |
175 |
expandChannel() { |
176 |
if(btnOptions.isSelected()) return; |
177 |
btnOptions.doClick(); |
178 |
} |
179 |
|
180 |
////////////////////////////////////////////// |
181 |
|
182 |
|
183 |
/** |
184 |
* Updates the mute button with the proper icon regarding to information obtained |
185 |
* from <code>channel</code>. |
186 |
* @param channel A <code>SamplerChannel</code> instance containing the new settings |
187 |
* for this channel. |
188 |
*/ |
189 |
private void |
190 |
updateMuteIcon(SamplerChannel channel) { |
191 |
if(channel.isMutedBySolo()) btnMute.setIcon(Res.gfxMutedBySoloSmall); |
192 |
else if(channel.isMuted()) btnMute.setIcon(Res.gfxMuteSmallOn); |
193 |
else btnMute.setIcon(Res.gfxMuteSmallOff); |
194 |
} |
195 |
|
196 |
protected JPanel |
197 |
createVSeparator() { |
198 |
PixmapPane p = new PixmapPane(Res.gfxVLine); |
199 |
p.setOpaque(false); |
200 |
p.setPreferredSize(new Dimension(2, 22)); |
201 |
p.setMinimumSize(p.getPreferredSize()); |
202 |
p.setMaximumSize(p.getPreferredSize()); |
203 |
return p; |
204 |
} |
205 |
|
206 |
|
207 |
private class MuteButton extends PixmapButton implements ActionListener { |
208 |
MuteButton() { |
209 |
super(Res.gfxMuteSmallOff); |
210 |
setDisabledIcon ( |
211 |
SubstanceImageCreator.makeTransparent(this, Res.gfxMuteSmallOff, 0.4) |
212 |
); |
213 |
addActionListener(this); |
214 |
} |
215 |
|
216 |
public void |
217 |
actionPerformed(ActionEvent e) { |
218 |
SamplerChannel sc = channel.getChannelInfo(); |
219 |
boolean b = true; |
220 |
|
221 |
/* |
222 |
* Changing the mute button icon now instead of |
223 |
* leaving the work to the notification mechanism of the LinuxSampler. |
224 |
*/ |
225 |
if(sc.isMuted() && !sc.isMutedBySolo()) { |
226 |
b = false; |
227 |
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
228 |
|
229 |
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.gfxMuteSmallOff); |
230 |
else setIcon(Res.gfxMutedBySoloSmall); |
231 |
} else setIcon(Res.gfxMuteSmallOn); |
232 |
|
233 |
channel.getModel().setBackendMute(b); |
234 |
} |
235 |
|
236 |
//public boolean |
237 |
//contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
238 |
} |
239 |
|
240 |
private class SoloButton extends PixmapButton implements ActionListener { |
241 |
SoloButton() { |
242 |
super(Res.gfxSoloSmallOff); |
243 |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
244 |
setDisabledIcon ( |
245 |
SubstanceImageCreator.makeTransparent(this, Res.gfxSoloSmallOff, 0.4) |
246 |
); |
247 |
addActionListener(this); |
248 |
} |
249 |
|
250 |
public void |
251 |
actionPerformed(ActionEvent e) { |
252 |
SamplerChannel sc = channel.getChannelInfo(); |
253 |
boolean b = !sc.isSoloChannel(); |
254 |
|
255 |
/* |
256 |
* Changing the solo button icon (and related) now instead of |
257 |
* leaving the work to the notification mechanism of the LinuxSampler. |
258 |
*/ |
259 |
if(b) { |
260 |
setIcon(Res.gfxSoloSmallOn); |
261 |
if(sc.isMutedBySolo()) btnMute.setIcon(Res.gfxMuteSmallOff); |
262 |
} else { |
263 |
setIcon(Res.gfxSoloSmallOff); |
264 |
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
265 |
btnMute.setIcon(Res.gfxMutedBySoloSmall); |
266 |
} |
267 |
|
268 |
channel.getModel().setBackendSolo(b); |
269 |
} |
270 |
|
271 |
//public boolean |
272 |
//contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
273 |
} |
274 |
|
275 |
static class ChannelScreen extends PixmapPane { |
276 |
private final Channel channel; |
277 |
|
278 |
//private final ChannelInfoPane channelInfoPane; |
279 |
|
280 |
private final Channel.StreamVoiceCountPane streamVoiceCountPane; |
281 |
|
282 |
|
283 |
private final Channel.VolumePane volumePane; |
284 |
|
285 |
private JButton btnInstr = |
286 |
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
287 |
|
288 |
|
289 |
private static Insets pixmapInsets = new Insets(5, 5, 4, 5); |
290 |
|
291 |
ChannelScreen(final Channel channel) { |
292 |
super(Res.gfxTextField); |
293 |
|
294 |
this.channel = channel; |
295 |
|
296 |
addMouseListener(channel.getContextMenu()); |
297 |
|
298 |
streamVoiceCountPane = new Channel.StreamVoiceCountPane(channel); |
299 |
|
300 |
//channelInfoPane = new ChannelInfoPane(channel); |
301 |
volumePane = new Channel.VolumePane(channel); |
302 |
|
303 |
setPixmapInsets(pixmapInsets); |
304 |
setBorder(BorderFactory.createEmptyBorder(4, 3, 3, 4)); |
305 |
|
306 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
307 |
|
308 |
JPanel p = new JPanel(); |
309 |
p.setOpaque(false); |
310 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
311 |
|
312 |
//p.add(channelInfoPane); |
313 |
|
314 |
btnInstr.setRolloverEnabled(false); |
315 |
btnInstr.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
316 |
btnInstr.setHorizontalAlignment(btnInstr.LEFT); |
317 |
btnInstr.addMouseListener(channel.getContextMenu()); |
318 |
|
319 |
int h = btnInstr.getPreferredSize().height; |
320 |
btnInstr.setPreferredSize(new Dimension(100, h)); |
321 |
btnInstr.setMinimumSize(btnInstr.getPreferredSize()); |
322 |
btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
323 |
|
324 |
p.add(btnInstr); |
325 |
|
326 |
h = p.getPreferredSize().height; |
327 |
p.setPreferredSize(new Dimension(159, h)); |
328 |
p.setMinimumSize(p.getPreferredSize()); |
329 |
p.setMaximumSize(p.getPreferredSize()); |
330 |
|
331 |
add(p); |
332 |
|
333 |
add(Box.createRigidArea(new Dimension(3, 0))); |
334 |
add(streamVoiceCountPane); |
335 |
add(volumePane); |
336 |
|
337 |
setPreferredSize(new Dimension(270, getPreferredSize().height)); |
338 |
setMinimumSize(getPreferredSize()); |
339 |
setMaximumSize(getPreferredSize()); |
340 |
|
341 |
btnInstr.addActionListener(new ActionListener() { |
342 |
public void |
343 |
actionPerformed(ActionEvent e) { channel.loadInstrument(); } |
344 |
}); |
345 |
} |
346 |
|
347 |
protected void |
348 |
updateVolumeInfo() { |
349 |
float f = channel.getChannelInfo().getVolume() * 100.0f; |
350 |
volumePane.updateVolumeInfo((int)f); |
351 |
} |
352 |
|
353 |
/** |
354 |
* Updates the number of active disk streams. |
355 |
* @param count The new number of active disk streams. |
356 |
*/ |
357 |
protected void |
358 |
updateStreamCount(int count) { |
359 |
streamVoiceCountPane.updateStreamCount(count); |
360 |
} |
361 |
|
362 |
/** |
363 |
* Updates the number of active voices. |
364 |
* @param count The new number of active voices. |
365 |
*/ |
366 |
protected void |
367 |
updateVoiceCount(int count) { |
368 |
streamVoiceCountPane.updateVoiceCount(count); |
369 |
} |
370 |
|
371 |
protected void |
372 |
updateScreenInfo(SamplerChannel sc) { |
373 |
int status = sc.getInstrumentStatus(); |
374 |
if(status >= 0 && status < 100) { |
375 |
btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status)); |
376 |
} else if(status == -1) { |
377 |
btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
378 |
} else if(status < -1) { |
379 |
btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument")); |
380 |
} else { |
381 |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
382 |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
383 |
} |
384 |
|
385 |
//channelInfoPane.updateChannelInfo(); |
386 |
} |
387 |
} |
388 |
|
389 |
private static class ChannelInfoPane extends JPanel { |
390 |
private final Channel channel; |
391 |
private final JLabel lInfo; |
392 |
|
393 |
ChannelInfoPane(Channel channel) { |
394 |
this.channel = channel; |
395 |
|
396 |
setOpaque(false); |
397 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
398 |
|
399 |
lInfo = createScreenLabel(""); |
400 |
lInfo.setFont(Res.fontScreenMono); |
401 |
lInfo.setText("1234"); |
402 |
lInfo.setPreferredSize(lInfo.getPreferredSize()); // Don't remove this! |
403 |
lInfo.setMinimumSize(lInfo.getPreferredSize()); |
404 |
lInfo.setMaximumSize(lInfo.getPreferredSize()); |
405 |
|
406 |
updateChannelInfo(); |
407 |
|
408 |
add(lInfo); |
409 |
|
410 |
setPreferredSize(getPreferredSize()); // Don't remove this! |
411 |
setMinimumSize(getPreferredSize()); |
412 |
setMaximumSize(getPreferredSize()); |
413 |
} |
414 |
|
415 |
protected void |
416 |
updateChannelInfo() { |
417 |
String s = channel.getChannelId() < 10 ? " " : ""; |
418 |
s += String.valueOf(channel.getChannelId()) + ":"; |
419 |
|
420 |
/*SamplerChannel sc = channel.getChannelInfo(); |
421 |
s += sc.getMidiInputPort() + "/"; |
422 |
|
423 |
if(sc.getMidiInputChannel() == -1) s += "All"; |
424 |
else s += sc.getMidiInputChannel() + 1;*/ |
425 |
lInfo.setText(s); |
426 |
} |
427 |
} |
428 |
|
429 |
private class FxSendsButton extends PixmapButton implements ActionListener { |
430 |
FxSendsButton() { |
431 |
super(Res.gfxFx); |
432 |
|
433 |
setRolloverIcon(Res.gfxFxRO); |
434 |
|
435 |
addActionListener(this); |
436 |
} |
437 |
|
438 |
public void |
439 |
actionPerformed(ActionEvent e) { channel.showFxSendsDialog(); } |
440 |
|
441 |
public boolean |
442 |
contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
443 |
} |
444 |
} |