src/share/classes/javax/sound/sampled/Port.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2004, 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 /**
  30  * Ports are simple lines for input or output of audio to or from audio devices.
  31  * Common examples of ports that act as source lines (mixer inputs) include the microphone,
  32  * line input, and CD-ROM drive.  Ports that act as target lines (mixer outputs) include the
  33  * speaker, headphone, and line output.  You can access port using a <code>{@link Port.Info}</code>
  34  * object.
  35  *
  36  * @author Kara Kytle
  37  * @since 1.3
  38  */
  39 public interface Port extends Line {
  40 
  41 
  42     // INNER CLASSES
  43 
  44 
  45     /**
  46      * The <code>Port.Info</code> class extends <code>{@link Line.Info}</code>
  47      * with additional information specific to ports, including the port's name
  48      * and whether it is a source or a target for its mixer.
  49      * By definition, a port acts as either a source or a target to its mixer,
  50      * but not both.  (Audio input ports are sources; audio output ports are targets.)
  51      * <p>
  52      * To learn what ports are available, you can retrieve port info objects through the
  53      * <code>{@link Mixer#getSourceLineInfo getSourceLineInfo}</code> and
  54      * <code>{@link Mixer#getTargetLineInfo getTargetLineInfo}</code>
  55      * methods of the <code>Mixer</code> interface.  Instances of the
  56      * <code>Port.Info</code> class may also be constructed and used to obtain
  57      * lines matching the parameters specified in the <code>Port.Info</code> object.
  58      *
  59      * @author Kara Kytle
  60      * @since 1.3
  61      */
  62     public static class Info extends Line.Info {
  63 
  64 
  65         // AUDIO PORT TYPE DEFINES
  66 
  67 
  68         // SOURCE PORTS
  69 
  70         /**
  71          * A type of port that gets audio from a built-in microphone or a microphone jack.

  72          */
  73         public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true);
  74 
  75         /**
  76          * A type of port that gets audio from a line-level audio input jack.
  77          */
  78         public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true);
  79 
  80         /**
  81          * A type of port that gets audio from a CD-ROM drive.
  82          */
  83         public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true);
  84 
  85 
  86         // TARGET PORTS
  87 
  88         /**
  89          * A type of port that sends audio to a built-in speaker or a speaker jack.

  90          */
  91         public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false);
  92 
  93         /**
  94          * A type of port that sends audio to a headphone jack.
  95          */
  96         public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false);
  97 
  98         /**
  99          * A type of port that sends audio to a line-level audio output jack.
 100          */
 101         public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false);
 102 
 103 
 104         // FUTURE DIRECTIONS...
 105 
 106         // telephone
 107         // DAT
 108         // DVD
 109 
 110 
 111         // INSTANCE VARIABLES
 112 
 113         private String name;
 114         private boolean isSource;
 115 
 116 
 117         // CONSTRUCTOR
 118 
 119         /**
 120          * Constructs a port's info object from the information given.
 121          * This constructor is typically used by an implementation
 122          * of Java Sound to describe a supported line.
 123          *
 124          * @param lineClass the class of the port described by the info object.
 125          * @param name the string that names the port
 126          * @param isSource <code>true</code> if the port is a source port (such
 127          * as a microphone), <code>false</code> if the port is a target port
 128          * (such as a speaker).
 129          */
 130         public Info(Class<?> lineClass, String name, boolean isSource) {
 131 
 132             super(lineClass);
 133             this.name = name;
 134             this.isSource = isSource;
 135         }
 136 
 137 
 138         // METHODS
 139 
 140         /**
 141          * Obtains the name of the port.

 142          * @return the string that names the port
 143          */
 144         public String getName() {
 145             return name;
 146         }
 147 
 148         /**
 149          * Indicates whether the port is a source or a target for its mixer.
 150          * @return <code>true</code> if the port is a source port (such
 151          * as a microphone), <code>false</code> if the port is a target port
 152          * (such as a speaker).

 153          */
 154         public boolean isSource() {
 155             return isSource;
 156         }
 157 
 158         /**
 159          * Indicates whether this info object specified matches this one.
 160          * To match, the match requirements of the superclass must be
 161          * met and the types must be equal.

 162          * @param info the info object for which the match is queried
 163          */

 164         public boolean matches(Line.Info info) {
 165 
 166             if (! (super.matches(info)) ) {
 167                 return false;
 168             }
 169 
 170             if (!(name.equals(((Info)info).getName())) ) {
 171                 return false;
 172             }
 173 
 174             if (! (isSource == ((Info)info).isSource()) ) {
 175                 return false;
 176             }
 177 
 178             return true;
 179         }
 180 
 181 
 182         /**
 183          * Finalizes the equals method
 184          */

 185         public final boolean equals(Object obj) {
 186             return super.equals(obj);
 187         }
 188 
 189         /**
 190          * Finalizes the hashCode method
 191          */

 192         public final int hashCode() {
 193             return super.hashCode();
 194         }
 195 
 196 
 197 
 198         /**
 199          * Provides a <code>String</code> representation
 200          * of the port.
 201          * @return  a string that describes the port
 202          */

 203         public final String toString() {
 204             return (name + ((isSource == true) ? " source" : " target") + " port");
 205         }
 206 
 207     } // class Info
 208 }
   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 }