1. /*
  2. * @(#)Port.java 1.26 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.sound.sampled;
  8. /**
  9. * Ports are simple lines for input or output of audio to or from audio devices.
  10. * Common examples of ports that act as source lines (mixer inputs) include the microphone,
  11. * line input, and CD-ROM drive. Ports that act as target lines (mixer outputs) include the
  12. * speaker, headphone, and line output. You can access port using a <code>{@link Port.Info}</code>
  13. * object.
  14. *
  15. * @author Kara Kytle
  16. * @version 1.26, 04/05/05
  17. * @since 1.3
  18. */
  19. public interface Port extends Line {
  20. // INNER CLASSES
  21. /**
  22. * The <code>Port.Info</code> class extends <code>{@link Line.Info}</code>
  23. * with additional information specific to ports, including the port's name
  24. * and whether it is a source or a target for its mixer.
  25. * By definition, a port acts as either a source or a target to its mixer,
  26. * but not both. (Audio input ports are sources; audio output ports are targets.)
  27. * <p>
  28. * To learn what ports are available, you can retrieve port info objects through the
  29. * <code>{@link Mixer#getSourceLineInfo getSourceLineInfo}</code> and
  30. * <code>{@link Mixer#getTargetLineInfo getTargetLineInfo}</code>
  31. * methods of the <code>Mixer</code> interface. Instances of the
  32. * <code>Port.Info</code> class may also be constructed and used to obtain
  33. * lines matching the parameters specified in the <code>Port.Info</code> object.
  34. *
  35. * @author Kara Kytle
  36. * @version 1.26, 04/05/05
  37. * @since 1.3
  38. */
  39. public static class Info extends Line.Info {
  40. // AUDIO PORT TYPE DEFINES
  41. // SOURCE PORTS
  42. /**
  43. * A type of port that gets audio from a built-in microphone or a microphone jack.
  44. */
  45. public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true);
  46. /**
  47. * A type of port that gets audio from a line-level audio input jack.
  48. */
  49. public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true);
  50. /**
  51. * A type of port that gets audio from a CD-ROM drive.
  52. */
  53. public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true);
  54. // TARGET PORTS
  55. /**
  56. * A type of port that sends audio to a built-in speaker or a speaker jack.
  57. */
  58. public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false);
  59. /**
  60. * A type of port that sends audio to a headphone jack.
  61. */
  62. public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false);
  63. /**
  64. * A type of port that sends audio to a line-level audio output jack.
  65. */
  66. public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false);
  67. // FUTURE DIRECTIONS...
  68. // telephone
  69. // DAT
  70. // DVD
  71. // INSTANCE VARIABLES
  72. private String name;
  73. private boolean isSource;
  74. // CONSTRUCTOR
  75. /**
  76. * Constructs a port's info object from the information given.
  77. * This constructor is typically used by an implementation
  78. * of Java Sound to describe a supported line.
  79. *
  80. * @param lineClass the class of the port described by the info object.
  81. * @param name the string that names the port
  82. * @param isSource <code>true</code> if the port is a source port (such
  83. * as a microphone), <code>false</code> if the port is a target port
  84. * (such as a speaker).
  85. */
  86. public Info(Class<?> lineClass, String name, boolean isSource) {
  87. super(lineClass);
  88. this.name = name;
  89. this.isSource = isSource;
  90. }
  91. // METHODS
  92. /**
  93. * Obtains the name of the port.
  94. * @return the string that names the port
  95. */
  96. public String getName() {
  97. return name;
  98. }
  99. /**
  100. * Indicates whether the port is a source or a target for its mixer.
  101. * @return <code>true</code> if the port is a source port (such
  102. * as a microphone), <code>false</code> if the port is a target port
  103. * (such as a speaker).
  104. */
  105. public boolean isSource() {
  106. return isSource;
  107. }
  108. /**
  109. * Indicates whether this info object specified matches this one.
  110. * To match, the match requirements of the superclass must be
  111. * met and the types must be equal.
  112. * @param info the info object for which the match is queried
  113. */
  114. public boolean matches(Line.Info info) {
  115. if (! (super.matches(info)) ) {
  116. return false;
  117. }
  118. if (!(name.equals(((Info)info).getName())) ) {
  119. return false;
  120. }
  121. if (! (isSource == ((Info)info).isSource()) ) {
  122. return false;
  123. }
  124. return true;
  125. }
  126. /**
  127. * Finalizes the equals method
  128. */
  129. public final boolean equals(Object obj) {
  130. return super.equals(obj);
  131. }
  132. /**
  133. * Finalizes the hashCode method
  134. */
  135. public final int hashCode() {
  136. return super.hashCode();
  137. }
  138. /**
  139. * Provides a <code>String</code> representation
  140. * of the port.
  141. * @return a string that describes the port
  142. */
  143. public final String toString() {
  144. return (name + ((isSource == true) ? " source" : " target") + " port");
  145. }
  146. } // class Info
  147. }