Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.media; 027 028import javafx.beans.property.DoubleProperty; 029import javafx.beans.property.DoublePropertyBase; 030 031/** 032 * The <code>EqualizerBand</code> class provides control for each band in the 033 * {@link AudioEqualizer}. 034 * 035 * @see AudioEqualizer 036 */ 037public final class EqualizerBand { 038 /** 039 * Minimum possible gain value. 040 * In the current implementation this value is <code>-24.0</code> dB. 041 */ 042 public static final double MIN_GAIN = com.sun.media.jfxmedia.effects.EqualizerBand.MIN_GAIN; 043 044 /** 045 * Maximum possible gain value. 046 * In the current implementation this value is <code>12.0</code> dB. 047 */ 048 public static final double MAX_GAIN = com.sun.media.jfxmedia.effects.EqualizerBand.MAX_GAIN; 049 050 /** 051 * <code>EqualizerBand</code> default constructor. It creates an instance with 052 * <code>centerFrequency</code>, <code>bandwidth</code> and <code>gain</code> set to 0. 053 */ 054 public EqualizerBand() {} 055 056 /** 057 * Custom <code>EqualizerBand</code> constructor. It creates an instance 058 * from the <code>centerFrequency</code>, <code>bandwidth</code> and 059 * <code>gain</code> parameters. The <code>gain</code> specifies the amount 060 * of amplification (<code>gain > 0.0</code> dB) or attenuation 061 * (<code>gain < 0.0</code> dB) to be applied to the center frequency of 062 * the band. The bandwidth is the frequency spread between the upper and 063 * lower edges of the equalizer transfer function which have half the dB gain 064 * of the peak (center frequency). 065 * 066 * @param centerFrequency a positive value specifying the center 067 * frequency of the band in Hertz. 068 * @param bandwidth a positive value specifying the bandwidth of the band in Hertz. 069 * @param gain the gain in decibels to be applied to the band in the range 070 * [{@link #MIN_GAIN}, {@link #MAX_GAIN}] dB. 071 */ 072 public EqualizerBand(double centerFrequency, double bandwidth, double gain) { 073 setCenterFrequency(centerFrequency); 074 setBandwidth(bandwidth); 075 setGain(gain); 076 } 077 /* 078 * Package private write only property. 079 * 080 */ 081 private final Object disposeLock = new Object(); 082 private com.sun.media.jfxmedia.effects.EqualizerBand jfxBand; 083 void setJfxBand(com.sun.media.jfxmedia.effects.EqualizerBand jfxBand) { 084 synchronized (disposeLock) { 085 this.jfxBand = jfxBand; 086 } 087 } 088 089 /** 090 * Center frequency of the band in Hertz. The default value is 091 * <code>0.0</code> Hz. 092 */ 093 private DoubleProperty centerFrequency; 094 095 096 /** 097 * Set the center frequency on the band in Hertz. 098 * @param value the center frequency which must be a positive value in Hz. 099 */ 100 public final void setCenterFrequency(double value) { 101 centerFrequencyProperty().set(value); 102 } 103 104 /** 105 * Retrieve the center frequency of the band. 106 * @return the center frequency on the band in Hertz. 107 */ 108 public final double getCenterFrequency() { 109 return centerFrequency == null ? 0.0 : centerFrequency.get(); 110 } 111 112 public DoubleProperty centerFrequencyProperty() { 113 if (centerFrequency == null) { 114 centerFrequency = new DoublePropertyBase() { 115 116 @Override 117 protected void invalidated() { 118 synchronized (disposeLock) { 119 double value = centerFrequency.get(); 120 if (jfxBand != null && value > 0.0) { 121 jfxBand.setCenterFrequency(value); 122 } 123 } 124 } 125 126 @Override 127 public Object getBean() { 128 return EqualizerBand.this; 129 } 130 131 @Override 132 public String getName() { 133 return "centerFrequency"; 134 } 135 }; 136 } 137 return centerFrequency; 138 } 139 140 /** 141 * Bandwidth of the band in Hertz. The default value is 142 * <code>0.0</code> Hz. 143 */ 144 private DoubleProperty bandwidth; 145 146 147 /** 148 * Set the bandwidth of the band in Hertz. 149 * @param value the bandwidth which must be a positive value in Hz. 150 */ 151 public final void setBandwidth(double value) { 152 bandwidthProperty().set(value); 153 } 154 155 /** 156 * Retrieve the bandwidth of the band. 157 * @return the bandwidth of the band in Hertz. 158 */ 159 public final double getBandwidth() { 160 return bandwidth == null ? 0.0 : bandwidth.get(); 161 } 162 163 public DoubleProperty bandwidthProperty() { 164 if (bandwidth == null) { 165 bandwidth = new DoublePropertyBase() { 166 167 @Override 168 protected void invalidated() { 169 synchronized (disposeLock) { 170 double value = bandwidth.get(); 171 if (jfxBand != null && value > 0.0) { 172 jfxBand.setBandwidth(value); 173 } 174 } 175 } 176 177 @Override 178 public Object getBean() { 179 return EqualizerBand.this; 180 } 181 182 @Override 183 public String getName() { 184 return "bandwidth"; 185 } 186 }; 187 } 188 return bandwidth; 189 } 190 191 /** 192 * The gain to be applied to the frequencies of this band. The default value 193 * is <code>0.0</code> dB. 194 */ 195 private DoubleProperty gain; 196 197 /** 198 * Set the gain of the band in dB. Gain property is limited to be 199 * within the interval {@link #MIN_GAIN} to {@link #MAX_GAIN}. 200 * @param value the gain in the range 201 * [{@link #MIN_GAIN}, {@link #MAX_GAIN}]. 202 */ 203 public final void setGain(double value) { 204 gainProperty().set(value); 205 } 206 207 /** 208 * Retrieve the gain to be applied to the band. 209 * @return the gain of the band in dB. 210 */ 211 public final double getGain() { 212 return gain == null ? 0.0 : gain.get(); 213 } 214 215 public DoubleProperty gainProperty() { 216 if (gain == null) { 217 gain = new DoublePropertyBase() { 218 219 @Override 220 protected void invalidated() { 221 synchronized (disposeLock) { 222 if (jfxBand != null) { 223 jfxBand.setGain(gain.get()); 224 } 225 } 226 } 227 228 @Override 229 public Object getBean() { 230 return EqualizerBand.this; 231 } 232 233 @Override 234 public String getName() { 235 return "gain"; 236 } 237 }; 238 } 239 return gain; 240 } 241}