Source for javax.sound.sampled.FloatControl

   1: /* Floating point control
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath 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, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.sound.sampled;
  40: 
  41: /** @since 1.3 */
  42: public abstract class FloatControl extends Control
  43: {
  44:   /**
  45:    * An instance of this class describes a particular floating point control.
  46:    * @since 1.3
  47:      */
  48:   public static class Type extends Control.Type
  49:   {
  50:     /** Auxiliary return gain.  */
  51:     public static final Type AUX_RETURN = new Type("AUX return");
  52: 
  53:     /** Auxiliary send gain.  */
  54:     public static final Type AUX_SEND = new Type("AUX send");
  55: 
  56:     /** Balance.  */
  57:     public static final Type BALANCE = new Type("Balance");
  58: 
  59:     /** Master gain control.  */
  60:     public static final Type MASTER_GAIN = new Type("Master gain");
  61: 
  62:     /** Control for panning.  */
  63:     public static final Type PAN = new Type("Pan");
  64: 
  65:     /** Post-reverb gain.  */
  66:     public static final Type REVERB_RETURN = new Type("Reverb return");
  67: 
  68:     /** Pre-reverb gain.  */
  69:     public static final Type REVERB_SEND = new Type("Reverb send");
  70: 
  71:     /** Control the sample rate.  */
  72:     public static final Type SAMPLE_RATE = new Type("Sample rate");
  73: 
  74:     /** Volume control.  */
  75:     public static final Type VOLUME = new Type("Volume");
  76: 
  77:     /**
  78:      * Create a new type given its name.
  79:      * @param name the name of the type
  80:      */
  81:     protected Type(String name)
  82:     {
  83:       super(name);
  84:     }
  85:   }
  86: 
  87:   private float minimum;
  88:   private float maximum;
  89:   private float precision;
  90:   private int updatePeriod;
  91:   private float value;
  92:   private String units;
  93:   private String minLabel;
  94:   private String maxLabel;
  95:   private String midLabel;
  96: 
  97:   /**
  98:    * Create a new FloatControl given its type and various parameters.
  99:    * 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: }