author | serb |
Mon, 15 Aug 2016 20:08:55 +0300 | |
changeset 40444 | afabcfc2f3ef |
parent 32871 | f013b86386e6 |
child 45012 | 4e9dedef0231 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22949 | 2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.sound.sampled; |
|
27 |
||
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
28 |
import java.util.EventObject; |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
29 |
|
2 | 30 |
/** |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
31 |
* The {@code LineEvent} class encapsulates information that a line sends its |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
32 |
* listeners whenever the line opens, closes, starts, or stops. Each of these |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
33 |
* four state changes is represented by a corresponding type of event. A |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
34 |
* listener receives the event as a parameter to its |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
35 |
* {@link LineListener#update update} method. By querying the event, the |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
36 |
* listener can learn the type of event, the line responsible for the event, and |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
37 |
* how much data the line had processed when the event occurred. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
38 |
* <p> |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
39 |
* Although this class implements Serializable, attempts to serialize a |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
40 |
* {@code LineEvent} object will fail. |
2 | 41 |
* |
42 |
* @author Kara Kytle |
|
43 |
* @see Line |
|
44 |
* @see LineListener#update |
|
45 |
* @since 1.3 |
|
46 |
* |
|
47 |
* @serial exclude |
|
48 |
*/ |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
49 |
public class LineEvent extends EventObject { |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
50 |
|
22949 | 51 |
private static final long serialVersionUID = -1274246333383880410L; |
2 | 52 |
|
53 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
54 |
* The kind of line event ({@code OPEN}, {@code CLOSE}, {@code START}, or |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
55 |
* {@code STOP}). |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
56 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
57 |
* @serial |
2 | 58 |
* @see #getType |
59 |
*/ |
|
60 |
private final Type type; |
|
61 |
||
62 |
/** |
|
63 |
* The media position when the event occurred, expressed in sample frames. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
64 |
* Note that this field is only relevant to certain events generated by data |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
65 |
* lines, such as {@code START} and {@code STOP}. For events generated by |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
66 |
* lines that do not count sample frames, and for any other events for which |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
67 |
* this value is not known, the position value should be |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
68 |
* {@link AudioSystem#NOT_SPECIFIED}. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
69 |
* |
2 | 70 |
* @serial |
71 |
* @see #getFramePosition |
|
72 |
*/ |
|
73 |
private final long position; |
|
74 |
||
75 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
76 |
* Constructs a new event of the specified type, originating from the |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
77 |
* specified line. |
2 | 78 |
* |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
79 |
* @param line the source of this event |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
80 |
* @param type the event type ({@code OPEN}, {@code CLOSE}, {@code START}, |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
81 |
* or {@code STOP}) |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
82 |
* @param position the number of sample frames that the line had already |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
83 |
* processed when the event occurred, or |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
84 |
* {@link AudioSystem#NOT_SPECIFIED} |
32871 | 85 |
* @throws IllegalArgumentException if {@code line} is {@code null} |
2 | 86 |
*/ |
87 |
public LineEvent(Line line, Type type, long position) { |
|
88 |
||
89 |
super(line); |
|
90 |
this.type = type; |
|
91 |
this.position = position; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Obtains the audio line that is the source of this event. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
96 |
* |
2 | 97 |
* @return the line responsible for this event |
98 |
*/ |
|
99 |
public final Line getLine() { |
|
100 |
||
101 |
return (Line)getSource(); |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Obtains the event's type. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
106 |
* |
2 | 107 |
* @return this event's type ({@link Type#OPEN}, {@link Type#CLOSE}, |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
108 |
* {@link Type#START}, or {@link Type#STOP}) |
2 | 109 |
*/ |
110 |
public final Type getType() { |
|
111 |
||
112 |
return type; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
116 |
* Obtains the position in the line's audio data when the event occurred, |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
117 |
* expressed in sample frames. For example, if a source line had already |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
118 |
* played back 14 sample frames at the time it was paused, the pause event |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
119 |
* would report the line's position as 14. The next frame to be processed |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
120 |
* would be frame number 14 using zero-based numbering, or 15 using |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
121 |
* one-based numbering. |
2 | 122 |
* <p> |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
123 |
* Note that this field is relevant only to certain events generated by data |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
124 |
* lines, such as {@code START} and {@code STOP}. For events generated by |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
125 |
* lines that do not count sample frames, and for any other events for which |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
126 |
* this value is not known, the position value should be |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
127 |
* {@link AudioSystem#NOT_SPECIFIED}. |
2 | 128 |
* |
129 |
* @return the line's position as a sample frame number |
|
130 |
*/ |
|
131 |
/* |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
132 |
* $$kk: 04.20.99: note to myself: should make sure our implementation is |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
133 |
* consistent with this. |
2 | 134 |
* which is a reasonable definition.... |
135 |
*/ |
|
136 |
public final long getFramePosition() { |
|
137 |
||
138 |
return position; |
|
139 |
} |
|
140 |
||
141 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
142 |
* Obtains a string representation of the event. The contents of the string |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
143 |
* may vary between implementations of Java Sound. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
144 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
145 |
* @return a string describing the event |
2 | 146 |
*/ |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
147 |
@Override |
2 | 148 |
public String toString() { |
149 |
String sType = ""; |
|
150 |
if (type != null) sType = type.toString()+" "; |
|
151 |
String sLine; |
|
152 |
if (getLine() == null) { |
|
153 |
sLine = "null"; |
|
154 |
} else { |
|
155 |
sLine = getLine().toString(); |
|
156 |
} |
|
157 |
return new String(sType + "event from line " + sLine); |
|
158 |
} |
|
159 |
||
160 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
161 |
* The LineEvent.Type inner class identifies what kind of event occurred on |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
162 |
* a line. Static instances are provided for the common types (OPEN, CLOSE, |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
163 |
* START, and STOP). |
2 | 164 |
* |
165 |
* @see LineEvent#getType() |
|
166 |
*/ |
|
167 |
public static class Type { |
|
168 |
||
169 |
/** |
|
170 |
* Type name. |
|
171 |
*/ |
|
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32871
diff
changeset
|
172 |
private final String name; |
2 | 173 |
|
174 |
/** |
|
175 |
* Constructs a new event type. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
176 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
177 |
* @param name name of the type |
2 | 178 |
*/ |
179 |
protected Type(String name) { |
|
180 |
this.name = name; |
|
181 |
} |
|
182 |
||
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
183 |
//$$fb 2002-11-26: fix for 4695001: SPEC: description of equals() method contains typo |
2 | 184 |
|
185 |
/** |
|
186 |
* Indicates whether the specified object is equal to this event type, |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
187 |
* returning {@code true} if the objects are identical. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
188 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
189 |
* @param obj the reference object with which to compare |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
190 |
* @return {@code true} if this event type is the same as {@code obj}; |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
191 |
* {@code false} otherwise |
2 | 192 |
*/ |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
193 |
@Override |
2 | 194 |
public final boolean equals(Object obj) { |
195 |
return super.equals(obj); |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* Finalizes the hashcode method. |
|
200 |
*/ |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
201 |
@Override |
2 | 202 |
public final int hashCode() { |
203 |
return super.hashCode(); |
|
204 |
} |
|
205 |
||
206 |
/** |
|
207 |
* Returns the type name as the string representation. |
|
208 |
*/ |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
209 |
@Override |
2 | 210 |
public String toString() { |
211 |
return name; |
|
212 |
} |
|
213 |
||
214 |
// LINE EVENT TYPE DEFINES |
|
215 |
||
216 |
/** |
|
217 |
* A type of event that is sent when a line opens, reserving system |
|
218 |
* resources for itself. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
219 |
* |
2 | 220 |
* @see #CLOSE |
221 |
* @see Line#open |
|
222 |
*/ |
|
223 |
public static final Type OPEN = new Type("Open"); |
|
224 |
||
225 |
/** |
|
226 |
* A type of event that is sent when a line closes, freeing the system |
|
227 |
* resources it had obtained when it was opened. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
228 |
* |
2 | 229 |
* @see #OPEN |
230 |
* @see Line#close |
|
231 |
*/ |
|
232 |
public static final Type CLOSE = new Type("Close"); |
|
233 |
||
234 |
/** |
|
235 |
* A type of event that is sent when a line begins to engage in active |
|
236 |
* input or output of audio data in response to a |
|
237 |
* {@link DataLine#start start} request. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
238 |
* |
2 | 239 |
* @see #STOP |
240 |
* @see DataLine#start |
|
241 |
*/ |
|
242 |
public static final Type START = new Type("Start"); |
|
243 |
||
244 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
245 |
* A type of event that is sent when a line ceases active input or |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
246 |
* output of audio data in response to a {@link DataLine#stop stop} |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
247 |
* request, or because the end of media has been reached. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
248 |
* |
2 | 249 |
* @see #START |
250 |
* @see DataLine#stop |
|
251 |
*/ |
|
252 |
public static final Type STOP = new Type("Stop"); |
|
253 |
||
254 |
/** |
|
255 |
* A type of event that is sent when a line ceases to engage in active |
|
256 |
* input or output of audio data because the end of media has been reached. |
|
257 |
*/ |
|
258 |
/* |
|
259 |
* ISSUE: we may want to get rid of this. Is JavaSound |
|
260 |
* responsible for reporting this?? |
|
261 |
* |
|
262 |
* [If it's decided to keep this API, the docs will need to be updated to include mention |
|
263 |
* of EOM events elsewhere.] |
|
264 |
*/ |
|
265 |
//public static final Type EOM = new Type("EOM"); |
|
266 |
||
267 |
/** |
|
268 |
* A type of event that is sent when a line begins to engage in active |
|
269 |
* input or output of audio data. Examples of when this happens are |
|
270 |
* when a source line begins or resumes writing data to its mixer, and |
|
271 |
* when a target line begins or resumes reading data from its mixer. |
|
272 |
* @see #STOP |
|
273 |
* @see SourceDataLine#write |
|
274 |
* @see TargetDataLine#read |
|
275 |
* @see DataLine#start |
|
276 |
*/ |
|
277 |
//public static final Type ACTIVE = new Type("ACTIVE"); |
|
278 |
||
279 |
/** |
|
280 |
* A type of event that is sent when a line ceases active input or output |
|
281 |
* of audio data. |
|
282 |
* @see #START |
|
283 |
* @see DataLine#stop |
|
284 |
*/ |
|
285 |
//public static final Type INACTIVE = new Type("INACTIVE"); |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
286 |
} |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
287 |
} |