Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/LineEvent.java
38918 views
/*1* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.sampled;2627/**28* The <code>LineEvent</code> class encapsulates information that a line29* sends its listeners whenever the line opens, closes, starts, or stops.30* Each of these four state changes is represented by a corresponding31* type of event. A listener receives the event as a parameter to its32* {@link LineListener#update update} method. By querying the event,33* the listener can learn the type of event, the line responsible for34* the event, and how much data the line had processed when the event occurred.35*36* <p>Although this class implements Serializable, attempts to37* serialize a <code>LineEvent</code> object will fail.38*39* @author Kara Kytle40*41* @see Line42* @see LineListener#update43* @since 1.344*45* @serial exclude46*/47public class LineEvent extends java.util.EventObject {4849// INSTANCE VARIABLES5051/**52* The kind of line event (<code>OPEN</code>, <code>CLOSE</code>,53* <code>START</code>, or <code>STOP</code>).54* @see #getType55* @serial56*/57private final Type type;5859/**60* The media position when the event occurred, expressed in sample frames.61* Note that this field is only relevant to certain events generated by62* data lines, such as <code>START</code> and <code>STOP</code>. For63* events generated by lines that do not count sample frames, and for any64* other events for which this value is not known, the position value65* should be {@link AudioSystem#NOT_SPECIFIED}.66* @serial67* @see #getFramePosition68*/69private final long position;707172/**73* Constructs a new event of the specified type, originating from the specified line.74* @param line the source of this event75* @param type the event type (<code>OPEN</code>, <code>CLOSE</code>, <code>START</code>, or <code>STOP</code>)76* @param position the number of sample frames that the line had already processed when the event occurred,77* or {@link AudioSystem#NOT_SPECIFIED}78*79* @throws IllegalArgumentException if <code>line</code> is80* <code>null</code>.81*/82public LineEvent(Line line, Type type, long position) {8384super(line);85this.type = type;86this.position = position;87}8889/**90* Obtains the audio line that is the source of this event.91* @return the line responsible for this event92*/93public final Line getLine() {9495return (Line)getSource();96}979899/**100* Obtains the event's type.101* @return this event's type ({@link Type#OPEN}, {@link Type#CLOSE},102* {@link Type#START}, or {@link Type#STOP})103*/104public final Type getType() {105106return type;107}108109/**110* Obtains the position in the line's audio data when the event occurred, expressed in sample frames.111* For example, if a source line had already played back 14 sample frames at the time it was112* paused, the pause event would report the line's position as 14. The next frame to be processed113* would be frame number 14 using zero-based numbering, or 15 using one-based numbering.114* <p>115* Note that this field is relevant only to certain events generated by116* data lines, such as <code>START</code> and <code>STOP</code>. For117* events generated by lines that do not count sample frames, and for any118* other events for which this value is not known, the position value119* should be {@link AudioSystem#NOT_SPECIFIED}.120*121* @return the line's position as a sample frame number122*/123/*124* $$kk: 04.20.99: note to myself: should make sure our implementation is consistent with this.125* which is a reasonable definition....126*/127public final long getFramePosition() {128129return position;130}131132/**133* Obtains a string representation of the event. The contents of the string may vary134* between implementations of Java Sound.135* @return a string describing the event.136*/137public String toString() {138String sType = "";139if (type != null) sType = type.toString()+" ";140String sLine;141if (getLine() == null) {142sLine = "null";143} else {144sLine = getLine().toString();145}146return new String(sType + "event from line " + sLine);147}148149150/**151* The LineEvent.Type inner class identifies what kind of event occurred on a line.152* Static instances are provided for the common types (OPEN, CLOSE, START, and STOP).153*154* @see LineEvent#getType()155*/156public static class Type {157158159/**160* Type name.161*/162// $$kk: 03.25.99: why can't this be final??163private /*final*/ String name;164165/**166* Constructs a new event type.167* @param name name of the type168*/169protected Type(String name) {170this.name = name;171}172173174//$$fb 2002-11-26: fix for 4695001: SPEC: description of equals() method contains typo175/**176* Indicates whether the specified object is equal to this event type,177* returning <code>true</code> if the objects are identical.178* @param obj the reference object with which to compare179* @return <code>true</code> if this event type is the same as180* <code>obj</code>; <code>false</code> otherwise181*/182public final boolean equals(Object obj) {183return super.equals(obj);184}185186187/**188* Finalizes the hashcode method.189*/190public final int hashCode() {191return super.hashCode();192}193194195/**196* Returns the type name as the string representation.197*/198public String toString() {199return name;200}201202203// LINE EVENT TYPE DEFINES204205/**206* A type of event that is sent when a line opens, reserving system207* resources for itself.208* @see #CLOSE209* @see Line#open210*/211public static final Type OPEN = new Type("Open");212213214/**215* A type of event that is sent when a line closes, freeing the system216* resources it had obtained when it was opened.217* @see #OPEN218* @see Line#close219*/220public static final Type CLOSE = new Type("Close");221222223/**224* A type of event that is sent when a line begins to engage in active225* input or output of audio data in response to a226* {@link DataLine#start start} request.227* @see #STOP228* @see DataLine#start229*/230public static final Type START = new Type("Start");231232233/**234* A type of event that is sent when a line ceases active input or output235* of audio data in response to a {@link DataLine#stop stop} request,236* or because the end of media has been reached.237* @see #START238* @see DataLine#stop239*/240public static final Type STOP = new Type("Stop");241242243/**244* A type of event that is sent when a line ceases to engage in active245* input or output of audio data because the end of media has been reached.246*/247/*248* ISSUE: we may want to get rid of this. Is JavaSound249* responsible for reporting this??250*251* [If it's decided to keep this API, the docs will need to be updated to include mention252* of EOM events elsewhere.]253*/254//public static final Type EOM = new Type("EOM");255256257/**258* A type of event that is sent when a line begins to engage in active259* input or output of audio data. Examples of when this happens are260* when a source line begins or resumes writing data to its mixer, and261* when a target line begins or resumes reading data from its mixer.262* @see #STOP263* @see SourceDataLine#write264* @see TargetDataLine#read265* @see DataLine#start266*/267//public static final Type ACTIVE = new Type("ACTIVE");268269270/**271* A type of event that is sent when a line ceases active input or output272* of audio data.273* @see #START274* @see DataLine#stop275*/276//public static final Type INACTIVE = new Type("INACTIVE");277278} // class Type279280} // class LineEvent281282283