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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2307 - (show annotations) (download)
Wed Jan 25 11:24:04 2012 UTC (12 years, 2 months ago) by iliev
File size: 17255 byte(s)
* the default MIDI bank numbering is now zero-based

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2011 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
27 import java.io.BufferedReader;
28 import java.io.StringReader;
29
30 import java.util.Vector;
31 import java.util.prefs.Preferences;
32
33 /**
34 *
35 * @author Grigor Iliev
36 */
37 public class JSPrefs extends PropertyChangeSupport {
38 /** 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 /**
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 /**
72 * 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 * 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
91 /**
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 /** Property which specifies whether the volume values should be shown in decibels. */
98 public final static String VOL_MEASUREMENT_UNIT_DECIBEL = "volMeasurementUnitDecibel";
99
100 /**
101 * 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 * 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
117 /**
118 * 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 * Integer property which provides the index of the server to connect on startup.
136 */
137 public final static String SERVER_INDEX = "serverIndex";
138
139 /**
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
145 /**
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 /** Property representing the maximum number of lines to be kept in the command history. */
156 public final static String LS_CONSOLE_HISTSIZE = "LSConsole.historySize";
157
158 /** Property which specifies whether the command history should be saved on exit. */
159 public final static String SAVE_LS_CONSOLE_HISTORY = "LSConsole.saveCommandHistory";
160
161 /** Property representing the background color of the LS Console. */
162 public final static String LS_CONSOLE_BACKGROUND_COLOR = "LSConsole.backgroundColor";
163
164 /** Property representing the text color of the LS Console. */
165 public final static String LS_CONSOLE_TEXT_COLOR = "LSConsole.textColor";
166
167 /** Property representing the notification messages' color of the LS Console. */
168 public final static String LS_CONSOLE_NOTIFY_COLOR = "LSConsole.notifyColor";
169
170 /** Property representing the warning messages' color of the LS Console. */
171 public final static String LS_CONSOLE_WARNING_COLOR = "LSConsole.warningColor";
172
173 /** Property representing the error messages' color of the LS Console. */
174 public final static String LS_CONSOLE_ERROR_COLOR = "LSConsole.errorColor";
175
176 /** Property representing the list of recent LSCP scripts. */
177 public final static String RECENT_LSCP_SCRIPTS = "recentLscpScripts";
178
179 /** Property representing the maximum number of recent LSCP scripts to be stored. */
180 public final static String RECENT_LSCP_SCRIPTS_SIZE = "recentLscpScripts.maxNumber";
181
182 /** Property which specifies whether the LS Console should be shown when script is run. */
183 public final static String SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT = "showLSConsoleWhenRunScript";
184
185 /** Property representing the maximum master volume (in percents). */
186 public final static String MAXIMUM_MASTER_VOLUME = "maximumMasterVolume";
187
188 /** Property representing the maximum channel volume (in percents). */
189 public final static String MAXIMUM_CHANNEL_VOLUME = "maximumChannelVolume";
190
191 /** Property which specifies whether the user should confirm channel removals. */
192 public final static String CONFIRM_CHANNEL_REMOVAL = "confirmChannelRemoval";
193
194 /** Property which specifies whether the user should confirm audio/MIDI device removals. */
195 public final static String CONFIRM_DEVICE_REMOVAL = "confirmDeviceRemoval";
196
197 /** Property which specifies whether the user should confirm quiting. */
198 public final static String CONFIRM_APP_QUIT = "confirmAppQuit";
199
200 /** Property which specifies the sort order in the instruments database frame. */
201 public final static String INSTRUMENTS_DB_FRAME_SORT_ORDER = "instrumentsDbFrameSortOrder";
202
203 /** Property representing the channel view to be used when creating a sampler channel. */
204 public final static String DEFAULT_CHANNEL_VIEW = "defaultChannelView";
205
206 /**
207 * Property which specifies whether a different sampler channel view should be shown
208 * when the mouse cursor is over a sampler channel.
209 */
210 public final static String DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER = "differentChannelViewOnMO";
211
212 /**
213 * Property representing the channel view to be used when
214 * the mouse cursor is over a sampler channel.
215 */
216 public final static String CHANNEL_VIEW_ON_MOUSE_OVER = "channelViewOnMouseOver";
217
218
219 private final String pathName;
220 private final Preferences userPrefs;
221
222 /**
223 * Creates a new instance of <code>JSPrefs</code>.
224 * @param pathName The path name of the preferences node.
225 */
226 public
227 JSPrefs(String pathName) {
228 super(new Object());
229
230 this.pathName = pathName;
231 userPrefs = Preferences.userRoot().node(pathName);
232 }
233
234 private Preferences
235 user() { return userPrefs; }
236
237 /**
238 * Gets a string property.
239 * @param name The name of the property.
240 * @return The value of the specified property.
241 * If the property is not set, the return value is <code>null</code>.
242 * @see #getDefaultStringValue
243 */
244 public String
245 getStringProperty(String name) {
246 return getStringProperty(name, getDefaultStringValue(name));
247 }
248
249 /**
250 * Gets a string property.
251 * @param name The name of the property.
252 * @param defaultValue The value to return if the property is not set.
253 * @return The value of the specified property.
254 */
255 public String
256 getStringProperty(String name, String defaultValue) {
257 return user().get(name, defaultValue);
258 }
259
260 /**
261 * Sets a string property.
262 * @param name The name of the property.
263 * @param s The new value for the specified property.
264 */
265 public void
266 setStringProperty(String name, String s) {
267 String oldValue = getStringProperty(name);
268
269 if(s == null) user().remove(name);
270 else user().put(name, s);
271
272 firePropertyChange(name, oldValue, s);
273 }
274
275 /**
276 * Gets the default value for the specified property.
277 * The default value is used when the property is not set.
278 * Override this method to provide custom default values for specific properties.
279 * @param name The name of the property whose default value should be obtained.
280 * @return <code>null</code>
281 * @see #getStringProperty(String name)
282 */
283 public String
284 getDefaultStringValue(String name) {
285 if(BACKEND_LAUNCH_COMMAND.equals(name)) return "linuxsampler";
286 if(RECENT_LSCP_SCRIPTS.equals(name)) return "";
287 if(DEFAULT_ENGINE.equals(name)) return "GIG";
288 if(DEFAULT_MIDI_INPUT.equals(name)) return "firstDeviceNextChannel";
289 if(DEFAULT_AUDIO_OUTPUT.equals(name)) return "firstDevice";
290 if(DEFAULT_MIDI_DRIVER.equals(name)) return "ALSA";
291 if(DEFAULT_AUDIO_DRIVER.equals(name)) return "ALSA";
292 if(DEFAULT_MIDI_INSTRUMENT_MAP.equals(name)) return "midiInstrumentMap.none";
293
294 return null;
295 }
296
297 /**
298 * Gets a string list property.
299 * @param name The name of the property.
300 * @return The value of the specified property.
301 * If the property is not set, the return value is an empty array.
302 * @see #getDefaultStringListValue
303 */
304 public String[]
305 getStringListProperty(String name) {
306 return getStringListProperty(name, getDefaultStringListValue(name));
307 }
308
309 /**
310 * Gets a string list property.
311 * @param name The name of the property.
312 * @param defaultValue The value to return if the property is not set.
313 * @return The value of the specified property.
314 */
315 public String[]
316 getStringListProperty(String name, String[] defaultValue) {
317 String s = user().get(name, null);
318 if(s == null) return defaultValue;
319 if(s.length() == 0) return new String[0];
320
321 BufferedReader br = new BufferedReader(new StringReader(s));
322 Vector<String> v = new Vector();
323
324 try {
325 s = br.readLine();
326 while(s != null) {
327 v.add(s);
328 s = br.readLine();
329 }
330 } catch(Exception x) {
331 x.printStackTrace();
332 }
333
334 return v.toArray(new String[v.size()]);
335 }
336
337 /**
338 * Sets a string list property.
339 * Note that the string elements may not contain new lines.
340 * @param name The name of the property.
341 * @param list The new value for the specified property.
342 */
343 public void
344 setStringListProperty(String name, String[] list) {
345 String[] oldValue = getStringListProperty(name);
346
347 if(list == null) user().remove(name);
348 else {
349 StringBuffer sb = new StringBuffer();
350 for(String s : list) sb.append(s).append("\n");
351 user().put(name, sb.toString());
352 }
353
354 firePropertyChange(name, oldValue, list);
355 }
356
357 /**
358 * Gets the default value for the specified property.
359 * The default value is used when the property is not set.
360 * Override this method to provide custom default values for specific properties.
361 * @param name The name of the property whose default value should be obtained.
362 * @return An empty array.
363 * @see #getStringListProperty(String name)
364 */
365 public String[]
366 getDefaultStringListValue(String name) { return new String[0]; }
367
368 /**
369 * Gets an integer property.
370 * @param name The name of the property.
371 * @return The value of the specified property.
372 * @see #getDefaultIntValue
373 */
374 public int
375 getIntProperty(String name) {
376 return getIntProperty(name, getDefaultIntValue(name));
377 }
378
379 /**
380 * Gets an integer property.
381 * @param name The name of the property.
382 * @param defaultValue The value to return if the property is not set.
383 * @return The value of the specified property.
384 */
385 public int
386 getIntProperty(String name, int defaultValue) {
387 return user().getInt(name, defaultValue);
388 }
389
390 /**
391 * Gets the default value for the specified property.
392 * The default value is used when the property is not set.
393 * Override this method to provide custom default values for specific properties.
394 * @param name The name of the property whose default value should be obtained.
395 * @return <code>0</code>
396 * @see #getIntProperty(String name)
397 */
398 public int
399 getDefaultIntValue(String name) {
400 if(GLOBAL_VOICE_LIMIT.equals(name)) return 64;
401 if(GLOBAL_STREAM_LIMIT.equals(name)) return 90;
402 if(SOCKET_READ_TIMEOUT.equals(name)) return 90;
403 if(FIRST_MIDI_BANK_NUMBER.equals(name)) return 0;
404 if(FIRST_MIDI_PROGRAM_NUMBER.equals(name)) return 1;
405 if(BACKEND_LAUNCH_DELAY.equals(name)) return 3;
406 if(DEFAULT_CHANNEL_VOLUME.equals(name)) return 100;
407 if(LS_CONSOLE_HISTSIZE.equals(name)) return 1000;
408 if(RECENT_LSCP_SCRIPTS_SIZE.equals(name)) return 7;
409 if(MAXIMUM_MASTER_VOLUME.equals(name)) return 100;
410 if(MAXIMUM_CHANNEL_VOLUME.equals(name)) return 100;
411 if(INSTRUMENTS_DB_FRAME_SORT_ORDER.equals(name)) return 1;
412 if(DEFAULT_CHANNEL_VIEW.equals(name)) return 1;
413 if(CHANNEL_VIEW_ON_MOUSE_OVER.equals(name)) return 1;
414
415 return 0;
416 }
417
418 /**
419 * Sets an integer property.
420 * @param name The name of the property.
421 * @param i The new value for the specified property.
422 */
423 public void
424 setIntProperty(String name, int i) {
425 int oldValue = getIntProperty(name);
426 user().putInt(name, i);
427 firePropertyChange(name, oldValue, i);
428 }
429
430
431 /**
432 * Gets a boolean property.
433 * @param name The name of the property.
434 * @return The value of the specified property.
435 * @see #getDefaultBoolValue
436 */
437 public boolean
438 getBoolProperty(String name) {
439 return getBoolProperty(name, getDefaultBoolValue(name));
440 }
441 /**
442 * Gets a boolean property.
443 * @param name The name of the property.
444 * @param defaultValue The value to return if the property is not set.
445 * @return The value of the specified property.
446 */
447 public boolean
448 getBoolProperty(String name, boolean defaultValue) {
449 return user().getBoolean(name, defaultValue);
450 }
451
452 /**
453 * Sets a boolean property.
454 * @param name The name of the property.
455 * @param b The new value for the specified property.
456 */
457 public void
458 setBoolProperty(String name, boolean b) {
459 boolean oldValue = getBoolProperty(name);
460 user().putBoolean(name, b);
461 firePropertyChange(name, oldValue, b);
462 }
463
464 /**
465 * Gets the default value for the specified property.
466 * The default value is used when the property is not set.
467 * Override this method to provide custom default values for specific properties.
468 * @param name The name of the property whose default value should be obtained.
469 * @see #getBoolProperty(String name)
470 */
471 public boolean
472 getDefaultBoolValue(String name) {
473 if(VOL_MEASUREMENT_UNIT_DECIBEL.equals(name)) return true;
474 if(EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT.equals(name)) return true;
475 if(LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND.equals(name)) return true;
476 if(LAUNCH_BACKEND_LOCALLY.equals(name)) return true;
477 if(DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER.equals(name)) return true;
478 if(CONFIRM_CHANNEL_REMOVAL.equals(name)) return true;
479 if(CONFIRM_DEVICE_REMOVAL.equals(name)) return true;
480 if(CONFIRM_APP_QUIT.equals(name)) return true;
481 if(SAVE_LS_CONSOLE_HISTORY.equals(name)) return true;
482 if(USE_CHANNEL_DEFAULTS.equals(name)) return true;
483 if("nativeFileChoosers".equals(name) && CC.isMacOS()) return true;
484
485 return false;
486 }
487 }

  ViewVC Help
Powered by ViewVC