< prev index next >

src/java.desktop/share/classes/javax/sound/sampled/LineEvent.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, 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


  83      * @param  type the event type ({@code OPEN}, {@code CLOSE}, {@code START},
  84      *         or {@code STOP})
  85      * @param  position the number of sample frames that the line had already
  86      *         processed when the event occurred, or
  87      *         {@link AudioSystem#NOT_SPECIFIED}
  88      * @throws IllegalArgumentException if {@code line} is {@code null}
  89      */
  90     public LineEvent(Line line, Type type, long position) {
  91 
  92         super(line);
  93         this.type = type;
  94         this.position = position;
  95     }
  96 
  97     /**
  98      * Obtains the audio line that is the source of this event.
  99      *
 100      * @return the line responsible for this event
 101      */
 102     public final Line getLine() {
 103 
 104         return (Line)getSource();
 105     }
 106 
 107     /**
 108      * Obtains the event's type.
 109      *
 110      * @return this event's type ({@link Type#OPEN}, {@link Type#CLOSE},
 111      *         {@link Type#START}, or {@link Type#STOP})
 112      */
 113     public final Type getType() {
 114 
 115         return type;
 116     }
 117 
 118     /**
 119      * Obtains the position in the line's audio data when the event occurred,
 120      * expressed in sample frames. For example, if a source line had already
 121      * played back 14 sample frames at the time it was paused, the pause event
 122      * would report the line's position as 14. The next frame to be processed
 123      * would be frame number 14 using zero-based numbering, or 15 using
 124      * one-based numbering.
 125      * <p>
 126      * Note that this field is relevant only to certain events generated by data
 127      * lines, such as {@code START} and {@code STOP}. For events generated by
 128      * lines that do not count sample frames, and for any other events for which
 129      * this value is not known, the position value should be
 130      * {@link AudioSystem#NOT_SPECIFIED}.
 131      *
 132      * @return the line's position as a sample frame number
 133      */
 134     /*
 135      * $$kk: 04.20.99: note to myself: should make sure our implementation is
 136      * consistent with this.
 137      * which is a reasonable definition....
 138      */
 139     public final long getFramePosition() {
 140 
 141         return position;
 142     }
 143 
 144     /**
 145      * Obtains a string representation of the event. The contents of the string
 146      * may vary between implementations of Java Sound.
 147      *
 148      * @return a string describing the event
 149      */
 150     @Override
 151     public String toString() {
 152         String sType = "";
 153         if (type != null) sType = type.toString()+" ";
 154         String sLine;
 155         if (getLine() == null) {
 156             sLine = "null";
 157         } else {
 158             sLine = getLine().toString();
 159         }
 160         return new String(sType + "event from line " + sLine);


   1 /*
   2  * Copyright (c) 1999, 2018, 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


  83      * @param  type the event type ({@code OPEN}, {@code CLOSE}, {@code START},
  84      *         or {@code STOP})
  85      * @param  position the number of sample frames that the line had already
  86      *         processed when the event occurred, or
  87      *         {@link AudioSystem#NOT_SPECIFIED}
  88      * @throws IllegalArgumentException if {@code line} is {@code null}
  89      */
  90     public LineEvent(Line line, Type type, long position) {
  91 
  92         super(line);
  93         this.type = type;
  94         this.position = position;
  95     }
  96 
  97     /**
  98      * Obtains the audio line that is the source of this event.
  99      *
 100      * @return the line responsible for this event
 101      */
 102     public final Line getLine() {

 103         return (Line)getSource();
 104     }
 105 
 106     /**
 107      * Obtains the event's type.
 108      *
 109      * @return this event's type ({@link Type#OPEN}, {@link Type#CLOSE},
 110      *         {@link Type#START}, or {@link Type#STOP})
 111      */
 112     public final Type getType() {

 113         return type;
 114     }
 115 
 116     /**
 117      * Obtains the position in the line's audio data when the event occurred,
 118      * expressed in sample frames. For example, if a source line had already
 119      * played back 14 sample frames at the time it was paused, the pause event
 120      * would report the line's position as 14. The next frame to be processed
 121      * would be frame number 14 using zero-based numbering, or 15 using
 122      * one-based numbering.
 123      * <p>
 124      * Note that this field is relevant only to certain events generated by data
 125      * lines, such as {@code START} and {@code STOP}. For events generated by
 126      * lines that do not count sample frames, and for any other events for which
 127      * this value is not known, the position value should be
 128      * {@link AudioSystem#NOT_SPECIFIED}.
 129      *
 130      * @return the line's position as a sample frame number
 131      */
 132     /*
 133      * $$kk: 04.20.99: note to myself: should make sure our implementation is
 134      * consistent with this.
 135      * which is a reasonable definition....
 136      */
 137     public final long getFramePosition() {

 138         return position;
 139     }
 140 
 141     /**
 142      * Obtains a string representation of the event. The contents of the string
 143      * may vary between implementations of Java Sound.
 144      *
 145      * @return a string describing the event
 146      */
 147     @Override
 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);


< prev index next >