/[svn]/jsampler/trunk/src/org/jsampler/JSPrefs.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/JSPrefs.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1540 - (hide annotations) (download)
Mon Dec 3 23:22:02 2007 UTC (16 years, 4 months ago) by iliev
File size: 9824 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;
24    
25     import java.beans.PropertyChangeSupport;
26 iliev 1308
27     import java.io.BufferedReader;
28     import java.io.StringReader;
29    
30     import java.util.Vector;
31 iliev 1286 import java.util.prefs.Preferences;
32    
33     /**
34     *
35     * @author Grigor Iliev
36     */
37     public class JSPrefs extends PropertyChangeSupport {
38 iliev 1313 /**
39     * Property which specifies whether to apply default
40     * actions to newly created sampler channels.
41     */
42     public final static String USE_CHANNEL_DEFAULTS = "samplerChannel.useDefaultActions";
43    
44     /**
45     * Property representing the default engine to be used when
46     * new sampler channel is created. The action is taken only if
47     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
48     */
49     public final static String DEFAULT_ENGINE = "defaultEngine";
50    
51     /**
52     * Property representing the default MIDI input to be used when
53     * new sampler channel is created. The action is taken only if
54     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
55     */
56     public final static String DEFAULT_MIDI_INPUT = "defaultMidiInput";
57    
58     /**
59     * Property representing the default audio output to be used when
60     * new sampler channel is created. The action is taken only if
61     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
62     */
63     public final static String DEFAULT_AUDIO_OUTPUT = "defaultAudioOutput";
64    
65 iliev 1315 /**
66 iliev 1334 * Property representing the default MIDI instrument map to be used when
67     * new sampler channel is created. The action is taken only if
68     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
69     */
70     public final static String DEFAULT_MIDI_INSTRUMENT_MAP = "defaultMidiInstrumentMap";
71    
72     /**
73     * Property representing the default channel volume when
74     * new sampler channel is created. The action is taken only if
75     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
76     */
77     public final static String DEFAULT_CHANNEL_VOLUME = "defaultChannelVolume";
78    
79     /**
80 iliev 1315 * Property representing the default MIDI input driver to be used
81     * when creating new MIDI input device.
82     */
83     public final static String DEFAULT_MIDI_DRIVER = "defaultMidiDriver";
84 iliev 1313
85 iliev 1315 /**
86     * Property representing the default audio output driver to be used
87     * when creating new audio output device.
88     */
89     public final static String DEFAULT_AUDIO_DRIVER = "defaultAudioDriver";
90    
91 iliev 1540 /** Property which specifies whether the volume values should be shown in decibels. */
92     public final static String VOL_MEASUREMENT_UNIT_DECIBEL = "volMeasurementUnitDecibel";
93 iliev 1315
94 iliev 1540
95 iliev 1286 private final String pathName;
96     private final Preferences userPrefs;
97    
98     /**
99     * Creates a new instance of <code>JSPrefs</code>.
100     * @param pathName The path name of the preferences node.
101     */
102     public
103     JSPrefs(String pathName) {
104     super(new Object());
105    
106     this.pathName = pathName;
107     userPrefs = Preferences.userRoot().node(pathName);
108     }
109    
110     private Preferences
111     user() { return userPrefs; }
112    
113     /**
114     * Gets a string property.
115     * @param name The name of the property.
116     * @return The value of the specified property.
117     * If the property is not set, the return value is <code>null</code>.
118     * @see #getDefaultStringValue
119     */
120     public String
121     getStringProperty(String name) {
122     return getStringProperty(name, getDefaultStringValue(name));
123     }
124    
125     /**
126     * Gets a string property.
127     * @param name The name of the property.
128     * @param defaultValue The value to return if the property is not set.
129     * @return The value of the specified property.
130     */
131     public String
132     getStringProperty(String name, String defaultValue) {
133     return user().get(name, defaultValue);
134     }
135    
136     /**
137 iliev 1308 * Sets a string property.
138 iliev 1286 * @param name The name of the property.
139 iliev 1308 * @param s The new value for the specified property.
140 iliev 1286 */
141     public void
142     setStringProperty(String name, String s) {
143     String oldValue = getStringProperty(name);
144    
145     if(s == null) user().remove(name);
146     else user().put(name, s);
147    
148     firePropertyChange(name, oldValue, s);
149     }
150    
151     /**
152     * Gets the default value for the specified property.
153     * The default value is used when the property is not set.
154     * Override this method to provide custom default values for specific properties.
155 iliev 1327 * @param name The name of the property whose default value should be obtained.
156 iliev 1286 * @return <code>null</code>
157     * @see #getStringProperty(String name)
158     */
159     public String
160     getDefaultStringValue(String name) { return null; }
161    
162     /**
163 iliev 1308 * Gets a string list property.
164     * @param name The name of the property.
165     * @return The value of the specified property.
166     * If the property is not set, the return value is an empty array.
167     * @see #getDefaultStringListValue
168     */
169     public String[]
170     getStringListProperty(String name) {
171     return getStringListProperty(name, getDefaultStringListValue(name));
172     }
173    
174     /**
175     * Gets a string list property.
176     * @param name The name of the property.
177     * @param defaultValue The value to return if the property is not set.
178     * @return The value of the specified property.
179     */
180     public String[]
181     getStringListProperty(String name, String[] defaultValue) {
182     String s = user().get(name, null);
183     if(s == null) return defaultValue;
184     if(s.length() == 0) return new String[0];
185    
186     BufferedReader br = new BufferedReader(new StringReader(s));
187     Vector<String> v = new Vector();
188    
189     try {
190     s = br.readLine();
191     while(s != null) {
192     v.add(s);
193     s = br.readLine();
194     }
195     } catch(Exception x) {
196     x.printStackTrace();
197     }
198    
199     return v.toArray(new String[v.size()]);
200     }
201    
202     /**
203     * Sets a string list property.
204     * Note that the string elements may not contain new lines.
205     * @param name The name of the property.
206     * @param list The new value for the specified property.
207     */
208     public void
209     setStringListProperty(String name, String[] list) {
210     String[] oldValue = getStringListProperty(name);
211    
212     if(list == null) user().remove(name);
213     else {
214     StringBuffer sb = new StringBuffer();
215     for(String s : list) sb.append(s).append("\n");
216     user().put(name, sb.toString());
217     }
218    
219     firePropertyChange(name, oldValue, list);
220     }
221    
222     /**
223     * Gets the default value for the specified property.
224     * The default value is used when the property is not set.
225     * Override this method to provide custom default values for specific properties.
226 iliev 1327 * @param name The name of the property whose default value should be obtained.
227 iliev 1308 * @return An empty array.
228     * @see #getStringListProperty(String name)
229     */
230     public String[]
231     getDefaultStringListValue(String name) { return new String[0]; }
232    
233     /**
234 iliev 1286 * Gets an integer property.
235     * @param name The name of the property.
236     * @return The value of the specified property.
237     * @see #getDefaultIntValue
238     */
239     public int
240     getIntProperty(String name) {
241     return getIntProperty(name, getDefaultIntValue(name));
242     }
243    
244     /**
245     * Gets an integer property.
246     * @param name The name of the property.
247     * @param defaultValue The value to return if the property is not set.
248     * @return The value of the specified property.
249     */
250     public int
251     getIntProperty(String name, int defaultValue) {
252     return user().getInt(name, defaultValue);
253     }
254    
255     /**
256     * Gets the default value for the specified property.
257     * The default value is used when the property is not set.
258     * Override this method to provide custom default values for specific properties.
259 iliev 1327 * @param name The name of the property whose default value should be obtained.
260 iliev 1286 * @return <code>0</code>
261     * @see #getIntProperty(String name)
262     */
263     public int
264     getDefaultIntValue(String name) { return 0; }
265    
266     /**
267     * Sets an integer property.
268     * @param name The name of the property.
269     * @param i The new value for the specified property.
270     */
271     public void
272     setIntProperty(String name, int i) {
273     int oldValue = getIntProperty(name);
274     user().putInt(name, i);
275     firePropertyChange(name, oldValue, i);
276     }
277    
278    
279     /**
280     * Gets a boolean property.
281     * @param name The name of the property.
282     * @return The value of the specified property.
283     * @see #getDefaultBoolValue
284     */
285     public boolean
286     getBoolProperty(String name) {
287     return getBoolProperty(name, getDefaultBoolValue(name));
288     }
289     /**
290     * Gets a boolean property.
291     * @param name The name of the property.
292     * @param defaultValue The value to return if the property is not set.
293     * @return The value of the specified property.
294     */
295     public boolean
296     getBoolProperty(String name, boolean defaultValue) {
297     return user().getBoolean(name, defaultValue);
298     }
299    
300     /**
301     * Sets a boolean property.
302     * @param name The name of the property.
303     * @param b The new value for the specified property.
304     */
305     public void
306     setBoolProperty(String name, boolean b) {
307     boolean oldValue = getBoolProperty(name);
308     user().putBoolean(name, b);
309     firePropertyChange(name, oldValue, b);
310     }
311    
312     /**
313     * Gets the default value for the specified property.
314     * The default value is used when the property is not set.
315     * Override this method to provide custom default values for specific properties.
316 iliev 1327 * @param name The name of the property whose default value should be obtained.
317 iliev 1286 * @see #getBoolProperty(String name)
318     */
319     public boolean
320 iliev 1540 getDefaultBoolValue(String name) {
321     if(name == VOL_MEASUREMENT_UNIT_DECIBEL) return true;
322     return false;
323     }
324 iliev 1286 }

  ViewVC Help
Powered by ViewVC