All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javafx.scene.media.EqualizerBand Maven / Gradle / Ivy

There is a newer version: 24-ea+15
Show newest version
/*
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package javafx.scene.media;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.DoublePropertyBase;

/**
 * The EqualizerBand class provides control for each band in the
 * {@link AudioEqualizer}.
 *
 * @see AudioEqualizer
 * @since JavaFX 2.0
 */
public final class EqualizerBand {
    /**
     * Minimum possible gain value.
     * In the current implementation this value is -24.0 dB.
     */
    public static final double MIN_GAIN = com.sun.media.jfxmedia.effects.EqualizerBand.MIN_GAIN;

    /**
     * Maximum possible gain value.
     * In the current implementation this value is 12.0 dB.
     */
    public static final double MAX_GAIN = com.sun.media.jfxmedia.effects.EqualizerBand.MAX_GAIN;

    /**
     * EqualizerBand default constructor. It creates an instance with
     * centerFrequency, bandwidth and gain set to 0.
     */
    public EqualizerBand() {}

    /**
     * Custom EqualizerBand constructor. It creates an instance
     * from the centerFrequency, bandwidth and
     * gain parameters. The gain specifies the amount
     * of amplification (gain > 0.0 dB) or attenuation
     * (gain < 0.0 dB) to be applied to the center frequency of
     * the band. The bandwidth is the frequency spread between the upper and
     * lower edges of the equalizer transfer function which have half the dB gain
     * of the peak (center frequency).
     *
     * @param centerFrequency a positive value specifying the center
     * frequency of the band in Hertz.
     * @param bandwidth a positive value specifying the bandwidth of the band in Hertz.
     * @param gain the gain in decibels to be applied to the band in the range
     * [{@link #MIN_GAIN}, {@link #MAX_GAIN}] dB.
     */
    public EqualizerBand(double centerFrequency, double bandwidth, double gain) {
        setCenterFrequency(centerFrequency);
        setBandwidth(bandwidth);
        setGain(gain);
    }
    /*
     * Package private write only property.
     *
     */
    private final Object disposeLock = new Object();
    private com.sun.media.jfxmedia.effects.EqualizerBand jfxBand;
    void setJfxBand(com.sun.media.jfxmedia.effects.EqualizerBand jfxBand) {
        synchronized (disposeLock) {
            this.jfxBand = jfxBand;
        }
    }

    /**
     * Center frequency of the band in Hertz. The default value is
     * 0.0 Hz.
     */
    private DoubleProperty centerFrequency;


    /**
     * Set the center frequency on the band in Hertz.
     * @param value the center frequency which must be a positive value in Hz.
     */
    public final void setCenterFrequency(double value) {
        centerFrequencyProperty().set(value);
    }

    /**
     * Retrieve the center frequency of the band.
     * @return the center frequency on the band in Hertz.
     */
    public final double getCenterFrequency() {
        return centerFrequency == null ? 0.0 : centerFrequency.get();
    }

    public DoubleProperty centerFrequencyProperty() {
        if (centerFrequency == null) {
            centerFrequency = new DoublePropertyBase() {

                @Override
                protected void invalidated() {
                    synchronized (disposeLock) {
                        double value = centerFrequency.get();
                        if (jfxBand != null && value > 0.0) {
                            jfxBand.setCenterFrequency(value);
                        }
                    }
                }

                @Override
                public Object getBean() {
                    return EqualizerBand.this;
                }

                @Override
                public String getName() {
                    return "centerFrequency";
                }
            };
        }
        return centerFrequency;
    }

    /**
     * Bandwidth of the band in Hertz. The default value is
     * 0.0 Hz.
     */
    private DoubleProperty bandwidth;


    /**
     * Set the bandwidth of the band in Hertz.
     * @param value the bandwidth which must be a positive value in Hz.
     */
    public final void setBandwidth(double value) {
        bandwidthProperty().set(value);
    }

    /**
     * Retrieve the bandwidth of the band.
     * @return the bandwidth of the band in Hertz.
     */
    public final double getBandwidth() {
        return bandwidth == null ? 0.0 : bandwidth.get();
    }

    public DoubleProperty bandwidthProperty() {
        if (bandwidth == null) {
            bandwidth = new DoublePropertyBase() {

                @Override
                protected void invalidated() {
                    synchronized (disposeLock) {
                        double value = bandwidth.get();
                        if (jfxBand != null && value > 0.0) {
                            jfxBand.setBandwidth(value);
                        }
                    }
                }

                @Override
                public Object getBean() {
                    return EqualizerBand.this;
                }

                @Override
                public String getName() {
                    return "bandwidth";
                }
            };
        }
        return bandwidth;
    }

    /**
     * The gain to be applied to the frequencies of this band. The default value
     * is 0.0 dB.
     */
    private DoubleProperty gain;

    /**
     * Set the gain of the band in dB. Gain property is limited to be
     * within the interval {@link #MIN_GAIN} to {@link #MAX_GAIN}.
     * @param value the gain in the range
     * [{@link #MIN_GAIN}, {@link #MAX_GAIN}].
     */
    public final void setGain(double value) {
        gainProperty().set(value);
    }

    /**
     * Retrieve the gain to be applied to the band.
     * @return the gain of the band in dB.
     */
    public final double getGain() {
        return gain == null ? 0.0 : gain.get();
    }

    public DoubleProperty gainProperty() {
        if (gain == null) {
            gain = new DoublePropertyBase() {

                @Override
                protected void invalidated() {
                    synchronized (disposeLock) {
                        if (jfxBand != null) {
                            jfxBand.setGain(gain.get());
                        }
                    }
                }

                @Override
                public Object getBean() {
                    return EqualizerBand.this;
                }

                @Override
                public String getName() {
                    return "gain";
                }
            };
        }
        return gain;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy