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); }
private void fade(FloatControl control, double to) { //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (control) { int steps = FADE_DURATION / FADE_STEP_DURATION; to = (to <= 0.0) ? 0.0001 : ((to > 1.0) ? 1.0 : to); float currDB = control.getValue(); float toDB = getDb(to); float diffStep = (toDB - currDB) / (float) steps; for (int i = 0; i < steps; i++) { currDB += diffStep; currDB = (Math.abs(currDB - toDB) < Math.abs(diffStep * 1.5)) ? toDB : currDB; control.setValue(currDB); try { Thread.sleep(FADE_STEP_DURATION); } catch (Exception ignored) { ignored.printStackTrace(); } } } }
// Возвращает текущую громкость (число от 0 до 1) public float getVolume() { float v = volumeC.getValue(); float min = volumeC.getMinimum(); float max = volumeC.getMaximum(); return (v - min) / (max - min); }
public int getValue() { return (int) (control.getValue() * getScaleFactor()); }