Example usage for javax.sound.sampled FloatControl getValue

List of usage examples for javax.sound.sampled FloatControl getValue

Introduction

In this page you can find the example usage for javax.sound.sampled FloatControl getValue.

Prototype

public float getValue() 

Source Link

Document

Obtains this control's current value.

Usage

From source file:SoundPlayer.java

JSlider createSlider(final FloatControl c) {
    if (c == null)
        return null;
    final JSlider s = new JSlider(0, 1000);
    final float min = c.getMinimum();
    final float max = c.getMaximum();
    final float width = max - min;
    float fval = c.getValue();
    s.setValue((int) ((fval - min) / width * 1000));

    java.util.Hashtable labels = new java.util.Hashtable(3);
    labels.put(new Integer(0), new JLabel(c.getMinLabel()));
    labels.put(new Integer(500), new JLabel(c.getMidLabel()));
    labels.put(new Integer(1000), new JLabel(c.getMaxLabel()));
    s.setLabelTable(labels);// w  w w .j a v  a  2 s  .  c o  m
    s.setPaintLabels(true);

    s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits()));

    s.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int i = s.getValue();
            float f = min + (i * width / 1000.0f);
            c.setValue(f);
        }
    });
    return s;
}

From source file:org.eclipse.smarthome.io.javasound.internal.JavaSoundAudioSink.java

@Override
public PercentType getVolume() throws IOException {
    if (!isMac) {
        final Float[] volumes = new Float[1];
        runVolumeCommand(new Closure() {
            @Override/* w ww  .jav  a2s .  co  m*/
            public void execute(Object input) {
                FloatControl volumeControl = (FloatControl) input;
                volumes[0] = volumeControl.getValue();
            }
        });
        if (volumes[0] != null) {
            return new PercentType(new BigDecimal(volumes[0] * 100f));
        } else {
            throw new IOException("Cannot determine master volume level");
        }
    } else {
        // we use a cache of the value as the script execution is pretty slow
        if (macVolumeValue == null) {
            Process p = Runtime.getRuntime()
                    .exec(new String[] { "osascript", "-e", "output volume of (get volume settings)" });
            String value = IOUtils.toString(p.getInputStream()).trim();
            macVolumeValue = new PercentType(value);
        }
        return macVolumeValue;
    }
}

From source file:org.openhab.io.multimedia.actions.Audio.java

private static float getMasterVolumeJavaSound() throws IOException {
    final Float[] volumes = new Float[1];
    runVolumeCommand(new Closure() {
        public void execute(Object input) {
            FloatControl volumeControl = (FloatControl) input;
            volumes[0] = volumeControl.getValue();
        }//from  www .j  ava2s  .c o  m
    });
    if (volumes[0] != null) {
        return volumes[0];
    } else {
        throw new IOException("Cannot determine master volume level");
    }
}