/[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 1734 - (show annotations) (download)
Sun May 4 18:40:13 2008 UTC (15 years, 11 months ago) by iliev
File size: 13746 byte(s)
* bugfix: JSampler took forever to load a configuration with
  too many sampler channels
* Implemented option to show different channel view when
  the mouse pointer is over sampler channel
  (choose Edit/Preferences, then click the `Defaults' tab)

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 addMouseListener(channel.getContextMenu());
91
92 screen = new ChannelScreen(channel);
93
94 btnPower = new Channel.PowerButton(channel);
95 components.add(btnPower);
96
97 btnOptions = new Channel.OptionsButton(channel);
98 components.add(btnOptions);
99
100 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
101
102 setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 11));
103
104 add(btnPower);
105 add(Box.createRigidArea(new Dimension(4, 0)));
106
107 add(createVSeparator());
108 add(Box.createRigidArea(new Dimension(3, 0)));
109
110 add(screen);
111
112 add(Box.createRigidArea(new Dimension(2, 0)));
113 add(createVSeparator());
114 add(new FxSendsButton());
115
116 add(createVSeparator());
117 add(Box.createRigidArea(new Dimension(1, 0)));
118
119 components.add(btnMute);
120 components.add(btnSolo);
121
122 add(btnMute);
123 add(btnSolo);
124
125 add(Box.createRigidArea(new Dimension(1, 0)));
126 add(createVSeparator());
127 add(Box.createRigidArea(new Dimension(8, 0)));
128
129 add(btnOptions);
130
131 setPreferredSize(new Dimension(420, 22));
132 setMinimumSize(getPreferredSize());
133 setMaximumSize(getPreferredSize());
134
135 installView();
136 }
137
138 //////////////////////////////////////////////
139 // Implementation of the ChannelView interface
140 //////////////////////////////////////////////
141
142 public Type
143 getType() { return Type.SMALL; }
144
145 public JComponent
146 getComponent() { return this; }
147
148 public void
149 installView() {
150 String vmud = VOL_MEASUREMENT_UNIT_DECIBEL;
151 preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() {
152 public void
153 propertyChange(PropertyChangeEvent e) {
154 boolean b;
155 b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL);
156 screen.updateVolumeInfo();
157 }
158 });
159 }
160
161 public void
162 uninstallView() {
163
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 addMouseListener(channel.getContextMenu());
340
341 streamVoiceCountPane = new Channel.StreamVoiceCountPane(channel);
342 components.add(streamVoiceCountPane);
343
344 //channelInfoPane = new ChannelInfoPane(channel);
345 volumePane = new Channel.VolumePane(channel);
346 components.add(volumePane);
347
348 setPixmapInsets(pixmapInsets);
349 setBorder(BorderFactory.createEmptyBorder(4, 3, 3, 4));
350
351 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
352
353 JPanel p = new JPanel();
354 components.add(p);
355 p.setOpaque(false);
356 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
357
358 //p.add(channelInfoPane);
359
360 btnInstr.setRolloverEnabled(false);
361 btnInstr.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
362 btnInstr.setHorizontalAlignment(btnInstr.LEFT);
363 btnInstr.addMouseListener(channel.getContextMenu());
364
365 int h = btnInstr.getPreferredSize().height;
366 btnInstr.setPreferredSize(new Dimension(100, h));
367 btnInstr.setMinimumSize(btnInstr.getPreferredSize());
368 btnInstr.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
369 components.add(btnInstr);
370
371 p.add(btnInstr);
372
373 h = p.getPreferredSize().height;
374 p.setPreferredSize(new Dimension(159, h));
375 p.setMinimumSize(p.getPreferredSize());
376 p.setMaximumSize(p.getPreferredSize());
377
378 add(p);
379
380 add(Box.createRigidArea(new Dimension(3, 0)));
381 add(streamVoiceCountPane);
382 add(volumePane);
383
384 setPreferredSize(new Dimension(270, getPreferredSize().height));
385 setMinimumSize(getPreferredSize());
386 setMaximumSize(getPreferredSize());
387
388 btnInstr.addActionListener(new ActionListener() {
389 public void
390 actionPerformed(ActionEvent e) { channel.loadInstrument(); }
391 });
392 }
393
394 public void
395 addEnhancedMouseListener(MouseListener l) {
396 removeEnhancedMouseListener(l);
397 for(JComponent c : components) c.addMouseListener(l);
398 }
399
400 public void
401 removeEnhancedMouseListener(MouseListener l) {
402 for(JComponent c : components) c.removeMouseListener(l);
403 }
404
405 protected void
406 updateVolumeInfo() {
407 float f = channel.getChannelInfo().getVolume() * 100.0f;
408 volumePane.updateVolumeInfo((int)f);
409 }
410
411 /**
412 * Updates the number of active disk streams.
413 * @param count The new number of active disk streams.
414 */
415 protected void
416 updateStreamCount(int count) {
417 streamVoiceCountPane.updateStreamCount(count);
418 }
419
420 /**
421 * Updates the number of active voices.
422 * @param count The new number of active voices.
423 */
424 protected void
425 updateVoiceCount(int count) {
426 streamVoiceCountPane.updateVoiceCount(count);
427 }
428
429 protected void
430 updateScreenInfo(SamplerChannel sc) {
431 int status = sc.getInstrumentStatus();
432 if(status >= 0 && status < 100) {
433 btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status));
434 } else if(status == -1) {
435 btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
436 } else if(status < -1) {
437 btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument"));
438 } else {
439 if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
440 else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
441 }
442
443 //channelInfoPane.updateChannelInfo();
444 }
445 }
446
447 private static class ChannelInfoPane extends JPanel {
448 private final Channel channel;
449 private final JLabel lInfo;
450
451 ChannelInfoPane(Channel channel) {
452 this.channel = channel;
453
454 setOpaque(false);
455 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
456
457 lInfo = createScreenLabel("");
458 lInfo.setFont(Res.fontScreenMono);
459 lInfo.setText("1234");
460 lInfo.setPreferredSize(lInfo.getPreferredSize()); // Don't remove this!
461 lInfo.setMinimumSize(lInfo.getPreferredSize());
462 lInfo.setMaximumSize(lInfo.getPreferredSize());
463
464 updateChannelInfo();
465
466 add(lInfo);
467
468 setPreferredSize(getPreferredSize()); // Don't remove this!
469 setMinimumSize(getPreferredSize());
470 setMaximumSize(getPreferredSize());
471 }
472
473 protected void
474 updateChannelInfo() {
475 String s = channel.getChannelId() < 10 ? " " : "";
476 s += String.valueOf(channel.getChannelId()) + ":";
477
478 /*SamplerChannel sc = channel.getChannelInfo();
479 s += sc.getMidiInputPort() + "/";
480
481 if(sc.getMidiInputChannel() == -1) s += "All";
482 else s += sc.getMidiInputChannel() + 1;*/
483 lInfo.setText(s);
484 }
485 }
486
487 private class FxSendsButton extends PixmapButton implements ActionListener {
488 FxSendsButton() {
489 super(Res.gfxFx);
490
491 setRolloverIcon(Res.gfxFxRO);
492
493 addActionListener(this);
494 }
495
496 public void
497 actionPerformed(ActionEvent e) { channel.showFxSendsDialog(); }
498
499 public boolean
500 contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); }
501 }
502 }

  ViewVC Help
Powered by ViewVC