1 /* 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.sound.sampled; 27 28 /** 29 * Ports are simple lines for input or output of audio to or from audio devices. 30 * Common examples of ports that act as source lines (mixer inputs) include the 31 * microphone, line input, and CD-ROM drive. Ports that act as target lines 32 * (mixer outputs) include the speaker, headphone, and line output. You can 33 * access port using a {@link Port.Info} object. 34 * 35 * @author Kara Kytle 36 * @since 1.3 37 */ 38 public interface Port extends Line { 39 40 /** 41 * The {@code Port.Info} class extends {@code Line.Info} with additional 42 * information specific to ports, including the port's name and whether it 43 * is a source or a target for its mixer. By definition, a port acts as 44 * either a source or a target to its mixer, but not both. (Audio input 45 * ports are sources; audio output ports are targets.) 46 * <p> 47 * To learn what ports are available, you can retrieve port info objects 48 * through the {@link Mixer#getSourceLineInfo getSourceLineInfo} and 49 * {@link Mixer#getTargetLineInfo getTargetLineInfo} methods of the 50 * {@code Mixer} interface. Instances of the {@code Port.Info} class may 51 * also be constructed and used to obtain lines matching the parameters 52 * specified in the {@code Port.Info} object. 53 * 54 * @author Kara Kytle 55 * @since 1.3 56 */ 57 class Info extends Line.Info { 58 59 // AUDIO PORT TYPE DEFINES 60 61 // SOURCE PORTS 62 63 /** 64 * A type of port that gets audio from a built-in microphone or a 65 * microphone jack. 66 */ 67 public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true); 68 69 /** 70 * A type of port that gets audio from a line-level audio input jack. 71 */ 72 public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true); 73 74 /** 75 * A type of port that gets audio from a CD-ROM drive. 76 */ 77 public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true); 78 79 // TARGET PORTS 80 81 /** 82 * A type of port that sends audio to a built-in speaker or a speaker 83 * jack. 84 */ 85 public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false); 86 87 /** 88 * A type of port that sends audio to a headphone jack. 89 */ 90 public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false); 91 92 /** 93 * A type of port that sends audio to a line-level audio output jack. 94 */ 95 public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false); 96 97 // FUTURE DIRECTIONS... 98 99 // telephone 100 // DAT 101 // DVD 102 103 private final String name; 104 private final boolean isSource; 105 106 /** 107 * Constructs a port's info object from the information given. This 108 * constructor is typically used by an implementation of Java Sound to 109 * describe a supported line. 110 * 111 * @param lineClass the class of the port described by the info object 112 * @param name the string that names the port 113 * @param isSource {@code true} if the port is a source port (such as a 114 * microphone), {@code false} if the port is a target port 115 * (such as a speaker) 116 */ 117 public Info(Class<?> lineClass, String name, boolean isSource) { 118 119 super(lineClass); 120 this.name = name; 121 this.isSource = isSource; 122 } 123 124 /** 125 * Obtains the name of the port. 126 * 127 * @return the string that names the port 128 */ 129 public String getName() { 130 return name; 131 } 132 133 /** 134 * Indicates whether the port is a source or a target for its mixer. 135 * 136 * @return {@code true} if the port is a source port (such as a 137 * microphone), {@code false} if the port is a target port 138 * (such as a speaker) 139 */ 140 public boolean isSource() { 141 return isSource; 142 } 143 144 /** 145 * Indicates whether this info object specified matches this one. To 146 * match, the match requirements of the superclass must be met and the 147 * types must be equal. 148 * 149 * @param info the info object for which the match is queried 150 */ 151 @Override 152 public boolean matches(Line.Info info) { 153 154 if (! (super.matches(info)) ) { 155 return false; 156 } 157 158 if (!(name.equals(((Info)info).getName())) ) { 159 return false; 160 } 161 162 if (! (isSource == ((Info)info).isSource()) ) { 163 return false; 164 } 165 166 return true; 167 } 168 169 /** 170 * Finalizes the equals method. 171 */ 172 @Override 173 public final boolean equals(Object obj) { 174 return super.equals(obj); 175 } 176 177 /** 178 * Finalizes the hashCode method. 179 */ 180 @Override 181 public final int hashCode() { 182 return super.hashCode(); 183 } 184 185 /** 186 * Provides a {@code String} representation of the port. 187 * 188 * @return a string that describes the port 189 */ 190 @Override 191 public final String toString() { 192 return (name + ((isSource == true) ? " source" : " target") + " port"); 193 } 194 } 195 }