Java Reference
In-Depth Information
// Create the equalizer bands with the gains preset to
// a nice cosine wave pattern.
for (int j = 0; j < BAND_COUNT; j++) {
// Use j and BAND_COUNT to calculate a value between 0 and 2*pi
double theta = (double)j / (double)(BAND_COUNT-1) * (2*Math.PI);
// The cos function calculates a scale value between 0 and 0.4
double scale = 0.4 * (1 + Math.cos(theta));
// Set the gain to be a value between the midpoint and 0.9*max.
double gain = min + mid + (mid * scale);
bands.add(new EqualizerBand(freq, freq/2, gain));
freq *= 2;
}
for (int i = 0; i < bands.size(); ++i) {
EqualizerBand eb = bands.get(i);
Slider s = createEQSlider(eb, min, max);
final Label l = new Label(formatFrequency(eb.getCenterFrequency()));
l.getStyleClass().addAll("mediaText", "eqLabel");
GridPane.setHalignment(l, HPos.CENTER);
GridPane.setHalignment(s, HPos.CENTER);
GridPane.setHgrow(s, Priority.ALWAYS);
gp.add(l, i, 1);
gp.add(s, i, 2);
}
}
private Slider createEQSlider(EqualizerBand eb, double min, double max) {
final Slider s = new Slider(min, max, eb.getGain());
s.getStyleClass().add("eqSlider");
s.setOrientation(Orientation.VERTICAL);
s.valueProperty().bindBidirectional(eb.gainProperty());
s.setPrefWidth(44);
return s;
}
private String formatFrequency(double centerFrequency) {
if (centerFrequency < 1000) {
return String.format("%.0f Hz", centerFrequency);
} else {
return String.format("%.1f kHz", centerFrequency / 1000);
}
}
 
Search WWH ::




Custom Search