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