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

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/ChannelsBar.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 8160 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2288 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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 iliev 1540 import java.awt.event.ActionEvent;
29     import java.awt.event.ActionListener;
30 iliev 1357
31     import java.beans.PropertyChangeEvent;
32     import java.beans.PropertyChangeListener;
33    
34 iliev 1540 import java.text.NumberFormat;
35    
36     import javax.swing.BorderFactory;
37 iliev 1286 import javax.swing.Box;
38     import javax.swing.BoxLayout;
39 iliev 1540 import javax.swing.JButton;
40 iliev 1286 import javax.swing.JLabel;
41 iliev 1540 import javax.swing.JPanel;
42 iliev 1286 import javax.swing.JSlider;
43    
44 iliev 1357 import javax.swing.event.ChangeEvent;
45     import javax.swing.event.ChangeListener;
46    
47     import org.jsampler.CC;
48 iliev 1540 import org.jsampler.HF;
49 iliev 1357
50     import org.jsampler.event.SamplerAdapter;
51     import org.jsampler.event.SamplerEvent;
52    
53 iliev 1785 import org.jsampler.view.fantasia.basic.*;
54    
55 iliev 1540 import org.jsampler.view.std.JSVolumeEditorPopup;
56    
57 iliev 2288 import static org.jsampler.JSPrefs.*;
58 iliev 1357 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
59     import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
60 iliev 1540 import static org.jsampler.view.fantasia.FantasiaUtils.*;
61     import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType;
62 iliev 1357
63 iliev 1286 /**
64     *
65     * @author Grigor Iliev
66     */
67     public class ChannelsBar extends PixmapPane {
68     private final JSlider slVolume = new JSlider();
69 iliev 1540 JButton btnVolume = FantasiaUtils.createScreenButton("3 dB");
70 iliev 1286
71 iliev 1540 private final JLabel lStreams = createScreenLabel(" --");
72     private final JLabel lVoices = createScreenLabel("-- ");
73     private JSVolumeEditorPopup popupVolume;
74    
75 iliev 1785 private final FantasiaToggleButtonsPanel buttonsPanel;
76    
77 iliev 1540 private static NumberFormat numberFormat = NumberFormat.getInstance();
78    
79 iliev 1286 /** Creates a new instance of <code>ChannelsBar</code> */
80     public
81 iliev 1785 ChannelsBar(FantasiaToggleButtonsPanel buttonsPanel) {
82 iliev 1286 super(Res.gfxCreateChannel);
83 iliev 1540
84 iliev 1785 this.buttonsPanel = buttonsPanel;
85    
86 iliev 1540 numberFormat.setMaximumFractionDigits(1);
87     popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.MASTER);
88    
89 iliev 1286 setPixmapInsets(new Insets(1, 1, 1, 1));
90    
91     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
92    
93     add(Box.createRigidArea(new Dimension(5, 0)));
94     JLabel l = new JLabel(Res.iconVolume22);
95     add(l);
96    
97 iliev 1785 slVolume.setUI(new FantasiaFaderUI(slVolume));
98     slVolume.putClientProperty("Fader.knobSize", new Dimension(15, 22));
99 iliev 1286 slVolume.setOpaque(false);
100     slVolume.setFocusable(false);
101     Dimension d = new Dimension(150, 22);
102     slVolume.setPreferredSize(d);
103     slVolume.setMaximumSize(d);
104 iliev 1785 slVolume.setAlignmentY(CENTER_ALIGNMENT);
105 iliev 1286
106     add(slVolume);
107 iliev 1540 add(Box.createRigidArea(new Dimension(5, 0)));
108 iliev 1357
109 iliev 1540 PixmapPane p = new PixmapPane(Res.gfxTextField);
110     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
111     p.setPixmapInsets(new Insets(5, 5, 4, 5));
112 iliev 1743 p.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 5));
113 iliev 1540
114     lStreams.setFont(Res.fontScreenMono);
115     lStreams.setHorizontalAlignment(JLabel.RIGHT);
116     lStreams.setPreferredSize(lStreams.getPreferredSize());
117     lStreams.setMaximumSize(lStreams.getPreferredSize());
118     lStreams.setToolTipText(i18n.getLabel("ChannelsBar.streamVoiceCount"));
119     p.add(lStreams);
120    
121     l = createScreenLabel("/");
122     l.setFont(Res.fontScreenMono);
123     l.setToolTipText(i18n.getLabel("ChannelsBar.streamVoiceCount"));
124     p.add(l);
125    
126     lVoices.setFont(Res.fontScreenMono);
127     lVoices.setPreferredSize(lVoices.getPreferredSize());
128     lVoices.setMaximumSize(lVoices.getPreferredSize());
129     lVoices.setToolTipText(i18n.getLabel("ChannelsBar.streamVoiceCount"));
130     p.add(lVoices);
131    
132     btnVolume.setIcon(Res.iconVolume14);
133     btnVolume.setIconTextGap(2);
134 iliev 1872 btnVolume.setHorizontalAlignment(JButton.LEFT);
135 iliev 1540 d = btnVolume.getPreferredSize();
136 iliev 1785 d.width = 65;
137 iliev 1540 btnVolume.setPreferredSize(d);
138     btnVolume.setMaximumSize(d);
139     p.add(btnVolume);
140    
141     p.setMaximumSize(p.getPreferredSize());
142 iliev 1785 p.setAlignmentY(CENTER_ALIGNMENT);
143 iliev 1540
144     add(p);
145 iliev 1785
146     add(Box.createRigidArea(new Dimension(2, 0)));
147     add(createVSeparator());
148 iliev 1872 add(Box.createRigidArea(new Dimension(6, 0)));
149 iliev 1785
150     buttonsPanel.setAlignmentY(CENTER_ALIGNMENT);
151     add(buttonsPanel);
152 iliev 1286 add(Box.createGlue());
153    
154     d = new Dimension(420, 29);
155     setMinimumSize(d);
156     setPreferredSize(d);
157     setMaximumSize(d);
158    
159 iliev 1357 int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
160     slVolume.setMaximum(i);
161     String s = MAXIMUM_MASTER_VOLUME;
162     preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
163     public void
164     propertyChange(PropertyChangeEvent e) {
165     int j = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
166     slVolume.setMaximum(j);
167     }
168     });
169    
170     slVolume.addChangeListener(new ChangeListener() {
171     public void
172     stateChanged(ChangeEvent e) { setVolume(); }
173     });
174    
175     CC.getSamplerModel().addSamplerListener(new SamplerAdapter() {
176     public void
177     volumeChanged(SamplerEvent e) { updateVolume(); }
178 iliev 1545
179     public void
180     totalVoiceCountChanged(SamplerEvent e) {
181     int i = CC.getSamplerModel().getTotalVoiceCount();
182     if(i == 0) lVoices.setText("--");
183     else lVoices.setText(String.valueOf(i));
184     }
185    
186     public void
187     totalStreamCountChanged(SamplerEvent e) {
188     int i = CC.getSamplerModel().getTotalStreamCount();
189     if(i == 0) lStreams.setText("--");
190     else lStreams.setText(String.valueOf(i));
191     }
192 iliev 1357 });
193    
194     updateVolume();
195    
196 iliev 1540 btnVolume.addActionListener(new ActionListener() {
197 iliev 1357 public void
198 iliev 1540 actionPerformed(ActionEvent e) {
199     if(popupVolume.isVisible()) {
200     popupVolume.commit();
201     popupVolume.hide();
202     } else {
203     float vol = CC.getSamplerModel().getVolume();
204     popupVolume.setCurrentVolume(vol);
205     popupVolume.show();
206 iliev 1357 }
207     }
208 iliev 1540 });
209    
210     popupVolume.addActionListener(new ActionListener() {
211 iliev 1357 public void
212 iliev 1540 actionPerformed(ActionEvent e) {
213     CC.getSamplerModel().setBackendVolume(popupVolume.getVolumeFactor());
214 iliev 1357 }
215     });
216 iliev 1540
217     s = VOL_MEASUREMENT_UNIT_DECIBEL;
218     preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
219     public void
220     propertyChange(PropertyChangeEvent e) {
221     setVolume();
222     }
223     });
224 iliev 1286 }
225    
226 iliev 1785 /*@Override
227     protected void
228     paintComponent(Graphics g) {
229     if(isOpaque()) super.paintComponent(g);
230    
231     double h = getSize().getHeight();
232     double w = getSize().getWidth();
233     Graphics2D g2 = (Graphics2D)g;
234    
235     FantasiaPainter.paintGradient(g2, 0, 0, w - 1, h - 1);
236     RoundCorners rc = new RoundCorners(false, true, true, false);
237     FantasiaPainter.paintOuterBorder(g2, 0, -1, w - 1, h - 1, rc);
238    
239     }*/
240    
241 iliev 1357 private void
242     setVolume() {
243     int volume = slVolume.getValue();
244    
245 iliev 1540 if(CC.getViewConfig().isMeasurementUnitDecibel()) {
246     double dB = HF.percentsToDecibels(volume);
247     btnVolume.setText(numberFormat.format(dB) + "dB");
248     } else {
249     btnVolume.setText(volume + "%");
250     }
251    
252 iliev 1357 if(slVolume.getValueIsAdjusting()) return;
253    
254     int vol = (int)(CC.getSamplerModel().getVolume() * 100);
255    
256     if(vol == slVolume.getValue()) return;
257    
258     /*
259     * If the model's volume is not equal to the slider
260     * value we assume that the change is due to user input.
261     * So we must update the volume at the backend too.
262     */
263     float v = slVolume.getValue();
264     v /= 100;
265     CC.getSamplerModel().setBackendVolume(v);
266     }
267    
268     private void
269     updateVolume() {
270     slVolume.setValue((int)(CC.getSamplerModel().getVolume() * 100));
271     }
272    
273 iliev 1785 protected JPanel
274     createVSeparator() {
275     PixmapPane p = new PixmapPane(Res.gfxVLine);
276     p.setOpaque(false);
277     p.setPreferredSize(new Dimension(2, 29));
278     p.setMinimumSize(p.getPreferredSize());
279     p.setMaximumSize(p.getPreferredSize());
280     return p;
281     }
282 iliev 1286 }

  ViewVC Help
Powered by ViewVC