Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/fluidsynth/api/settings/Setting.java


1   /*
2    * Copyright (C) 2003 Ken Ellinwood.
3    * 
4    * This file is part of FluidGUI.
5    * 
6    * FluidGUI is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  
21  package org.fluidsynth.api.settings;
22  
23  
24  /** Base class for objects which represent a fluidsynth setting.  */
25  public abstract class Setting
26  {
27  
28      private String name;
29      private String value;
30      private String commandLineOption;
31      private String realtime;
32      private String defaultValue;
33      private boolean isRealtime;
34      private Settings settings = null;
35  
36      /** Associate this setting to a Settings instance. */
37      public void setSettings( Settings settings)
38      {
39          this.settings = settings;
40      }
41  
42      /** Set the dirty state of our parent Settings object. */
43      protected void dirty()
44      {
45          if (settings != null) settings.dirty();
46      }
47      
48      /** Merge another setting into this one. */
49      public void merge( Setting other)
50      {
51          
52          if (other.name != null) setName( other.name);
53          if (other.value != null) setValue( other.value);
54          if (other.commandLineOption != null) setCommandLineOption( other.commandLineOption);
55          if (other.defaultValue != null) setDefaultValue( other.defaultValue);
56          if (other.realtime != null) setRealtime( other.realtime);
57      }
58  
59      /** Get the name of this setting. */
60      public String getName()
61      {
62          return name;
63      }
64  
65      /** Set the name of this setting. */
66      public void setName( String name)
67      {
68          this.name = name;
69      }
70  
71      /** Get the default value of this setting. */
72      public String getDefaultValue()
73      {
74          return defaultValue;
75      }
76  
77      /** Set the default value of this setting. */
78      public void setDefaultValue( String defaultValue)
79      {
80          this.defaultValue = defaultValue;
81      }
82  
83      /** Get the current value of this setting. */
84      public String getValue()
85      {
86          return value;
87      }
88  
89      /** Set the current value of this setting. */
90      public void setValue( String value)
91      {
92          this.value = value;
93          dirty();
94      }
95  
96      /** Set the realtime flag of this setting. */
97      public void setRealtime( String realtime)
98      {
99          isRealtime = "yes".equals( realtime);
100         this.realtime = realtime;
101     }
102 
103     /** Get the realtime flag of this setting. */
104     public String getRealtime()
105     {
106         return realtime;
107     }
108 
109     /** Get the realtime flag of this setting. */
110     public boolean isRealtime()
111     {
112         return isRealtime;
113     }
114     
115     /** Set the command line option used to set this setting on the
116      * synth command line.  E.g., the audio.driver setting has a
117      * command line option of "--audio.driver"
118      */
119     public void setCommandLineOption( String option)
120     {
121         this.commandLineOption = option;
122     }
123 
124 
125     /** Set the command line option used to set this setting on the
126      * synth command line.  E.g., the audio.driver setting has a
127      * command line option of "--audio.driver"
128      */
129     public String getCommandLineOption()
130     {
131         return commandLineOption;
132     }
133 
134     /** Return the command line argument used to communicate the
135      * current value of this setting to fluidsynth.  E.g., when the
136      * value of the audio.driver setting is "alsa", this method
137      * returns --audio-driver=alsa.
138      */
139     public String commandLineArg()
140     {
141         if (commandLineOption != null) return commandLineOption + '=' + getValue();
142         else return "-o " + getName() + '=' + getValue();
143     }
144 
145     /** Returns true of the current value is different than the default value. */
146     boolean isUserModified()
147     {
148         // Ignore settings with null values
149         if (getValue() == null) return false;
150             
151         // Ignore settings with defaultValue == value
152         if (getDefaultValue() != null) return !getDefaultValue().equals( getValue());
153 
154         return true;
155 
156     }
157     
158     /** Returns an object which represents the current value as a java
159      * object.  For example, a BooleanSetting.objectGet() returns a
160      * java.lang.Boolean, IntegerSetting.objectGet() returns a
161      * java.lang.Integer, etc.
162      */
163     public abstract Object objectGet();
164 
165     /** Given a java object, set the value of this option. */
166     public abstract void objectSet( Object value) throws IllegalArgumentException;
167 
168     /** Validates the value and if valid, returns it unaltered.  Throws
169      *  IllegalArgumentException if the object is not valid.
170      */
171     public abstract Object validate( Object value) throws IllegalArgumentException;
172 }
173 
174 
175