< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/PortMixer.java
Print this page
*** 25,51 ****
package com.sun.media.sound;
import java.util.Vector;
import javax.sound.sampled.Control;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Port;
- import javax.sound.sampled.BooleanControl;
- import javax.sound.sampled.CompoundControl;
- import javax.sound.sampled.FloatControl;
-
/**
* A Mixer which only provides Ports.
*
* @author Florian Bomers
*/
final class PortMixer extends AbstractMixer {
- // CONSTANTS
private static final int SRC_UNKNOWN = 0x01;
private static final int SRC_MICROPHONE = 0x02;
private static final int SRC_LINE_IN = 0x03;
private static final int SRC_COMPACT_DISC = 0x04;
private static final int SRC_MASK = 0xFF;
--- 25,49 ----
package com.sun.media.sound;
import java.util.Vector;
+ import javax.sound.sampled.BooleanControl;
+ import javax.sound.sampled.CompoundControl;
import javax.sound.sampled.Control;
+ import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Port;
/**
* A Mixer which only provides Ports.
*
* @author Florian Bomers
*/
final class PortMixer extends AbstractMixer {
private static final int SRC_UNKNOWN = 0x01;
private static final int SRC_MICROPHONE = 0x02;
private static final int SRC_LINE_IN = 0x03;
private static final int SRC_COMPACT_DISC = 0x04;
private static final int SRC_MASK = 0xFF;
*** 54,72 ****
private static final int DST_SPEAKER = 0x0200;
private static final int DST_HEADPHONE = 0x0300;
private static final int DST_LINE_OUT = 0x0400;
private static final int DST_MASK = 0xFF00;
! // INSTANCE VARIABLES
! private Port.Info[] portInfos;
// cache of instantiated ports
private PortMixerPort[] ports;
// instance ID of the native implementation
private long id = 0;
- // CONSTRUCTOR
PortMixer(PortMixerProvider.PortMixerInfo portMixerInfo) {
// pass in Line.Info, mixer, controls
super(portMixerInfo, // Mixer.Info
null, // Control[]
null, // Line.Info[] sourceLineInfo
--- 52,68 ----
private static final int DST_SPEAKER = 0x0200;
private static final int DST_HEADPHONE = 0x0300;
private static final int DST_LINE_OUT = 0x0400;
private static final int DST_MASK = 0xFF00;
! private final Port.Info[] portInfos;
// cache of instantiated ports
private PortMixerPort[] ports;
// instance ID of the native implementation
private long id = 0;
PortMixer(PortMixerProvider.PortMixerInfo portMixerInfo) {
// pass in Line.Info, mixer, controls
super(portMixerInfo, // Mixer.Info
null, // Control[]
null, // Line.Info[] sourceLineInfo
*** 119,131 ****
}
if (Printer.trace) Printer.trace("<< PortMixer: constructor completed");
}
!
! // ABSTRACT MIXER: ABSTRACT METHOD IMPLEMENTATIONS
!
public Line getLine(Line.Info info) throws LineUnavailableException {
Line.Info fullInfo = getLineInfo(info);
if ((fullInfo != null) && (fullInfo instanceof Port.Info)) {
for (int i = 0; i < portInfos.length; i++) {
--- 115,125 ----
}
if (Printer.trace) Printer.trace("<< PortMixer: constructor completed");
}
! @Override
public Line getLine(Line.Info info) throws LineUnavailableException {
Line.Info fullInfo = getLineInfo(info);
if ((fullInfo != null) && (fullInfo instanceof Port.Info)) {
for (int i = 0; i < portInfos.length; i++) {
*** 135,145 ****
}
}
throw new IllegalArgumentException("Line unsupported: " + info);
}
!
public int getMaxLines(Line.Info info) {
Line.Info fullInfo = getLineInfo(info);
// if it's not supported at all, return 0.
if (fullInfo == null) {
--- 129,139 ----
}
}
throw new IllegalArgumentException("Line unsupported: " + info);
}
! @Override
public int getMaxLines(Line.Info info) {
Line.Info fullInfo = getLineInfo(info);
// if it's not supported at all, return 0.
if (fullInfo == null) {
*** 151,170 ****
return 1;
}
return 0;
}
!
protected void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixer: implOpen (id="+id+")");
// open the mixer device
id = nOpen(getMixerIndex());
if (Printer.trace) Printer.trace("<< PortMixer: implOpen succeeded.");
}
protected void implClose() {
if (Printer.trace) Printer.trace(">> PortMixer: implClose");
// close the mixer device
long thisID = id;
--- 145,165 ----
return 1;
}
return 0;
}
! @Override
protected void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixer: implOpen (id="+id+")");
// open the mixer device
id = nOpen(getMixerIndex());
if (Printer.trace) Printer.trace("<< PortMixer: implOpen succeeded.");
}
+ @Override
protected void implClose() {
if (Printer.trace) Printer.trace(">> PortMixer: implClose");
// close the mixer device
long thisID = id;
*** 179,193 ****
}
if (Printer.trace) Printer.trace("<< PortMixer: implClose succeeded");
}
protected void implStart() {}
protected void implStop() {}
- // IMPLEMENTATION HELPERS
-
private Port.Info getPortInfo(int portIndex, int type) {
switch (type) {
case SRC_UNKNOWN: return new PortInfo(nGetPortName(getID(), portIndex), true);
case SRC_MICROPHONE: return Port.Info.MICROPHONE;
case SRC_LINE_IN: return Port.Info.LINE_IN;
--- 174,188 ----
}
if (Printer.trace) Printer.trace("<< PortMixer: implClose succeeded");
}
+ @Override
protected void implStart() {}
+ @Override
protected void implStop() {}
private Port.Info getPortInfo(int portIndex, int type) {
switch (type) {
case SRC_UNKNOWN: return new PortInfo(nGetPortName(getID(), portIndex), true);
case SRC_MICROPHONE: return Port.Info.MICROPHONE;
case SRC_LINE_IN: return Port.Info.LINE_IN;
*** 221,255 ****
long getID() {
return id;
}
- // INNER CLASSES
-
/**
* Private inner class representing a Port for the PortMixer.
*/
private static final class PortMixerPort extends AbstractLine
implements Port {
private final int portIndex;
private long id;
- // CONSTRUCTOR
private PortMixerPort(Port.Info info,
PortMixer mixer,
int portIndex) {
super(info, mixer, null);
if (Printer.trace) Printer.trace("PortMixerPort CONSTRUCTOR: info: " + info);
this.portIndex = portIndex;
}
-
- // ABSTRACT METHOD IMPLEMENTATIONS
-
- // ABSTRACT LINE
-
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;
--- 216,242 ----
*** 284,304 ****
private void disposeControls() {
enableControls(controls, false);
controls = new Control[0];
}
-
void implClose() {
if (Printer.trace) Printer.trace(">> PortMixerPort: implClose()");
// get rid of controls
enableControls(controls, false);
if (Printer.trace) Printer.trace("<< PortMixerPort: implClose() succeeded");
}
- // METHOD OVERRIDES
-
// this is very similar to open(AudioFormat, int) in AbstractDataLine...
public void open() throws LineUnavailableException {
synchronized (mixer) {
// if the line is not currently open, try to open it with this format and buffer size
if (!isOpen()) {
if (Printer.trace) Printer.trace("> PortMixerPort: open");
--- 271,289 ----
private void disposeControls() {
enableControls(controls, false);
controls = new Control[0];
}
void implClose() {
if (Printer.trace) Printer.trace(">> PortMixerPort: implClose()");
// get rid of controls
enableControls(controls, false);
if (Printer.trace) Printer.trace("<< PortMixerPort: implClose() succeeded");
}
// this is very similar to open(AudioFormat, int) in AbstractDataLine...
+ @Override
public void open() throws LineUnavailableException {
synchronized (mixer) {
// if the line is not currently open, try to open it with this format and buffer size
if (!isOpen()) {
if (Printer.trace) Printer.trace("> PortMixerPort: open");
*** 319,328 ****
--- 304,314 ----
}
}
}
// this is very similar to close() in AbstractDataLine...
+ @Override
public void close() {
synchronized (mixer) {
if (isOpen()) {
if (Printer.trace) Printer.trace("> PortMixerPort.close()");
*** 340,350 ****
}
} // class PortMixerPort
/**
! * Private inner class representing a BooleanControl for PortMixerPort
*/
private static final class BoolCtrl extends BooleanControl {
// the handle to the native control function
private final long controlID;
private boolean closed = false;
--- 326,336 ----
}
} // class PortMixerPort
/**
! * Private inner class representing a BooleanControl for PortMixerPort.
*/
private static final class BoolCtrl extends BooleanControl {
// the handle to the native control function
private final long controlID;
private boolean closed = false;
*** 358,422 ****
//return BooleanControl.Type.SELECT;
}
return new BCT(name);
}
-
private BoolCtrl(long controlID, String name) {
this(controlID, createType(name));
}
private BoolCtrl(long controlID, BooleanControl.Type typ) {
super(typ, false);
this.controlID = controlID;
}
public void setValue(boolean value) {
if (!closed) {
nControlSetIntValue(controlID, value?1:0);
}
}
public boolean getValue() {
if (!closed) {
// never use any cached values
return (nControlGetIntValue(controlID)!=0)?true:false;
}
// ??
return false;
}
/**
! * inner class for custom types
*/
private static final class BCT extends BooleanControl.Type {
private BCT(String name) {
super(name);
}
}
}
/**
! * Private inner class representing a CompoundControl for PortMixerPort
*/
private static final class CompCtrl extends CompoundControl {
private CompCtrl(String name, Control[] controls) {
super(new CCT(name), controls);
}
/**
! * inner class for custom compound control types
*/
private static final class CCT extends CompoundControl.Type {
private CCT(String name) {
super(name);
}
}
}
/**
! * Private inner class representing a BooleanControl for PortMixerPort
*/
private static final class FloatCtrl extends FloatControl {
// the handle to the native control function
private final long controlID;
private boolean closed = false;
--- 344,409 ----
//return BooleanControl.Type.SELECT;
}
return new BCT(name);
}
private BoolCtrl(long controlID, String name) {
this(controlID, createType(name));
}
private BoolCtrl(long controlID, BooleanControl.Type typ) {
super(typ, false);
this.controlID = controlID;
}
+ @Override
public void setValue(boolean value) {
if (!closed) {
nControlSetIntValue(controlID, value?1:0);
}
}
+ @Override
public boolean getValue() {
if (!closed) {
// never use any cached values
return (nControlGetIntValue(controlID)!=0)?true:false;
}
// ??
return false;
}
/**
! * inner class for custom types.
*/
private static final class BCT extends BooleanControl.Type {
private BCT(String name) {
super(name);
}
}
}
/**
! * Private inner class representing a CompoundControl for PortMixerPort.
*/
private static final class CompCtrl extends CompoundControl {
private CompCtrl(String name, Control[] controls) {
super(new CCT(name), controls);
}
/**
! * inner class for custom compound control types.
*/
private static final class CCT extends CompoundControl.Type {
private CCT(String name) {
super(name);
}
}
}
/**
! * Private inner class representing a BooleanControl for PortMixerPort.
*/
private static final class FloatCtrl extends FloatControl {
// the handle to the native control function
private final long controlID;
private boolean closed = false;
*** 444,480 ****
float min, float max, float precision, String units) {
super(typ, min, max, precision, 1000, min, units);
this.controlID = controlID;
}
public void setValue(float value) {
if (!closed) {
nControlSetFloatValue(controlID, value);
}
}
public float getValue() {
if (!closed) {
// never use any cached values
return nControlGetFloatValue(controlID);
}
// ??
return getMinimum();
}
/**
! * inner class for custom types
*/
private static final class FCT extends FloatControl.Type {
private FCT(String name) {
super(name);
}
}
}
/**
! * Private inner class representing a port info
*/
private static final class PortInfo extends Port.Info {
private PortInfo(String name, boolean isSource) {
super(Port.class, name, isSource);
}
--- 431,469 ----
float min, float max, float precision, String units) {
super(typ, min, max, precision, 1000, min, units);
this.controlID = controlID;
}
+ @Override
public void setValue(float value) {
if (!closed) {
nControlSetFloatValue(controlID, value);
}
}
+ @Override
public float getValue() {
if (!closed) {
// never use any cached values
return nControlGetFloatValue(controlID);
}
// ??
return getMinimum();
}
/**
! * inner class for custom types.
*/
private static final class FCT extends FloatControl.Type {
private FCT(String name) {
super(name);
}
}
}
/**
! * Private inner class representing a port info.
*/
private static final class PortInfo extends Port.Info {
private PortInfo(String name, boolean isSource) {
super(Port.class, name, isSource);
}
< prev index next >