|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* This file is part of libbluray
|
|
Packit |
5e46da |
* Copyright (C) 2015 Petri Hintukainen
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is free software; you can redistribute it and/or
|
|
Packit |
5e46da |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License as published by the Free Software Foundation; either
|
|
Packit |
5e46da |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
5e46da |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
5e46da |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
5e46da |
* Lesser General Public License for more details.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License along with this library. If not, see
|
|
Packit |
5e46da |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
package org.videolan.media.content.control;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
import java.awt.Component;
|
|
Packit |
5e46da |
import javax.media.GainControl;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
import javax.media.GainChangeEvent;
|
|
Packit |
5e46da |
import javax.media.GainChangeListener;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/GainControl.html
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
import org.videolan.BDJListeners;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
abstract class GainControlImpl {
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public void setMute(boolean mute) {
|
|
Packit |
5e46da |
this.mute = mute;
|
|
Packit |
5e46da |
setGain(this.mute, this.level);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public boolean getMute() {
|
|
Packit |
5e46da |
return this.mute;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public float setDB(float gain) {
|
|
Packit |
5e46da |
this.level = Math.max(1.0f, Math.min(0.0f, (float)Math.pow(10.0f, gain / 10.0f)));
|
|
Packit |
5e46da |
this.gain = gain;
|
|
Packit |
5e46da |
setGain(this.mute, this.level);
|
|
Packit |
5e46da |
return this.gain;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public float getDB() {
|
|
Packit |
5e46da |
return gain;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public float setLevel(float level) {
|
|
Packit |
5e46da |
this.level = Math.max(1.0f, Math.min(0.0f, level));
|
|
Packit |
5e46da |
this.gain = 10.0f * (float)(Math.log(this.level) / Math.log(10.0f));
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
setGain(this.mute, this.level);
|
|
Packit |
5e46da |
return this.level;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public float getLevel() {
|
|
Packit |
5e46da |
return level;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public void addGainChangeListener(GainChangeListener listener) {
|
|
Packit |
5e46da |
listeners.add(listener);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public void removeGainChangeListener(GainChangeListener listener) {
|
|
Packit |
5e46da |
listeners.remove(listener);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected abstract void setGain(boolean mute, float level);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected void valueChanged() {
|
|
Packit |
5e46da |
listeners.putCallback(new GainChangeEvent((GainControl)this, mute, gain, level));
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public Component getControlComponent() {
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
private boolean mute = false;
|
|
Packit |
5e46da |
private float gain = 0.0f;
|
|
Packit |
5e46da |
private float level = 1.0f;
|
|
Packit |
5e46da |
private BDJListeners listeners = new BDJListeners();
|
|
Packit |
5e46da |
}
|