author | darcy |
Tue, 24 Sep 2019 18:25:54 -0700 | |
changeset 58309 | c6f8b2c3dc66 |
parent 50832 | e069b9e49ca7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
50832 | 2 |
* Copyright (c) 1999, 2018, 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 |
|
47195 | 51 |
/** |
52 |
* Use serialVersionUID from JDK 1.3 for interoperability. |
|
53 |
*/ |
|
22949 | 54 |
private static final long serialVersionUID = -1274246333383880410L; |
2 | 55 |
|
56 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
57 |
* 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
|
58 |
* {@code STOP}). |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
59 |
* |
47195 | 60 |
* @see #getType |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
61 |
* @serial |
2 | 62 |
*/ |
58309
c6f8b2c3dc66
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents:
50832
diff
changeset
|
63 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 64 |
private final Type type; |
65 |
||
66 |
/** |
|
67 |
* 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
|
68 |
* 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
|
69 |
* 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
|
70 |
* 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
|
71 |
* this value is not known, the position value should be |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
72 |
* {@link AudioSystem#NOT_SPECIFIED}. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
73 |
* |
47195 | 74 |
* @see #getFramePosition |
2 | 75 |
* @serial |
76 |
*/ |
|
77 |
private final long position; |
|
78 |
||
79 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
80 |
* 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
|
81 |
* specified line. |
2 | 82 |
* |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
83 |
* @param line the source of this event |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
84 |
* @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
|
85 |
* or {@code STOP}) |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
86 |
* @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
|
87 |
* processed when the event occurred, or |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
88 |
* {@link AudioSystem#NOT_SPECIFIED} |
32871 | 89 |
* @throws IllegalArgumentException if {@code line} is {@code null} |
2 | 90 |
*/ |
91 |
public LineEvent(Line line, Type type, long position) { |
|
92 |
||
93 |
super(line); |
|
94 |
this.type = type; |
|
95 |
this.position = position; |
|
96 |
} |
|
97 |
||
98 |
/** |
|
99 |
* 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
|
100 |
* |
2 | 101 |
* @return the line responsible for this event |
102 |
*/ |
|
103 |
public final Line getLine() { |
|
104 |
return (Line)getSource(); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Obtains the event's type. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
109 |
* |
2 | 110 |
* @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
|
111 |
* {@link Type#START}, or {@link Type#STOP}) |
2 | 112 |
*/ |
113 |
public final Type getType() { |
|
114 |
return type; |
|
115 |
} |
|
116 |
||
117 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
118 |
* 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
|
119 |
* 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
|
120 |
* 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
|
121 |
* 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
|
122 |
* 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
|
123 |
* one-based numbering. |
2 | 124 |
* <p> |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
125 |
* 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
|
126 |
* 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
|
127 |
* 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
|
128 |
* this value is not known, the position value should be |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
129 |
* {@link AudioSystem#NOT_SPECIFIED}. |
2 | 130 |
* |
131 |
* @return the line's position as a sample frame number |
|
132 |
*/ |
|
133 |
/* |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
134 |
* $$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
|
135 |
* consistent with this. |
2 | 136 |
* which is a reasonable definition.... |
137 |
*/ |
|
138 |
public final long getFramePosition() { |
|
139 |
return position; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
143 |
* 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
|
144 |
* may vary between implementations of Java Sound. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
145 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
146 |
* @return a string describing the event |
2 | 147 |
*/ |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
148 |
@Override |
2 | 149 |
public String toString() { |
150 |
String sType = ""; |
|
151 |
if (type != null) sType = type.toString()+" "; |
|
152 |
String sLine; |
|
153 |
if (getLine() == null) { |
|
154 |
sLine = "null"; |
|
155 |
} else { |
|
156 |
sLine = getLine().toString(); |
|
157 |
} |
|
158 |
return new String(sType + "event from line " + sLine); |
|
159 |
} |
|
160 |
||
161 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
162 |
* 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
|
163 |
* 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
|
164 |
* START, and STOP). |
2 | 165 |
* |
166 |
* @see LineEvent#getType() |
|
167 |
*/ |
|
168 |
public static class Type { |
|
169 |
||
170 |
/** |
|
171 |
* Type name. |
|
172 |
*/ |
|
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32871
diff
changeset
|
173 |
private final String name; |
2 | 174 |
|
175 |
/** |
|
176 |
* Constructs a new event type. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
177 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
178 |
* @param name name of the type |
2 | 179 |
*/ |
180 |
protected Type(String name) { |
|
181 |
this.name = name; |
|
182 |
} |
|
183 |
||
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
184 |
//$$fb 2002-11-26: fix for 4695001: SPEC: description of equals() method contains typo |
2 | 185 |
|
186 |
/** |
|
187 |
* Indicates whether the specified object is equal to this event type, |
|
47195 | 188 |
* returning {@code true} if the objects are the same. |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
189 |
* |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
190 |
* @param obj the reference object with which to compare |
47195 | 191 |
* @return {@code true} if the specified object is equal to this event |
192 |
* type; {@code false} otherwise |
|
2 | 193 |
*/ |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
194 |
@Override |
2 | 195 |
public final boolean equals(Object obj) { |
196 |
return super.equals(obj); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
47195 | 200 |
* Returns a hash code value for this event type. |
201 |
* |
|
202 |
* @return a hash code value for this event type |
|
2 | 203 |
*/ |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
204 |
@Override |
2 | 205 |
public final int hashCode() { |
206 |
return super.hashCode(); |
|
207 |
} |
|
208 |
||
209 |
/** |
|
210 |
* Returns the type name as the string representation. |
|
47195 | 211 |
* |
212 |
* @return the type name as the string representation |
|
2 | 213 |
*/ |
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
214 |
@Override |
2 | 215 |
public String toString() { |
216 |
return name; |
|
217 |
} |
|
218 |
||
219 |
// LINE EVENT TYPE DEFINES |
|
220 |
||
221 |
/** |
|
222 |
* A type of event that is sent when a line opens, reserving system |
|
223 |
* resources for itself. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
224 |
* |
2 | 225 |
* @see #CLOSE |
226 |
* @see Line#open |
|
227 |
*/ |
|
45012
4e9dedef0231
8178971: Uncommon formatting and typos in java.desktop module
serb
parents:
40444
diff
changeset
|
228 |
public static final Type OPEN = new Type("Open"); |
2 | 229 |
|
230 |
/** |
|
231 |
* A type of event that is sent when a line closes, freeing the system |
|
232 |
* resources it had obtained when it was opened. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
233 |
* |
2 | 234 |
* @see #OPEN |
235 |
* @see Line#close |
|
236 |
*/ |
|
45012
4e9dedef0231
8178971: Uncommon formatting and typos in java.desktop module
serb
parents:
40444
diff
changeset
|
237 |
public static final Type CLOSE = new Type("Close"); |
2 | 238 |
|
239 |
/** |
|
240 |
* A type of event that is sent when a line begins to engage in active |
|
241 |
* input or output of audio data in response to a |
|
242 |
* {@link DataLine#start start} request. |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
243 |
* |
2 | 244 |
* @see #STOP |
245 |
* @see DataLine#start |
|
246 |
*/ |
|
45012
4e9dedef0231
8178971: Uncommon formatting and typos in java.desktop module
serb
parents:
40444
diff
changeset
|
247 |
public static final Type START = new Type("Start"); |
2 | 248 |
|
249 |
/** |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
250 |
* 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
|
251 |
* 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
|
252 |
* request, or because the end of media has been reached. |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
253 |
* |
2 | 254 |
* @see #START |
255 |
* @see DataLine#stop |
|
256 |
*/ |
|
45012
4e9dedef0231
8178971: Uncommon formatting and typos in java.desktop module
serb
parents:
40444
diff
changeset
|
257 |
public static final Type STOP = new Type("Stop"); |
2 | 258 |
|
259 |
/** |
|
260 |
* A type of event that is sent when a line ceases to engage in active |
|
47195 | 261 |
* input or output of audio data because the end of media has been |
262 |
* reached. |
|
2 | 263 |
*/ |
264 |
/* |
|
47195 | 265 |
* ISSUE: we may want to get rid of this. Is JavaSound responsible for |
266 |
* reporting this?? |
|
2 | 267 |
* |
47195 | 268 |
* [If it's decided to keep this API, the docs will need to be updated |
269 |
* to include mention of EOM events elsewhere.] |
|
2 | 270 |
*/ |
271 |
//public static final Type EOM = new Type("EOM"); |
|
272 |
||
273 |
/** |
|
274 |
* A type of event that is sent when a line begins to engage in active |
|
47195 | 275 |
* input or output of audio data. Examples of when this happens are when |
276 |
* a source line begins or resumes writing data to its mixer, and when a |
|
277 |
* target line begins or resumes reading data from its mixer. |
|
278 |
* |
|
2 | 279 |
* @see #STOP |
280 |
* @see SourceDataLine#write |
|
281 |
* @see TargetDataLine#read |
|
282 |
* @see DataLine#start |
|
283 |
*/ |
|
284 |
//public static final Type ACTIVE = new Type("ACTIVE"); |
|
285 |
||
286 |
/** |
|
47195 | 287 |
* A type of event that is sent when a line ceases active input or |
288 |
* output of audio data. |
|
289 |
* |
|
2 | 290 |
* @see #START |
291 |
* @see DataLine#stop |
|
292 |
*/ |
|
293 |
//public static final Type INACTIVE = new Type("INACTIVE"); |
|
25128
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
294 |
} |
2dfdfa369071
8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents:
22949
diff
changeset
|
295 |
} |