1 7 8 package javax.sound.sampled; 9 10 37 public abstract class FloatControl extends Control { 38 39 40 42 43 45 48 private float minimum; 49 50 53 private float maximum; 54 55 58 private float precision; 59 60 64 private int updatePeriod; 65 66 67 71 private final String units; 72 73 76 private final String minLabel; 77 78 81 private final String maxLabel; 82 83 86 private final String midLabel; 87 88 89 91 94 private float value; 95 96 97 98 100 101 118 protected FloatControl(Type type, float minimum, float maximum, 119 float precision, int updatePeriod, float initialValue, 120 String units, String minLabel, String midLabel, String maxLabel) { 121 122 super(type); 123 124 this.minimum = minimum; 125 this.maximum = maximum; 126 127 this.precision = precision; 128 this.updatePeriod = updatePeriod; 129 this.value = initialValue; 130 131 this.units = units; 132 this.minLabel = ( (minLabel == null) ? "" : minLabel); 133 this.midLabel = ( (midLabel == null) ? "" : midLabel); 134 this.maxLabel = ( (maxLabel == null) ? "" : maxLabel); 135 } 136 137 138 154 protected FloatControl(Type type, float minimum, float maximum, 155 float precision, int updatePeriod, float initialValue, String units) { 156 this(type, minimum, maximum, precision, updatePeriod, initialValue, units, "", "", ""); 157 } 158 159 160 161 163 164 175 public void setValue(float newValue) { 176 177 if (newValue > maximum) { 178 throw new IllegalArgumentException ("Requested value " + newValue + " exceeds allowable maximum value " + maximum + "."); 179 } 180 181 if (newValue < minimum) { 182 throw new IllegalArgumentException ("Requested value " + newValue + " smaller than allowable minimum value " + minimum + "."); 183 } 184 185 value = newValue; 186 } 187 188 189 193 public float getValue() { 194 return value; 195 } 196 197 198 202 public float getMaximum() { 203 return maximum; 204 } 205 206 207 211 public float getMinimum() { 212 return minimum; 213 } 214 215 216 221 public String getUnits() { 222 return units; 223 } 224 225 226 230 public String getMinLabel() { 231 return minLabel; 232 } 233 234 235 239 public String getMidLabel() { 240 return midLabel; 241 } 242 243 244 248 public String getMaxLabel() { 249 return maxLabel; 250 } 251 252 253 260 public float getPrecision() { 261 return precision; 262 } 263 264 265 275 public int getUpdatePeriod() { 276 return updatePeriod; 277 } 278 279 280 294 public void shift(float from, float to, int microseconds) { 295 setValue(to); 296 } 297 298 299 301 302 306 public String toString() { 307 return new String (getType() + " with current value: " + getValue() + " " + units + 308 " (range: " + minimum + " - " + maximum + ")"); 309 } 310 311 312 314 315 324 public static class Type extends Control.Type { 325 326 327 329 330 332 368 public static final Type MASTER_GAIN = new Type("Master Gain"); 369 370 376 public static final Type AUX_SEND = new Type("AUX Send"); 377 378 384 public static final Type AUX_RETURN = new Type("AUX Return"); 385 386 395 public static final Type REVERB_SEND = new Type("Reverb Send"); 396 397 405 public static final Type REVERB_RETURN = new Type("Reverb Return"); 406 407 408 410 413 416 public static final Type VOLUME = new Type("Volume"); 417 418 419 421 430 public static final Type PAN = new Type("Pan"); 431 432 433 435 442 public static final Type BALANCE = new Type("Balance"); 443 444 445 447 463 public static final Type SAMPLE_RATE = new Type("Sample Rate"); 464 465 466 468 472 protected Type(String name) { 473 super(name); 474 } 475 476 } 478 } | Popular Tags |