Home | History | Annotate | Download | only in sampled
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package javax.sound.sampled;
     19 
     20 import org.apache.harmony.sound.internal.nls.Messages;
     21 
     22 public abstract class FloatControl extends Control {
     23 
     24     public static class Type extends Control.Type {
     25         public static final Type MASTER_GAIN = new Type("Master Gain"); //$NON-NLS-1$
     26 
     27         public static final Type AUX_SEND = new Type("AUX Send"); //$NON-NLS-1$
     28 
     29         public static final Type AUX_RETURN = new Type("AUX Return"); //$NON-NLS-1$
     30 
     31         public static final Type REVERB_SEND = new Type("Reverb Send"); //$NON-NLS-1$
     32 
     33         public static final Type REVERB_RETURN = new Type("Reverb Return"); //$NON-NLS-1$
     34 
     35         public static final Type VOLUME = new Type("Volume"); //$NON-NLS-1$
     36 
     37         public static final Type PAN = new Type("Pan"); //$NON-NLS-1$
     38 
     39         public static final Type BALANCE = new Type("Balance"); //$NON-NLS-1$
     40 
     41         public static final Type SAMPLE_RATE = new Type("Sample Rate"); //$NON-NLS-1$
     42 
     43         protected Type(String name) {
     44             super(name);
     45         }
     46     }
     47 
     48     private float value;
     49 
     50     private float maximum;
     51 
     52     private float minimum;
     53 
     54     private String units;
     55 
     56     private String minLabel;
     57 
     58     private String midLabel;
     59 
     60     private String maxLabel;
     61 
     62     private float precision;
     63 
     64     private int updatePeriod;
     65 
     66     protected FloatControl(FloatControl.Type type, float minimum,
     67             float maximum, float precision, int updatePeriod,
     68             float initialValue, String units, String minLabel, String midLabel,
     69             String maxLabel) {
     70         super(type);
     71         this.maximum = maximum;
     72         this.maxLabel = maxLabel;
     73         this.midLabel = midLabel;
     74         this.minLabel = minLabel;
     75         this.minimum = minimum;
     76         this.precision = precision;
     77         this.units = units;
     78         this.updatePeriod = updatePeriod;
     79         this.value = initialValue;
     80     }
     81 
     82     protected FloatControl(FloatControl.Type type, float minimum,
     83             float maximum, float precision, int updatePeriod,
     84             float initialValue, String units) {
     85         this(type, minimum, maximum, precision, updatePeriod, initialValue,
     86                 units, "", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     87     }
     88 
     89     public void setValue(float newValue) {
     90         if (newValue > maximum || newValue < minimum) {
     91             // sound.0F=value does not fall within the allowable range
     92             throw new IllegalArgumentException(Messages.getString("sound.0F")); //$NON-NLS-1$
     93         }
     94         this.value = newValue;
     95     }
     96 
     97     public float getValue() {
     98         return this.value;
     99     }
    100 
    101     public float getMaximum() {
    102         return this.maximum;
    103     }
    104 
    105     public float getMinimum() {
    106         return this.minimum;
    107     }
    108 
    109     public String getUnits() {
    110         return this.units;
    111     }
    112 
    113     public String getMinLabel() {
    114         return this.minLabel;
    115     }
    116 
    117     public String getMidLabel() {
    118         return this.midLabel;
    119     }
    120 
    121     public String getMaxLabel() {
    122         return this.maxLabel;
    123     }
    124 
    125     public float getPrecision() {
    126         return this.precision;
    127     }
    128 
    129     public int getUpdatePeriod() {
    130         return this.updatePeriod;
    131     }
    132 
    133     public void shift(float from, float to, int microseconds) {
    134         setValue(to);
    135     }
    136 
    137     public String toString() {
    138         return getType() + " with current value: "+ value + " " + units  //$NON-NLS-1$ //$NON-NLS-2$
    139             + " (range: " + minimum + " - " + maximum + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    140     }
    141 
    142 }
    143