KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > sampled > Port


1 /*
2  * @(#)Port.java 1.26 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.sampled;
9
10
11 /**
12  * Ports are simple lines for input or output of audio to or from audio devices.
13  * Common examples of ports that act as source lines (mixer inputs) include the microphone,
14  * line input, and CD-ROM drive. Ports that act as target lines (mixer outputs) include the
15  * speaker, headphone, and line output. You can access port using a <code>{@link Port.Info}</code>
16  * object.
17  *
18  * @author Kara Kytle
19  * @version 1.26, 04/05/05
20  * @since 1.3
21  */

22 public interface Port extends Line JavaDoc {
23
24
25     // INNER CLASSES
26

27
28     /**
29      * The <code>Port.Info</code> class extends <code>{@link Line.Info}</code>
30      * with additional information specific to ports, including the port's name
31      * and whether it is a source or a target for its mixer.
32      * By definition, a port acts as either a source or a target to its mixer,
33      * but not both. (Audio input ports are sources; audio output ports are targets.)
34      * <p>
35      * To learn what ports are available, you can retrieve port info objects through the
36      * <code>{@link Mixer#getSourceLineInfo getSourceLineInfo}</code> and
37      * <code>{@link Mixer#getTargetLineInfo getTargetLineInfo}</code>
38      * methods of the <code>Mixer</code> interface. Instances of the
39      * <code>Port.Info</code> class may also be constructed and used to obtain
40      * lines matching the parameters specified in the <code>Port.Info</code> object.
41      *
42      * @author Kara Kytle
43      * @version 1.26, 04/05/05
44      * @since 1.3
45      */

46     public static class Info extends Line.Info JavaDoc {
47
48
49     // AUDIO PORT TYPE DEFINES
50

51
52     // SOURCE PORTS
53

54     /**
55      * A type of port that gets audio from a built-in microphone or a microphone jack.
56      */

57     public static final Info MICROPHONE = new Info(Port JavaDoc.class,"MICROPHONE", true);
58
59     /**
60      * A type of port that gets audio from a line-level audio input jack.
61      */

62     public static final Info LINE_IN = new Info(Port JavaDoc.class,"LINE_IN", true);
63
64     /**
65      * A type of port that gets audio from a CD-ROM drive.
66      */

67     public static final Info COMPACT_DISC = new Info(Port JavaDoc.class,"COMPACT_DISC", true);
68
69
70     // TARGET PORTS
71

72     /**
73      * A type of port that sends audio to a built-in speaker or a speaker jack.
74      */

75     public static final Info SPEAKER = new Info(Port JavaDoc.class,"SPEAKER", false);
76
77     /**
78      * A type of port that sends audio to a headphone jack.
79      */

80     public static final Info HEADPHONE = new Info(Port JavaDoc.class,"HEADPHONE", false);
81
82     /**
83      * A type of port that sends audio to a line-level audio output jack.
84      */

85     public static final Info LINE_OUT = new Info(Port JavaDoc.class,"LINE_OUT", false);
86
87         
88     // FUTURE DIRECTIONS...
89

90     // telephone
91
// DAT
92
// DVD
93

94
95     // INSTANCE VARIABLES
96

97     private String JavaDoc name;
98     private boolean isSource;
99
100
101     // CONSTRUCTOR
102

103     /**
104      * Constructs a port's info object from the information given.
105      * This constructor is typically used by an implementation
106      * of Java Sound to describe a supported line.
107      *
108      * @param lineClass the class of the port described by the info object.
109      * @param name the string that names the port
110      * @param isSource <code>true</code> if the port is a source port (such
111      * as a microphone), <code>false</code> if the port is a target port
112      * (such as a speaker).
113      */

114     public Info(Class JavaDoc<?> lineClass, String JavaDoc name, boolean isSource) {
115
116         super(lineClass);
117         this.name = name;
118         this.isSource = isSource;
119     }
120
121
122     // METHODS
123

124     /**
125      * Obtains the name of the port.
126      * @return the string that names the port
127      */

128     public String JavaDoc getName() {
129         return name;
130     }
131
132     /**
133      * Indicates whether the port is a source or a target for its mixer.
134      * @return <code>true</code> if the port is a source port (such
135      * as a microphone), <code>false</code> if the port is a target port
136      * (such as a speaker).
137      */

138     public boolean isSource() {
139         return isSource;
140     }
141
142     /**
143      * Indicates whether this info object specified matches this one.
144      * To match, the match requirements of the superclass must be
145      * met and the types must be equal.
146      * @param info the info object for which the match is queried
147      */

148     public boolean matches(Line.Info JavaDoc info) {
149
150         if (! (super.matches(info)) ) {
151         return false;
152         }
153
154         if (!(name.equals(((Info)info).getName())) ) {
155         return false;
156         }
157
158         if (! (isSource == ((Info)info).isSource()) ) {
159         return false;
160         }
161
162         return true;
163     }
164
165
166         /**
167      * Finalizes the equals method
168      */

169         public final boolean equals(Object JavaDoc obj) {
170             return super.equals(obj);
171         }
172
173         /**
174      * Finalizes the hashCode method
175      */

176         public final int hashCode() {
177             return super.hashCode();
178         }
179
180
181
182     /**
183      * Provides a <code>String</code> representation
184      * of the port.
185      * @return a string that describes the port
186      */

187     public final String JavaDoc toString() {
188         return (name + ((isSource == true) ? " source" : " target") + " port");
189     }
190
191     } // class Info
192
}
193
Popular Tags