Example #1
0
 public FloatControlBoundedRangeModel(FloatControl control) {
   this.control = control;
   float range = 100;
   float steps = range / 100;
   factor = range / steps;
   int min = (int) (control.getMinimum() * factor);
   int max = (int) (control.getMaximum() * factor);
   int value = (int) (control.getValue() * factor);
   setRangeProperties(value, 0, min, max, false);
 }
Example #2
0
  public boolean play() {

    try {
      if (playState != STOPPED) playStop();

      if (audioBytes == null) return false;

      DataLine.Info info = new DataLine.Info(Clip.class, format);

      clip = (Clip) AudioSystem.getLine(info);
      clip.addLineListener(new ClipListener());

      long clipStart = (long) (audioBytes.length * getStartTime() / (getDuration() * 1000.0));
      long clipEnd = (long) (audioBytes.length * getEndTime() / (getDuration() * 1000.0));
      if ((clipEnd - clipStart) > MAX_CLIP_LENGTH) clipEnd = clipStart + MAX_CLIP_LENGTH;
      byte[] clipBytes = new byte[(int) (clipEnd - clipStart)];
      System.arraycopy(audioBytes, (int) clipStart, clipBytes, 0, clipBytes.length);
      clip.open(format, clipBytes, 0, clipBytes.length);

      FloatControl panControl = (FloatControl) clip.getControl(FloatControl.Type.PAN);

      panControl.setValue((float) panSetting / 100.0f);

      double value = (double) gainSetting;

      FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
      float dB = (float) (Math.log(value == 0.0 ? 0.0001 : value) / Math.log(10.0) * 20.0);
      gainControl.setValue(dB);
      double playStartTime = (player.getSeekTime() / 100) * (playGetLength());
      clip.setMicrosecondPosition((long) playStartTime);

      clip.start();

      playState = PLAYING;

      return true;

    } catch (Exception ex) {
      ex.printStackTrace();
      playState = STOPPED;
      clip = null;
      return false;
    }
  }
Example #3
0
 public int getValue() {
   return (int) (control.getValue() * getScaleFactor());
 }
Example #4
0
 public void setValue(int nValue) {
   super.setValue(nValue);
   control.setValue((float) nValue / getScaleFactor());
 }
Example #5
0
 /**
  * Returns whether the type of a FloatControl is BALANCE or PAN.
  *
  * @param control FloatControl control
  * @return boolean is Balance or Pan
  */
 private static boolean isBalanceOrPan(FloatControl control) {
   Control.Type type = control.getType();
   return type.equals(FloatControl.Type.PAN) || type.equals(FloatControl.Type.BALANCE);
 }