/[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 1818 - (hide annotations) (download)
Wed Dec 24 17:29:47 2008 UTC (15 years, 5 months ago) by iliev
File size: 12798 byte(s)
* Added support for controlling the global sampler-wide limit of
  maximum voices and disk streams
  (choose Edit/Preferences, then click the `General' tab)
* Fantasia: store the view configuration of audio/MIDI devices and sampler
  channels in the LSCP script when exporting sampler configuration
* Fantasia: Implemented multiple sampler channels' selection
* Fantasia: Added option to move sampler channels up and down
  in the channels list
* Fantasia: Added option to move sampler channels
  to another channels panels

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 1818 /** Property representing the global sampler-wide limit of maximum voices. */
39     public final static String GLOBAL_VOICE_LIMIT = "globalVoiceLimit";
40    
41     /** Property representing the global sampler-wide limit of maximum disk streams. */
42     public final static String GLOBAL_STREAM_LIMIT = "globalStreamLimit";
43    
44 iliev 1313 /**
45     * Property which specifies whether to apply default
46     * actions to newly created sampler channels.
47     */
48     public final static String USE_CHANNEL_DEFAULTS = "samplerChannel.useDefaultActions";
49    
50     /**
51     * Property representing the default engine to be used when
52     * new sampler channel is created. The action is taken only if
53     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
54     */
55     public final static String DEFAULT_ENGINE = "defaultEngine";
56    
57     /**
58     * Property representing the default MIDI input to be used when
59     * new sampler channel is created. The action is taken only if
60     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
61     */
62     public final static String DEFAULT_MIDI_INPUT = "defaultMidiInput";
63    
64     /**
65     * Property representing the default audio output to be used when
66     * new sampler channel is created. The action is taken only if
67     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
68     */
69     public final static String DEFAULT_AUDIO_OUTPUT = "defaultAudioOutput";
70    
71 iliev 1315 /**
72 iliev 1334 * Property representing the default MIDI instrument map to be used when
73     * new sampler channel is created. The action is taken only if
74     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
75     */
76     public final static String DEFAULT_MIDI_INSTRUMENT_MAP = "defaultMidiInstrumentMap";
77    
78     /**
79     * Property representing the default channel volume when
80     * new sampler channel is created. The action is taken only if
81     * <code>USE_CHANNEL_DEFAULTS</code> is <code>true</code>.
82     */
83     public final static String DEFAULT_CHANNEL_VOLUME = "defaultChannelVolume";
84    
85     /**
86 iliev 1315 * Property representing the default MIDI input driver to be used
87     * when creating new MIDI input device.
88     */
89     public final static String DEFAULT_MIDI_DRIVER = "defaultMidiDriver";
90 iliev 1313
91 iliev 1315 /**
92     * Property representing the default audio output driver to be used
93     * when creating new audio output device.
94     */
95     public final static String DEFAULT_AUDIO_DRIVER = "defaultAudioDriver";
96    
97 iliev 1540 /** Property which specifies whether the volume values should be shown in decibels. */
98     public final static String VOL_MEASUREMENT_UNIT_DECIBEL = "volMeasurementUnitDecibel";
99 iliev 1315
100 iliev 1688 /**
101 iliev 1767 * Property which specifies whether the MIDI instrument maps
102     * should be included in the session script.
103     */
104     public final static String EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT = "exportMidiMapsToSessionScript";
105    
106     /**
107     * Property which specifies whether to set the MIDI instrument loading
108     * in background when exporting MIDI instrument maps to LSCP script.
109     */
110     public final static String LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND = "loadMidiInstrumentsInBackground";
111    
112     /**
113 iliev 1688 * Property which specifies whether the user should manually select a server to connect on startup.
114     */
115     public final static String MANUAL_SERVER_SELECT_ON_STARTUP = "manualServerSelectOnStartup";
116 iliev 1540
117 iliev 1688 /**
118 iliev 1786 * Property which specifies whether the backend should be launched by jsampler
119     * if it is not yet started, when trying to connect locally - 127.0.0.1 or localhost.
120     */
121     public final static String LAUNCH_BACKEND_LOCALLY = "launchBackednLocally";
122    
123     /**
124     * Property which specifies the command to be used to start the backend.
125     */
126     public final static String BACKEND_LAUNCH_COMMAND = "backendLaunchCommand";
127    
128     /**
129     * Property which specifies whether the backend should be launched by jsampler
130     * if it is not yet started, when trying to connect locally - 127.0.0.1 or localhost.
131     */
132     public final static String BACKEND_LAUNCH_DELAY = "backendLaunchDelay";
133    
134     /**
135 iliev 1688 * Integer property which provides the index of the server to connect on startup.
136     */
137     public final static String SERVER_INDEX = "serverIndex";
138    
139 iliev 1767 /**
140     * Property specifying the MIDI bank numbering, whether
141     * the index of the first MIDI bank is 0 or 1 (zero-based or one-based).
142     */
143     public final static String FIRST_MIDI_BANK_NUMBER = "firstMidiBankNumber";
144 iliev 1688
145 iliev 1767 /**
146     * Property specifying the MIDI program numbering, whether
147     * the index of the first MIDI program is 0 or 1 (zero-based or one-based).
148     */
149     public final static String FIRST_MIDI_PROGRAM_NUMBER = "firstMidiProgramNumber";
150    
151     /** Property representing the socket read timeout (in seconds). */
152     public final static String SOCKET_READ_TIMEOUT = "socketReadTimeout";
153    
154    
155 iliev 1286 private final String pathName;
156     private final Preferences userPrefs;
157    
158     /**
159     * Creates a new instance of <code>JSPrefs</code>.
160     * @param pathName The path name of the preferences node.
161     */
162     public
163     JSPrefs(String pathName) {
164     super(new Object());
165    
166     this.pathName = pathName;
167     userPrefs = Preferences.userRoot().node(pathName);
168     }
169    
170     private Preferences
171     user() { return userPrefs; }
172    
173     /**
174     * Gets a string property.
175     * @param name The name of the property.
176     * @return The value of the specified property.
177     * If the property is not set, the return value is <code>null</code>.
178     * @see #getDefaultStringValue
179     */
180     public String
181     getStringProperty(String name) {
182     return getStringProperty(name, getDefaultStringValue(name));
183     }
184    
185     /**
186     * Gets a string property.
187     * @param name The name of the property.
188     * @param defaultValue The value to return if the property is not set.
189     * @return The value of the specified property.
190     */
191     public String
192     getStringProperty(String name, String defaultValue) {
193     return user().get(name, defaultValue);
194     }
195    
196     /**
197 iliev 1308 * Sets a string property.
198 iliev 1286 * @param name The name of the property.
199 iliev 1308 * @param s The new value for the specified property.
200 iliev 1286 */
201     public void
202     setStringProperty(String name, String s) {
203     String oldValue = getStringProperty(name);
204    
205     if(s == null) user().remove(name);
206     else user().put(name, s);
207    
208     firePropertyChange(name, oldValue, s);
209     }
210    
211     /**
212     * Gets the default value for the specified property.
213     * The default value is used when the property is not set.
214     * Override this method to provide custom default values for specific properties.
215 iliev 1327 * @param name The name of the property whose default value should be obtained.
216 iliev 1286 * @return <code>null</code>
217     * @see #getStringProperty(String name)
218     */
219     public String
220 iliev 1786 getDefaultStringValue(String name) {
221     if(BACKEND_LAUNCH_COMMAND.equals(name)) return "linuxsampler";
222     return null;
223     }
224 iliev 1286
225     /**
226 iliev 1308 * Gets a string list property.
227     * @param name The name of the property.
228     * @return The value of the specified property.
229     * If the property is not set, the return value is an empty array.
230     * @see #getDefaultStringListValue
231     */
232     public String[]
233     getStringListProperty(String name) {
234     return getStringListProperty(name, getDefaultStringListValue(name));
235     }
236    
237     /**
238     * Gets a string list property.
239     * @param name The name of the property.
240     * @param defaultValue The value to return if the property is not set.
241     * @return The value of the specified property.
242     */
243     public String[]
244     getStringListProperty(String name, String[] defaultValue) {
245     String s = user().get(name, null);
246     if(s == null) return defaultValue;
247     if(s.length() == 0) return new String[0];
248    
249     BufferedReader br = new BufferedReader(new StringReader(s));
250     Vector<String> v = new Vector();
251    
252     try {
253     s = br.readLine();
254     while(s != null) {
255     v.add(s);
256     s = br.readLine();
257     }
258     } catch(Exception x) {
259     x.printStackTrace();
260     }
261    
262     return v.toArray(new String[v.size()]);
263     }
264    
265     /**
266     * Sets a string list property.
267     * Note that the string elements may not contain new lines.
268     * @param name The name of the property.
269     * @param list The new value for the specified property.
270     */
271     public void
272     setStringListProperty(String name, String[] list) {
273     String[] oldValue = getStringListProperty(name);
274    
275     if(list == null) user().remove(name);
276     else {
277     StringBuffer sb = new StringBuffer();
278     for(String s : list) sb.append(s).append("\n");
279     user().put(name, sb.toString());
280     }
281    
282     firePropertyChange(name, oldValue, list);
283     }
284    
285     /**
286     * Gets the default value for the specified property.
287     * The default value is used when the property is not set.
288     * Override this method to provide custom default values for specific properties.
289 iliev 1327 * @param name The name of the property whose default value should be obtained.
290 iliev 1308 * @return An empty array.
291     * @see #getStringListProperty(String name)
292     */
293     public String[]
294     getDefaultStringListValue(String name) { return new String[0]; }
295    
296     /**
297 iliev 1286 * Gets an integer property.
298     * @param name The name of the property.
299     * @return The value of the specified property.
300     * @see #getDefaultIntValue
301     */
302     public int
303     getIntProperty(String name) {
304     return getIntProperty(name, getDefaultIntValue(name));
305     }
306    
307     /**
308     * Gets an integer property.
309     * @param name The name of the property.
310     * @param defaultValue The value to return if the property is not set.
311     * @return The value of the specified property.
312     */
313     public int
314     getIntProperty(String name, int defaultValue) {
315     return user().getInt(name, defaultValue);
316     }
317    
318     /**
319     * Gets the default value for the specified property.
320     * The default value is used when the property is not set.
321     * Override this method to provide custom default values for specific properties.
322 iliev 1327 * @param name The name of the property whose default value should be obtained.
323 iliev 1286 * @return <code>0</code>
324     * @see #getIntProperty(String name)
325     */
326     public int
327 iliev 1767 getDefaultIntValue(String name) {
328 iliev 1818 if(GLOBAL_VOICE_LIMIT.equals(name)) return 64;
329     if(GLOBAL_STREAM_LIMIT.equals(name)) return 90;
330 iliev 1786 if(SOCKET_READ_TIMEOUT.equals(name)) return 90;
331     if(FIRST_MIDI_BANK_NUMBER.equals(name)) return 1;
332     if(FIRST_MIDI_PROGRAM_NUMBER.equals(name)) return 1;
333     if(BACKEND_LAUNCH_DELAY.equals(name)) return 3;
334 iliev 1767 return 0;
335     }
336 iliev 1286
337     /**
338     * Sets an integer property.
339     * @param name The name of the property.
340     * @param i The new value for the specified property.
341     */
342     public void
343     setIntProperty(String name, int i) {
344     int oldValue = getIntProperty(name);
345     user().putInt(name, i);
346     firePropertyChange(name, oldValue, i);
347     }
348    
349    
350     /**
351     * Gets a boolean property.
352     * @param name The name of the property.
353     * @return The value of the specified property.
354     * @see #getDefaultBoolValue
355     */
356     public boolean
357     getBoolProperty(String name) {
358     return getBoolProperty(name, getDefaultBoolValue(name));
359     }
360     /**
361     * Gets a boolean property.
362     * @param name The name of the property.
363     * @param defaultValue The value to return if the property is not set.
364     * @return The value of the specified property.
365     */
366     public boolean
367     getBoolProperty(String name, boolean defaultValue) {
368     return user().getBoolean(name, defaultValue);
369     }
370    
371     /**
372     * Sets a boolean property.
373     * @param name The name of the property.
374     * @param b The new value for the specified property.
375     */
376     public void
377     setBoolProperty(String name, boolean b) {
378     boolean oldValue = getBoolProperty(name);
379     user().putBoolean(name, b);
380     firePropertyChange(name, oldValue, b);
381     }
382    
383     /**
384     * Gets the default value for the specified property.
385     * The default value is used when the property is not set.
386     * Override this method to provide custom default values for specific properties.
387 iliev 1327 * @param name The name of the property whose default value should be obtained.
388 iliev 1286 * @see #getBoolProperty(String name)
389     */
390     public boolean
391 iliev 1540 getDefaultBoolValue(String name) {
392 iliev 1786 if(VOL_MEASUREMENT_UNIT_DECIBEL.equals(name)) return true;
393     if(EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT.equals(name)) return true;
394     if(LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND.equals(name)) return true;
395     if(LAUNCH_BACKEND_LOCALLY.equals(name)) return true;
396 iliev 1540 return false;
397     }
398 iliev 1286 }

  ViewVC Help
Powered by ViewVC