src/java.desktop/share/classes/javax/sound/sampled/Line.java
author serb
Fri, 29 Mar 2019 23:14:37 -0700
changeset 54406 080937e6e85c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8221436: Incorrect check of package in Line.Info.toString() Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54406
080937e6e85c 8221436: Incorrect check of package in Line.Info.toString()
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.sampled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    29
 * The {@code Line} interface represents a mono or multi-channel audio feed. A
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    30
 * line is an element of the digital audio "pipeline," such as a mixer, an input
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    31
 * or output port, or a data path into or out of a mixer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    33
 * A line can have controls, such as gain, pan, and reverb. The controls
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    34
 * themselves are instances of classes that extend the base {@link Control}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    35
 * class. The {@code Line} interface provides two accessor methods for obtaining
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    36
 * the line's controls: {@link #getControls getControls} returns the entire set,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    37
 * and {@link #getControl getControl} returns a single control of specified
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    38
 * type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    40
 * Lines exist in various states at different times. When a line opens, it
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    41
 * reserves system resources for itself, and when it closes, these resources are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    42
 * freed for other objects or applications. The {@link #isOpen()} method lets
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    43
 * you discover whether a line is open or closed. An open line need not be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    44
 * processing data, however. Such processing is typically initiated by
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    45
 * subinterface methods such as
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    46
 * {@link SourceDataLine#write SourceDataLine.write} and
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    47
 * {@link TargetDataLine#read TargetDataLine.read}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    48
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    49
 * You can register an object to receive notifications whenever the line's state
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    50
 * changes. The object must implement the {@link LineListener} interface, which
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    51
 * consists of the single method {@link LineListener#update update}. This method
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    52
 * will be invoked when a line opens and closes (and, if it's a {@link DataLine}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    53
 * , when it starts and stops).
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    54
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    55
 * An object can be registered to listen to multiple lines. The event it
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    56
 * receives in its {@code update} method will specify which line created the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    57
 * event, what type of event it was ({@code OPEN}, {@code CLOSE}, {@code START},
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    58
 * or {@code STOP}), and how many sample frames the line had processed at the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    59
 * time the event occurred.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Certain line operations, such as open and close, can generate security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * exceptions if invoked by unprivileged code when the line is a shared audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
5998
586c1b1dbb10 6963723: Project Coin: Retrofit more JDK classes for ARM
darcy
parents: 5506
diff changeset
    69
public interface Line extends AutoCloseable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    72
     * Obtains the {@code Line.Info} object describing this line.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    73
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return description of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    76
    Line.Info getLineInfo();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    79
     * Opens the line, indicating that it should acquire any required system
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    80
     * resources and become operational. If this operation succeeds, the line is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    81
     * marked as open, and an {@code OPEN} event is dispatched to the line's
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    82
     * listeners.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    84
     * Note that some lines, once closed, cannot be reopened. Attempts to reopen
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    85
     * such a line will always result in an {@code LineUnavailableException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    87
     * Some types of lines have configurable properties that may affect resource
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    88
     * allocation. For example, a {@code DataLine} must be opened with a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    89
     * particular format and buffer size. Such lines should provide a mechanism
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    90
     * for configuring these properties, such as an additional {@code open}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    91
     * method or methods which allow an application to specify the desired
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    92
     * settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * This method takes no arguments, and opens the line with the current
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    95
     * settings. For {@link SourceDataLine} and {@link TargetDataLine} objects,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    96
     * this means that the line is opened with default settings. For a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    97
     * {@link Clip}, however, the buffer size is determined when data is loaded.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    98
     * Since this method does not allow the application to specify any data to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
    99
     * load, an {@code IllegalArgumentException} is thrown. Therefore, you
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   100
     * should instead use one of the {@code open} methods provided in the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   101
     * {@code Clip} interface to load data into the {@code Clip}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   103
     * For {@code DataLine}'s, if the {@code DataLine.Info} object which was
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   104
     * used to retrieve the line, specifies at least one fully qualified audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   105
     * format, the last one will be used as the default format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   107
     * @throws IllegalArgumentException if this method is called on a Clip
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   108
     *         instance
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   109
     * @throws LineUnavailableException if the line cannot be opened due to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   110
     *         resource restrictions
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   111
     * @throws SecurityException if the line cannot be opened due to security
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   112
     *         restrictions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see #isOpen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see DataLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @see Clip#open(AudioFormat, byte[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see Clip#open(AudioInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   120
    void open() throws LineUnavailableException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   123
     * Closes the line, indicating that any system resources in use by the line
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   124
     * can be released. If this operation succeeds, the line is marked closed
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   125
     * and a {@code CLOSE} event is dispatched to the line's listeners.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   127
     * @throws SecurityException if the line cannot be closed due to security
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   128
     *         restrictions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #isOpen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   133
    @Override
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   134
    void close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   137
     * Indicates whether the line is open, meaning that it has reserved system
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   138
     * resources and is operational, although it might not currently be playing
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   139
     * or capturing sound.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   141
     * @return {@code true} if the line is open, otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see #open()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   145
    boolean isOpen();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   148
     * Obtains the set of controls associated with this line. Some controls may
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   149
     * only be available when the line is open. If there are no controls, this
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   150
     * method returns an array of length 0.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   151
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the array of controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #getControl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   155
    Control[] getControls();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   158
     * Indicates whether the line supports a control of the specified type. Some
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   159
     * controls may only be available when the line is open.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   160
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   161
     * @param  control the type of the control for which support is queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   162
     * @return {@code true} if at least one control of the specified type is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   163
     *         supported, otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   165
    boolean isControlSupported(Control.Type control);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   168
     * Obtains a control of the specified type, if there is any. Some controls
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   169
     * may only be available when the line is open.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   170
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   171
     * @param  control the type of the requested control
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return a control of the specified type
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   173
     * @throws IllegalArgumentException if a control of the specified type is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   174
     *         not supported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #getControls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see #isControlSupported(Control.Type control)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   178
    Control getControl(Control.Type control);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   181
     * Adds a listener to this line. Whenever the line's status changes, the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   182
     * listener's {@code update()} method is called with a {@code LineEvent}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   183
     * object that describes the change.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   184
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   185
     * @param  listener the object to add as a listener to this line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #removeLineListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see LineListener#update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   190
    void addLineListener(LineListener listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Removes the specified listener from this line's list of listeners.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   194
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   195
     * @param  listener listener to remove
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @see #addLineListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   198
    void removeLineListener(LineListener listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   201
     * A {@code Line.Info} object contains information about a line. The only
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   202
     * information provided by {@code Line.Info} itself is the Java class of the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   203
     * line. A subclass of {@code Line.Info} adds other kinds of information
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   204
     * about the line. This additional information depends on which {@code Line}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   205
     * subinterface is implemented by the kind of line that the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   206
     * {@code Line.Info} subclass describes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   208
     * A {@code Line.Info} can be retrieved using various methods of the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   209
     * {@code Line}, {@code Mixer}, and {@code AudioSystem} interfaces. Other
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   210
     * such methods let you pass a {@code Line.Info} as an argument, to learn
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   211
     * whether lines matching the specified configuration are available and to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   212
     * obtain them.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @author Kara Kytle
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   215
     * @see Line#getLineInfo()
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   216
     * @see Mixer#getSourceLineInfo()
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   217
     * @see Mixer#getTargetLineInfo()
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   218
     * @see Mixer#getLine(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   219
     * @see Mixer#getSourceLineInfo(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   220
     * @see Mixer#getTargetLineInfo(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   221
     * @see Mixer#isLineSupported(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   222
     * @see AudioSystem#getLine(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   223
     * @see AudioSystem#getSourceLineInfo(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   224
     * @see AudioSystem#getTargetLineInfo(Line.Info)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   225
     * @see AudioSystem#isLineSupported(Line.Info)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   228
    class Info {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * The class of the line described by the info object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   233
        private final Class<?> lineClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   236
         * Constructs an info object that describes a line of the specified
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   237
         * class. This constructor is typically used by an application to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * describe a desired line.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   239
         *
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   240
         * @param  lineClass the class of the line that the new
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   241
         *         {@code Line.Info} object describes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public Info(Class<?> lineClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (lineClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                this.lineClass = Line.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                this.lineClass = lineClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        /**
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   253
         * Obtains the class of the line that this {@code Line.Info} object
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   254
         * describes.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   255
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * @return the described line's class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        public Class<?> getLineClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return lineClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   263
         * Indicates whether the specified info object matches this one. To
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   264
         * match, the specified object must be identical to or a special case of
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   265
         * this one. The specified info object must be either an instance of the
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   266
         * same class as this one, or an instance of a sub-type of this one. In
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   267
         * addition, the attributes of the specified object must be compatible
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   268
         * with the capabilities of this one. Specifically, the routing
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   269
         * configuration for the specified info object must be compatible with
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   270
         * that of this one. Subclasses may add other criteria to determine
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 25859
diff changeset
   271
         * whether the two objects match.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   273
         * @param  info the info object which is being compared to this one
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   274
         * @return {@code true} if the specified object matches this one,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   275
         *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        public boolean matches(Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            // $$kk: 08.30.99: is this backwards?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            // dataLine.matches(targetDataLine) == true: targetDataLine is always dataLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            // targetDataLine.matches(dataLine) == false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            // so if i want to make sure i get a targetDataLine, i need:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // targetDataLine.matches(prospective_match) == true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // => prospective_match may be other things as well, but it is at least a targetDataLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // targetDataLine defines the requirements which prospective_match must meet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            // "if this Class object represents a declared class, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            // true if the specified Object argument is an instance of the represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            // class (or of any of its subclasses)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            // GainControlClass.isInstance(MyGainObj) => true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // GainControlClass.isInstance(MySpecialGainInterfaceObj) => true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            // this_class.isInstance(that_object)       => that object can by cast to this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            //                                                                          => that_object's class may be a subtype of this_class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            //                                                                          => that may be more specific (subtype) of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // "If this Class object represents an interface, this method returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // if the class or any superclass of the specified Object argument implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            // this interface"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            // GainControlClass.isInstance(MyGainObj) => true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // GainControlClass.isInstance(GenericControlObj) => may be false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            // => that may be more specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (! (this.getClass().isInstance(info)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // this.isAssignableFrom(that)  =>  this is same or super to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            //                                                          =>      this is at least as general as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            //                                                          =>      that may be subtype of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (! (getLineClass().isAssignableFrom(info.getLineClass())) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * Obtains a textual description of the line info.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   322
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * @return a string description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   325
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        public String toString() {
54406
080937e6e85c 8221436: Incorrect check of package in Line.Info.toString()
serb
parents: 47216
diff changeset
   327
            final String str = getLineClass().toString();
080937e6e85c 8221436: Incorrect check of package in Line.Info.toString()
serb
parents: 47216
diff changeset
   328
            if (getLineClass().getPackage() == Line.class.getPackage()) {
080937e6e85c 8221436: Incorrect check of package in Line.Info.toString()
serb
parents: 47216
diff changeset
   329
                return str.replace("javax.sound.sampled.", "");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
54406
080937e6e85c 8221436: Incorrect check of package in Line.Info.toString()
serb
parents: 47216
diff changeset
   331
            return str;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   333
    }
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 7668
diff changeset
   334
}