001    /* Floating point control
002       Copyright (C) 2005 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.sound.sampled;
040    
041    /** @since 1.3 */
042    public abstract class FloatControl extends Control
043    {
044      /**
045       * An instance of this class describes a particular floating point control.
046       * @since 1.3
047         */
048      public static class Type extends Control.Type
049      {
050        /** Auxiliary return gain.  */
051        public static final Type AUX_RETURN = new Type("AUX return");
052    
053        /** Auxiliary send gain.  */
054        public static final Type AUX_SEND = new Type("AUX send");
055    
056        /** Balance.  */
057        public static final Type BALANCE = new Type("Balance");
058    
059        /** Master gain control.  */
060        public static final Type MASTER_GAIN = new Type("Master gain");
061    
062        /** Control for panning.  */
063        public static final Type PAN = new Type("Pan");
064    
065        /** Post-reverb gain.  */
066        public static final Type REVERB_RETURN = new Type("Reverb return");
067    
068        /** Pre-reverb gain.  */
069        public static final Type REVERB_SEND = new Type("Reverb send");
070    
071        /** Control the sample rate.  */
072        public static final Type SAMPLE_RATE = new Type("Sample rate");
073    
074        /** Volume control.  */
075        public static final Type VOLUME = new Type("Volume");
076    
077        /**
078         * Create a new type given its name.
079         * @param name the name of the type
080         */
081        protected Type(String name)
082        {
083          super(name);
084        }
085      }
086    
087      private float minimum;
088      private float maximum;
089      private float precision;
090      private int updatePeriod;
091      private float value;
092      private String units;
093      private String minLabel;
094      private String maxLabel;
095      private String midLabel;
096    
097      /**
098       * Create a new FloatControl given its type and various parameters.
099       * The minimum, maximum, and midpoint labels will all be the empty string.
100       *
101       * @param type the type
102       * @param min the minimum valuee
103       * @param max the maximum value
104       * @param prec the precision
105       * @param update the update period
106       * @param init the initial value
107       * @param units the description of the units
108       */
109      protected FloatControl(Type type, float min, float max, float prec,
110                             int update, float init, String units)
111      {
112        super(type);
113        this.minimum = min;
114        this.maximum = max;
115        this.precision = prec;
116        this.updatePeriod = update;
117        this.value = init;
118        this.units = units;
119        this.minLabel = "";
120        this.maxLabel = "";
121        this.midLabel = "";
122      }
123    
124      /**
125       * Create a new FloatControl given its type and various parameters.
126       *
127       * @param type the type
128       * @param min the minimum valuee
129       * @param max the maximum value
130       * @param prec the precision
131       * @param update the update period
132       * @param init the initial value
133       * @param units the description of the units
134       * @param minLabel the label for the minimum value
135       * @param midLabel the label for the midpoint
136       * @param maxLabel the label for the maximum value
137       */
138      protected FloatControl(Type type, float min, float max, float prec,
139                             int update, float init, String units,
140                             String minLabel, String midLabel, String maxLabel)
141      {
142        super(type);
143        this.minimum = min;
144        this.maximum = max;
145        this.precision = prec;
146        this.updatePeriod = update;
147        this.value = init;
148        this.units = units;
149        this.minLabel = minLabel;
150        this.maxLabel = maxLabel;
151        this.midLabel = midLabel;
152      }
153    
154      /**
155       * Return the maximum value of this control.
156       */
157      public float getMaximum()
158      {
159        return maximum;
160      }
161    
162      /**
163       * Return the label for the minimum value of this control.
164       */
165      public String getMaxLabel()
166      {
167        return maxLabel;
168      }
169    
170      /**
171       * Return the label for the midpoint of this control.
172       */
173      public String getMidLabel()
174      {
175        return midLabel;
176      }
177    
178      /**
179       * Return the minimum value of this control.
180       */
181      public float getMinimum()
182      {
183        return minimum;
184      }
185    
186      /**
187       * Return the label for the minimum value of this control.
188       */
189      public String getMinLabel()
190      {
191        return minLabel;
192      }
193    
194      /**
195       * Return the precision of this control.
196       */
197      public float getPrecision()
198      {
199        return precision;
200      }
201    
202      /**
203       * Return the name of the units for this control.
204       */
205      public String getUnits()
206      {
207        return units;
208      }
209    
210      /**
211       * Return the update period of this control.
212       */
213      public int getUpdatePeriod()
214      {
215        return updatePeriod;
216      }
217    
218      /**
219       * Return the current value of this control.
220       */
221      public float getValue()
222      {
223        return value;
224      }
225    
226      /**
227       * Set the new value of this control.
228       * @param value the new value
229       * @throws IllegalArgumentException if the new value is greater than the
230       * maximum or less than the minimum.
231       */
232      public void setValue(float value)
233      {
234        if (value < minimum || value > maximum)
235          throw new IllegalArgumentException("value out of range");
236        this.value = value;
237      }
238    
239      /**
240       * This tells the control to start at the starting value
241       * and to shift its value incrementally to the final value
242       * over the given time interval, specified in microseconds.
243       * The default implementation does not do this, but instead
244       * simply sets the value to the final value immediately.
245       *
246       * @param from the starting value
247       * @param to the final value
248       * @param ms the number of microseconds
249       */
250      public void shift(float from, float to, int ms)
251      {
252        if (from < minimum || from > maximum
253            || to < minimum || to > maximum
254            || ms < 0)
255          throw new IllegalArgumentException("argument out of range");
256        // The default just sets the value to TO.
257        this.value = to;
258      }
259    
260      /**
261       * Return a string describing this control.
262       */
263      public String toString()
264      {
265        return super.toString() + ": " + value;
266      }
267    }