/[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 1767 - (hide annotations) (download)
Mon Sep 8 00:19:27 2008 UTC (15 years, 8 months ago) by iliev
File size: 11517 byte(s)
* Added `Copy To' and `Move To' commands to the MIDI bank context menu
  and to the MIDI instrument context menu
* Added commands to the MIDI instrument context menu for moving
  a MIDI instrument to another program
  (right-click on a MIDI instrument and choose `Change Program')
* Added option to choose between zero-based and one-based
  MIDI bank/program numbering
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to choose whether to include MIDI instrument
  mappings when exporting a sampler configuration to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to set the MIDI instrument loading in background
  when exporting MIDI instrument mappings to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Implemented an option to change the socket read timeout
  (choose Edit/Preferences, then click the `Backend' tab)
* Updated LscpTree
* Fantasia: Added option to hide the active stream/voice count statistic
  in the sampler channel's small view
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: `Turn off animation effects' checkbox moved to the `View' tab

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1767 * Copyright (C) 2005-2008 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;
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 1688 /**
95 iliev 1767 * Property which specifies whether the MIDI instrument maps
96     * should be included in the session script.
97     */
98     public final static String EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT = "exportMidiMapsToSessionScript";
99    
100     /**
101     * Property which specifies whether to set the MIDI instrument loading
102     * in background when exporting MIDI instrument maps to LSCP script.
103     */
104     public final static String LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND = "loadMidiInstrumentsInBackground";
105    
106     /**
107 iliev 1688 * Property which specifies whether the user should manually select a server to connect on startup.
108     */
109     public final static String MANUAL_SERVER_SELECT_ON_STARTUP = "manualServerSelectOnStartup";
110 iliev 1540
111 iliev 1688 /**
112     * Integer property which provides the index of the server to connect on startup.
113     */
114     public final static String SERVER_INDEX = "serverIndex";
115    
116 iliev 1767 /**
117     * Property specifying the MIDI bank numbering, whether
118     * the index of the first MIDI bank is 0 or 1 (zero-based or one-based).
119     */
120     public final static String FIRST_MIDI_BANK_NUMBER = "firstMidiBankNumber";
121 iliev 1688
122 iliev 1767 /**
123     * Property specifying the MIDI program numbering, whether
124     * the index of the first MIDI program is 0 or 1 (zero-based or one-based).
125     */
126     public final static String FIRST_MIDI_PROGRAM_NUMBER = "firstMidiProgramNumber";
127    
128     /** Property representing the socket read timeout (in seconds). */
129     public final static String SOCKET_READ_TIMEOUT = "socketReadTimeout";
130    
131    
132 iliev 1286 private final String pathName;
133     private final Preferences userPrefs;
134    
135     /**
136     * Creates a new instance of <code>JSPrefs</code>.
137     * @param pathName The path name of the preferences node.
138     */
139     public
140     JSPrefs(String pathName) {
141     super(new Object());
142    
143     this.pathName = pathName;
144     userPrefs = Preferences.userRoot().node(pathName);
145     }
146    
147     private Preferences
148     user() { return userPrefs; }
149    
150     /**
151     * Gets a string property.
152     * @param name The name of the property.
153     * @return The value of the specified property.
154     * If the property is not set, the return value is <code>null</code>.
155     * @see #getDefaultStringValue
156     */
157     public String
158     getStringProperty(String name) {
159     return getStringProperty(name, getDefaultStringValue(name));
160     }
161    
162     /**
163     * Gets a string property.
164     * @param name The name of the property.
165     * @param defaultValue The value to return if the property is not set.
166     * @return The value of the specified property.
167     */
168     public String
169     getStringProperty(String name, String defaultValue) {
170     return user().get(name, defaultValue);
171     }
172    
173     /**
174 iliev 1308 * Sets a string property.
175 iliev 1286 * @param name The name of the property.
176 iliev 1308 * @param s The new value for the specified property.
177 iliev 1286 */
178     public void
179     setStringProperty(String name, String s) {
180     String oldValue = getStringProperty(name);
181    
182     if(s == null) user().remove(name);
183     else user().put(name, s);
184    
185     firePropertyChange(name, oldValue, s);
186     }
187    
188     /**
189     * Gets the default value for the specified property.
190     * The default value is used when the property is not set.
191     * Override this method to provide custom default values for specific properties.
192 iliev 1327 * @param name The name of the property whose default value should be obtained.
193 iliev 1286 * @return <code>null</code>
194     * @see #getStringProperty(String name)
195     */
196     public String
197     getDefaultStringValue(String name) { return null; }
198    
199     /**
200 iliev 1308 * Gets a string list property.
201     * @param name The name of the property.
202     * @return The value of the specified property.
203     * If the property is not set, the return value is an empty array.
204     * @see #getDefaultStringListValue
205     */
206     public String[]
207     getStringListProperty(String name) {
208     return getStringListProperty(name, getDefaultStringListValue(name));
209     }
210    
211     /**
212     * Gets a string list property.
213     * @param name The name of the property.
214     * @param defaultValue The value to return if the property is not set.
215     * @return The value of the specified property.
216     */
217     public String[]
218     getStringListProperty(String name, String[] defaultValue) {
219     String s = user().get(name, null);
220     if(s == null) return defaultValue;
221     if(s.length() == 0) return new String[0];
222    
223     BufferedReader br = new BufferedReader(new StringReader(s));
224     Vector<String> v = new Vector();
225    
226     try {
227     s = br.readLine();
228     while(s != null) {
229     v.add(s);
230     s = br.readLine();
231     }
232     } catch(Exception x) {
233     x.printStackTrace();
234     }
235    
236     return v.toArray(new String[v.size()]);
237     }
238    
239     /**
240     * Sets a string list property.
241     * Note that the string elements may not contain new lines.
242     * @param name The name of the property.
243     * @param list The new value for the specified property.
244     */
245     public void
246     setStringListProperty(String name, String[] list) {
247     String[] oldValue = getStringListProperty(name);
248    
249     if(list == null) user().remove(name);
250     else {
251     StringBuffer sb = new StringBuffer();
252     for(String s : list) sb.append(s).append("\n");
253     user().put(name, sb.toString());
254     }
255    
256     firePropertyChange(name, oldValue, list);
257     }
258    
259     /**
260     * Gets the default value for the specified property.
261     * The default value is used when the property is not set.
262     * Override this method to provide custom default values for specific properties.
263 iliev 1327 * @param name The name of the property whose default value should be obtained.
264 iliev 1308 * @return An empty array.
265     * @see #getStringListProperty(String name)
266     */
267     public String[]
268     getDefaultStringListValue(String name) { return new String[0]; }
269    
270     /**
271 iliev 1286 * Gets an integer property.
272     * @param name The name of the property.
273     * @return The value of the specified property.
274     * @see #getDefaultIntValue
275     */
276     public int
277     getIntProperty(String name) {
278     return getIntProperty(name, getDefaultIntValue(name));
279     }
280    
281     /**
282     * Gets an integer property.
283     * @param name The name of the property.
284     * @param defaultValue The value to return if the property is not set.
285     * @return The value of the specified property.
286     */
287     public int
288     getIntProperty(String name, int defaultValue) {
289     return user().getInt(name, defaultValue);
290     }
291    
292     /**
293     * Gets the default value for the specified property.
294     * The default value is used when the property is not set.
295     * Override this method to provide custom default values for specific properties.
296 iliev 1327 * @param name The name of the property whose default value should be obtained.
297 iliev 1286 * @return <code>0</code>
298     * @see #getIntProperty(String name)
299     */
300     public int
301 iliev 1767 getDefaultIntValue(String name) {
302     if(name == SOCKET_READ_TIMEOUT) return 90;
303     if(name == FIRST_MIDI_BANK_NUMBER) return 1;
304     if(name == FIRST_MIDI_PROGRAM_NUMBER) return 1;
305     return 0;
306     }
307 iliev 1286
308     /**
309     * Sets an integer property.
310     * @param name The name of the property.
311     * @param i The new value for the specified property.
312     */
313     public void
314     setIntProperty(String name, int i) {
315     int oldValue = getIntProperty(name);
316     user().putInt(name, i);
317     firePropertyChange(name, oldValue, i);
318     }
319    
320    
321     /**
322     * Gets a boolean property.
323     * @param name The name of the property.
324     * @return The value of the specified property.
325     * @see #getDefaultBoolValue
326     */
327     public boolean
328     getBoolProperty(String name) {
329     return getBoolProperty(name, getDefaultBoolValue(name));
330     }
331     /**
332     * Gets a boolean property.
333     * @param name The name of the property.
334     * @param defaultValue The value to return if the property is not set.
335     * @return The value of the specified property.
336     */
337     public boolean
338     getBoolProperty(String name, boolean defaultValue) {
339     return user().getBoolean(name, defaultValue);
340     }
341    
342     /**
343     * Sets a boolean property.
344     * @param name The name of the property.
345     * @param b The new value for the specified property.
346     */
347     public void
348     setBoolProperty(String name, boolean b) {
349     boolean oldValue = getBoolProperty(name);
350     user().putBoolean(name, b);
351     firePropertyChange(name, oldValue, b);
352     }
353    
354     /**
355     * Gets the default value for the specified property.
356     * The default value is used when the property is not set.
357     * Override this method to provide custom default values for specific properties.
358 iliev 1327 * @param name The name of the property whose default value should be obtained.
359 iliev 1286 * @see #getBoolProperty(String name)
360     */
361     public boolean
362 iliev 1540 getDefaultBoolValue(String name) {
363     if(name == VOL_MEASUREMENT_UNIT_DECIBEL) return true;
364 iliev 1767 if(name == EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT) return true;
365     if(name == LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND) return true;
366 iliev 1540 return false;
367     }
368 iliev 1286 }

  ViewVC Help
Powered by ViewVC