0N/A/*
2362N/A * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.sound.sampled;
0N/A
0N/A/**
0N/A * The <code>LineEvent</code> class encapsulates information that a line
0N/A * sends its listeners whenever the line opens, closes, starts, or stops.
0N/A * Each of these four state changes is represented by a corresponding
0N/A * type of event. A listener receives the event as a parameter to its
0N/A * {@link LineListener#update update} method. By querying the event,
0N/A * the listener can learn the type of event, the line responsible for
0N/A * the event, and how much data the line had processed when the event occurred.
0N/A *
0N/A * <p>Although this class implements Serializable, attempts to
0N/A * serialize a <code>LineEvent</code> object will fail.
0N/A *
0N/A * @author Kara Kytle
0N/A *
0N/A * @see Line
0N/A * @see LineListener#update
0N/A * @since 1.3
0N/A *
0N/A * @serial exclude
0N/A */
0N/Apublic class LineEvent extends java.util.EventObject {
0N/A
0N/A // INSTANCE VARIABLES
0N/A
0N/A /**
0N/A * The kind of line event (<code>OPEN</code>, <code>CLOSE</code>,
0N/A * <code>START</code>, or <code>STOP</code>).
0N/A * @see #getType
0N/A * @serial
0N/A */
0N/A private final Type type;
0N/A
0N/A /**
0N/A * The media position when the event occurred, expressed in sample frames.
0N/A * Note that this field is only relevant to certain events generated by
0N/A * data lines, such as <code>START</code> and <code>STOP</code>. For
0N/A * events generated by lines that do not count sample frames, and for any
0N/A * other events for which this value is not known, the position value
0N/A * should be {@link AudioSystem#NOT_SPECIFIED}.
0N/A * @serial
0N/A * @see #getFramePosition
0N/A */
0N/A private final long position;
0N/A
0N/A
0N/A /**
0N/A * Constructs a new event of the specified type, originating from the specified line.
0N/A * @param line the source of this event
0N/A * @param type the event type (<code>OPEN</code>, <code>CLOSE</code>, <code>START</code>, or <code>STOP</code>)
0N/A * @param position the number of sample frames that the line had already processed when the event occurred,
0N/A * or {@link AudioSystem#NOT_SPECIFIED}
0N/A *
0N/A * @throws IllegalArgumentException if <code>line</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public LineEvent(Line line, Type type, long position) {
0N/A
0N/A super(line);
0N/A this.type = type;
0N/A this.position = position;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the audio line that is the source of this event.
0N/A * @return the line responsible for this event
0N/A */
0N/A public final Line getLine() {
0N/A
0N/A return (Line)getSource();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains the event's type.
0N/A * @return this event's type ({@link Type#OPEN}, {@link Type#CLOSE},
0N/A * {@link Type#START}, or {@link Type#STOP})
0N/A */
0N/A public final Type getType() {
0N/A
0N/A return type;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the position in the line's audio data when the event occurred, expressed in sample frames.
0N/A * For example, if a source line had already played back 14 sample frames at the time it was
0N/A * paused, the pause event would report the line's position as 14. The next frame to be processed
0N/A * would be frame number 14 using zero-based numbering, or 15 using one-based numbering.
0N/A * <p>
0N/A * Note that this field is relevant only to certain events generated by
0N/A * data lines, such as <code>START</code> and <code>STOP</code>. For
0N/A * events generated by lines that do not count sample frames, and for any
0N/A * other events for which this value is not known, the position value
0N/A * should be {@link AudioSystem#NOT_SPECIFIED}.
0N/A *
0N/A * @return the line's position as a sample frame number
0N/A */
0N/A /*
0N/A * $$kk: 04.20.99: note to myself: should make sure our implementation is consistent with this.
0N/A * which is a reasonable definition....
0N/A */
0N/A public final long getFramePosition() {
0N/A
0N/A return position;
0N/A }
0N/A
0N/A /**
0N/A * Obtains a string representation of the event. The contents of the string may vary
0N/A * between implementations of Java Sound.
0N/A * @return a string describing the event.
0N/A */
0N/A public String toString() {
0N/A String sType = "";
0N/A if (type != null) sType = type.toString()+" ";
0N/A String sLine;
0N/A if (getLine() == null) {
0N/A sLine = "null";
0N/A } else {
0N/A sLine = getLine().toString();
0N/A }
0N/A return new String(sType + "event from line " + sLine);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * The LineEvent.Type inner class identifies what kind of event occurred on a line.
0N/A * Static instances are provided for the common types (OPEN, CLOSE, START, and STOP).
0N/A *
0N/A * @see LineEvent#getType()
0N/A */
0N/A public static class Type {
0N/A
0N/A
0N/A /**
0N/A * Type name.
0N/A */
0N/A // $$kk: 03.25.99: why can't this be final??
0N/A private /*final*/ String name;
0N/A
0N/A /**
0N/A * Constructs a new event type.
0N/A * @param name name of the type
0N/A */
0N/A protected Type(String name) {
0N/A this.name = name;
0N/A }
0N/A
0N/A
0N/A //$$fb 2002-11-26: fix for 4695001: SPEC: description of equals() method contains typo
0N/A /**
0N/A * Indicates whether the specified object is equal to this event type,
0N/A * returning <code>true</code> if the objects are identical.
0N/A * @param obj the reference object with which to compare
0N/A * @return <code>true</code> if this event type is the same as
0N/A * <code>obj</code>; <code>false</code> otherwise
0N/A */
0N/A public final boolean equals(Object obj) {
0N/A return super.equals(obj);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Finalizes the hashcode method.
0N/A */
0N/A public final int hashCode() {
0N/A return super.hashCode();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the type name as the string representation.
0N/A */
0N/A public String toString() {
0N/A return name;
0N/A }
0N/A
0N/A
0N/A // LINE EVENT TYPE DEFINES
0N/A
0N/A /**
0N/A * A type of event that is sent when a line opens, reserving system
0N/A * resources for itself.
0N/A * @see #CLOSE
0N/A * @see Line#open
0N/A */
0N/A public static final Type OPEN = new Type("Open");
0N/A
0N/A
0N/A /**
0N/A * A type of event that is sent when a line closes, freeing the system
0N/A * resources it had obtained when it was opened.
0N/A * @see #OPEN
0N/A * @see Line#close
0N/A */
0N/A public static final Type CLOSE = new Type("Close");
0N/A
0N/A
0N/A /**
0N/A * A type of event that is sent when a line begins to engage in active
0N/A * input or output of audio data in response to a
0N/A * {@link DataLine#start start} request.
0N/A * @see #STOP
0N/A * @see DataLine#start
0N/A */
0N/A public static final Type START = new Type("Start");
0N/A
0N/A
0N/A /**
0N/A * A type of event that is sent when a line ceases active input or output
0N/A * of audio data in response to a {@link DataLine#stop stop} request,
0N/A * or because the end of media has been reached.
0N/A * @see #START
0N/A * @see DataLine#stop
0N/A */
0N/A public static final Type STOP = new Type("Stop");
0N/A
0N/A
0N/A /**
0N/A * A type of event that is sent when a line ceases to engage in active
0N/A * input or output of audio data because the end of media has been reached.
0N/A */
0N/A /*
0N/A * ISSUE: we may want to get rid of this. Is JavaSound
0N/A * responsible for reporting this??
0N/A *
0N/A * [If it's decided to keep this API, the docs will need to be updated to include mention
0N/A * of EOM events elsewhere.]
0N/A */
0N/A //public static final Type EOM = new Type("EOM");
0N/A
0N/A
0N/A /**
0N/A * A type of event that is sent when a line begins to engage in active
0N/A * input or output of audio data. Examples of when this happens are
0N/A * when a source line begins or resumes writing data to its mixer, and
0N/A * when a target line begins or resumes reading data from its mixer.
0N/A * @see #STOP
0N/A * @see SourceDataLine#write
0N/A * @see TargetDataLine#read
0N/A * @see DataLine#start
0N/A */
0N/A //public static final Type ACTIVE = new Type("ACTIVE");
0N/A
0N/A
0N/A /**
0N/A * A type of event that is sent when a line ceases active input or output
0N/A * of audio data.
0N/A * @see #START
0N/A * @see DataLine#stop
0N/A */
0N/A //public static final Type INACTIVE = new Type("INACTIVE");
0N/A
0N/A } // class Type
0N/A
0N/A} // class LineEvent