/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/SmallChannelView.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/SmallChannelView.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1735 - (show annotations) (download)
Sun May 4 18:58:16 2008 UTC (15 years, 11 months ago) by iliev
File size: 13703 byte(s)
- fixed channel context menu

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

  ViewVC Help
Powered by ViewVC