下面列出了怎么用javax.sound.sampled.Control的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Constructs a new AbstractMixer.
* @param mixer the mixer with which this line is associated
* @param controls set of supported controls
*/
protected AbstractMixer(Mixer.Info mixerInfo,
Control[] controls,
Line.Info[] sourceLineInfo,
Line.Info[] targetLineInfo) {
// Line.Info, AbstractMixer, Control[]
super(new Line.Info(Mixer.class), null, controls);
// setup the line part
this.mixer = this;
if (controls == null) {
controls = new Control[0];
}
// setup the mixer part
this.mixerInfo = mixerInfo;
this.sourceLineInfo = sourceLineInfo;
this.targetLineInfo = targetLineInfo;
}
void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixerPort: implOpen().");
long newID = ((PortMixer) mixer).getID();
if ((id == 0) || (newID != id) || (controls.length == 0)) {
id = newID;
Vector<Control> vector = new Vector<>();
synchronized (vector) {
nGetControls(id, portIndex, vector);
controls = new Control[vector.size()];
for (int i = 0; i < controls.length; i++) {
controls[i] = vector.elementAt(i);
}
}
} else {
enableControls(controls, true);
}
if (Printer.trace) Printer.trace("<< PortMixerPort: implOpen() succeeded");
}
void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixerPort: implOpen().");
long newID = ((PortMixer) mixer).getID();
if ((id == 0) || (newID != id) || (controls.length == 0)) {
id = newID;
Vector vector = new Vector();
synchronized (vector) {
nGetControls(id, portIndex, vector);
controls = new Control[vector.size()];
for (int i = 0; i < controls.length; i++) {
controls[i] = (Control) vector.elementAt(i);
}
}
} else {
enableControls(controls, true);
}
if (Printer.trace) Printer.trace("<< PortMixerPort: implOpen() succeeded");
}
/**
* Constructs a new AbstractMixer.
* @param mixerInfo the mixer with which this line is associated
* @param controls set of supported controls
*/
protected AbstractMixer(Mixer.Info mixerInfo,
Control[] controls,
Line.Info[] sourceLineInfo,
Line.Info[] targetLineInfo) {
// Line.Info, AbstractMixer, Control[]
super(new Line.Info(Mixer.class), null, controls);
// setup the line part
this.mixer = this;
if (controls == null) {
controls = new Control[0];
}
// setup the mixer part
this.mixerInfo = mixerInfo;
this.sourceLineInfo = sourceLineInfo;
this.targetLineInfo = targetLineInfo;
}
/**
* Constructs a new AbstractMixer.
* @param mixer the mixer with which this line is associated
* @param controls set of supported controls
*/
protected AbstractMixer(Mixer.Info mixerInfo,
Control[] controls,
Line.Info[] sourceLineInfo,
Line.Info[] targetLineInfo) {
// Line.Info, AbstractMixer, Control[]
super(new Line.Info(Mixer.class), null, controls);
// setup the line part
this.mixer = this;
if (controls == null) {
controls = new Control[0];
}
// setup the mixer part
this.mixerInfo = mixerInfo;
this.sourceLineInfo = sourceLineInfo;
this.targetLineInfo = targetLineInfo;
}
void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixerPort: implOpen().");
long newID = ((PortMixer) mixer).getID();
if ((id == 0) || (newID != id) || (controls.length == 0)) {
id = newID;
Vector vector = new Vector();
synchronized (vector) {
nGetControls(id, portIndex, vector);
controls = new Control[vector.size()];
for (int i = 0; i < controls.length; i++) {
controls[i] = (Control) vector.elementAt(i);
}
}
} else {
enableControls(controls, true);
}
if (Printer.trace) Printer.trace("<< PortMixerPort: implOpen() succeeded");
}
void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixerPort: implOpen().");
long newID = ((PortMixer) mixer).getID();
if ((id == 0) || (newID != id) || (controls.length == 0)) {
id = newID;
Vector vector = new Vector();
synchronized (vector) {
nGetControls(id, portIndex, vector);
controls = new Control[vector.size()];
for (int i = 0; i < controls.length; i++) {
controls[i] = (Control) vector.elementAt(i);
}
}
} else {
enableControls(controls, true);
}
if (Printer.trace) Printer.trace("<< PortMixerPort: implOpen() succeeded");
}
private void enableControls(Control[] controls, boolean enable) {
for (int i = 0; i < controls.length; i++) {
if (controls[i] instanceof BoolCtrl) {
((BoolCtrl) controls[i]).closed = !enable;
}
else if (controls[i] instanceof FloatCtrl) {
((FloatCtrl) controls[i]).closed = !enable;
}
else if (controls[i] instanceof CompoundControl) {
enableControls(((CompoundControl) controls[i]).getMemberControls(), enable);
}
}
}
public final boolean isControlSupported(Control.Type controlType) {
// protect against a NullPointerException
if (controlType == null) {
return false;
}
for (int i = 0; i < controls.length; i++) {
if (controlType == controls[i].getType()) {
return true;
}
}
return false;
}
public final Control getControl(Control.Type controlType) {
// protect against a NullPointerException
if (controlType != null) {
for (int i = 0; i < controls.length; i++) {
if (controlType == controls[i].getType()) {
return controls[i];
}
}
}
throw new IllegalArgumentException("Unsupported control type: " + controlType);
}
SoftMixingDataLine(SoftMixingMixer mixer, DataLine.Info info) {
this.mixer = mixer;
this.info = info;
this.control_mutex = mixer.control_mutex;
controls = new Control[] { gain_control, mute_control, balance_control,
pan_control, reverbsend_control, chorussend_control,
apply_reverb };
calcVolume();
}
public final Control getControl(Type control) {
if (control != null) {
for (int i = 0; i < controls.length; i++) {
if (controls[i].getType() == control) {
return controls[i];
}
}
}
throw new IllegalArgumentException("Unsupported control type : "
+ control);
}
@Override
public final boolean isControlSupported(Control.Type controlType) {
// protect against a NullPointerException
if (controlType == null) {
return false;
}
for (int i = 0; i < controls.length; i++) {
if (controlType == controls[i].getType()) {
return true;
}
}
return false;
}