Save This Page
Home » openjdk-7 » javax.sound » sampled » [javadoc | source]
    1   /*
    2    * Copyright 1999-2004 Sun Microsystems, Inc.  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.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any 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   }

Save This Page
Home » openjdk-7 » javax.sound » sampled » [javadoc | source]