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 
  60         // AUDIO PORT TYPE DEFINES
  61 
  62 
  63         // SOURCE PORTS
  64 
  65         /**
  66          * A type of port that gets audio from a built-in microphone or a
  67          * microphone jack.
  68          */
  69         public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true);
  70 
  71         /**
  72          * A type of port that gets audio from a line-level audio input jack.
  73          */
  74         public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true);
  75 
  76         /**
  77          * A type of port that gets audio from a CD-ROM drive.
  78          */
  79         public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true);
  80 
  81 
  82         // TARGET PORTS
  83 
  84         /**
  85          * A type of port that sends audio to a built-in speaker or a speaker
  86          * jack.
  87          */
  88         public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false);
  89 
  90         /**
  91          * A type of port that sends audio to a headphone jack.
  92          */
  93         public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false);
  94 
  95         /**
  96          * A type of port that sends audio to a line-level audio output jack.
  97          */
  98         public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false);
  99 
 100 
 101         // FUTURE DIRECTIONS...
 102 
 103         // telephone
 104         // DAT
 105         // DVD
 106 
 107 
 108         // INSTANCE VARIABLES
 109 
 110         private String name;
 111         private boolean isSource;
 112 
 113         /**
 114          * Constructs a port's info object from the information given. This
 115          * constructor is typically used by an implementation of Java Sound to
 116          * describe a supported line.
 117          *
 118          * @param  lineClass the class of the port described by the info object
 119          * @param  name the string that names the port
 120          * @param  isSource {@code true} if the port is a source port (such as a
 121          *         microphone), {@code false} if the port is a target port
 122          *         (such as a speaker)
 123          */
 124         public Info(Class<?> lineClass, String name, boolean isSource) {
 125 
 126             super(lineClass);
 127             this.name = name;
 128             this.isSource = isSource;
 129         }
 130 
 131         /**
 132          * Obtains the name of the port.
 133          *
 134          * @return the string that names the port
 135          */
 136         public String getName() {
 137             return name;
 138         }
 139 
 140         /**
 141          * Indicates whether the port is a source or a target for its mixer.
 142          *
 143          * @return {@code true} if the port is a source port (such as a
 144          *         microphone), {@code false} if the port is a target port
 145          *         (such as a speaker)
 146          */
 147         public boolean isSource() {
 148             return isSource;
 149         }
 150 
 151         /**
 152          * Indicates whether this info object specified matches this one. To
 153          * match, the match requirements of the superclass must be met and the
 154          * types must be equal.
 155          *
 156          * @param  info the info object for which the match is queried
 157          */
 158         @Override
 159         public boolean matches(Line.Info info) {
 160 
 161             if (! (super.matches(info)) ) {
 162                 return false;
 163             }
 164 
 165             if (!(name.equals(((Info)info).getName())) ) {
 166                 return false;
 167             }
 168 
 169             if (! (isSource == ((Info)info).isSource()) ) {
 170                 return false;
 171             }
 172 
 173             return true;
 174         }
 175 
 176         /**
 177          * Finalizes the equals method.
 178          */
 179         @Override
 180         public final boolean equals(Object obj) {
 181             return super.equals(obj);
 182         }
 183 
 184         /**
 185          * Finalizes the hashCode method.
 186          */
 187         @Override
 188         public final int hashCode() {
 189             return super.hashCode();
 190         }
 191 
 192         /**
 193          * Provides a {@code String} representation of the port.
 194          *
 195          * @return a string that describes the port
 196          */
 197         @Override
 198         public final String toString() {
 199             return (name + ((isSource == true) ? " source" : " target") + " port");
 200         }
 201     }
 202 }