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