/[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 1540 - (hide annotations) (download)
Mon Dec 3 23:22:02 2007 UTC (16 years, 5 months ago) by iliev
File size: 6691 byte(s)
* Fantasia: by default the volume values are now shown in decibels
* Implemented support for retrieving instrument information
  from instrument files
* Some bugfixes and enhancements

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

  ViewVC Help
Powered by ViewVC