0N/A/*
3261N/A * Copyright (c) 1999, 2010, 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.midi;
0N/A
0N/Aimport java.util.List;
0N/A
0N/A /**
0N/A * <code>MidiDevice</code> is the base interface for all MIDI devices.
0N/A * Common devices include synthesizers, sequencers, MIDI input ports, and MIDI
0N/A * output ports.
0N/A *
0N/A * <p>A <code>MidiDevice</code> can be a transmitter or a receiver of
0N/A * MIDI events, or both. Therefore, it can provide {@link Transmitter}
0N/A * or {@link Receiver} instances (or both). Typically, MIDI IN ports
0N/A * provide transmitters, MIDI OUT ports and synthesizers provide
0N/A * receivers. A Sequencer typically provides transmitters for playback
0N/A * and receivers for recording.
0N/A *
0N/A * <p>A <code>MidiDevice</code> can be opened and closed explicitly as
0N/A * well as implicitly. Explicit opening is accomplished by calling
0N/A * {@link #open}, explicit closing is done by calling {@link
0N/A * #close} on the <code>MidiDevice</code> instance.
0N/A * If an application opens a <code>MidiDevice</code>
0N/A * explicitly, it has to close it explicitly to free system resources
0N/A * and enable the application to exit cleanly. Implicit opening is
0N/A * done by calling {@link javax.sound.midi.MidiSystem#getReceiver
0N/A * MidiSystem.getReceiver} and {@link
0N/A * javax.sound.midi.MidiSystem#getTransmitter
0N/A * MidiSystem.getTransmitter}. The <code>MidiDevice</code> used by
0N/A * <code>MidiSystem.getReceiver</code> and
0N/A * <code>MidiSystem.getTransmitter</code> is implementation-dependant
0N/A * unless the properties <code>javax.sound.midi.Receiver</code>
0N/A * and <code>javax.sound.midi.Transmitter</code> are used (see the
0N/A * description of properties to select default providers in
0N/A * {@link javax.sound.midi.MidiSystem}). A <code>MidiDevice</code>
0N/A * that was opened implicitly, is closed implicitly by closing the
0N/A * <code>Receiver</code> or <code>Transmitter</code> that resulted in
0N/A * opening it. If more than one implicitly opening
0N/A * <code>Receiver</code> or <code>Transmitter</code> were obtained by
0N/A * the application, the decive is closed after the last
0N/A * <code>Receiver</code> or <code>Transmitter</code> has been
0N/A * closed. On the other hand, calling <code>getReceiver</code> or
0N/A * <code>getTransmitter</code> on the device instance directly does
0N/A * not open the device implicitly. Closing these
0N/A * <code>Transmitter</code>s and <code>Receiver</code>s does not close
0N/A * the device implicitly. To use a device with <code>Receiver</code>s
0N/A * or <code>Transmitter</code>s obtained this way, the device has to
0N/A * be opened and closed explicitly.
0N/A *
0N/A * <p>If implicit and explicit opening and closing are mixed on the
0N/A * same <code>MidiDevice</code> instance, the following rules apply:
0N/A *
0N/A * <ul>
0N/A * <li>After an explicit open (either before or after implicit
0N/A * opens), the device will not be closed by implicit closing. The only
0N/A * way to close an explicitly opened device is an explicit close.</li>
0N/A *
0N/A * <li>An explicit close always closes the device, even if it also has
0N/A * been opened implicitly. A subsequent implicit close has no further
0N/A * effect.</li>
0N/A * </ul>
0N/A *
0N/A * To detect if a MidiDevice represents a hardware MIDI port, the
0N/A * following programming technique can be used:
0N/A *
0N/A * <pre>
0N/A * MidiDevice device = ...;
0N/A * if ( ! (device instanceof Sequencer) && ! (device instanceof Synthesizer)) {
0N/A * // we're now sure that device represents a MIDI port
0N/A * // ...
0N/A * }
0N/A * </pre>
0N/A *
0N/A * <p>
0N/A * A <code>MidiDevice</code> includes a <code>{@link MidiDevice.Info}</code> object
0N/A * to provide manufacturer information and so on.
0N/A *
0N/A * @see Synthesizer
0N/A * @see Sequencer
0N/A * @see Receiver
0N/A * @see Transmitter
0N/A *
0N/A * @author Kara Kytle
0N/A * @author Florian Bomers
0N/A */
0N/A
2574N/Apublic interface MidiDevice extends AutoCloseable {
0N/A
0N/A
0N/A /**
0N/A * Obtains information about the device, including its Java class and
0N/A * <code>Strings</code> containing its name, vendor, and description.
0N/A *
0N/A * @return device info
0N/A */
0N/A public Info getDeviceInfo();
0N/A
0N/A
0N/A /**
0N/A * Opens the device, indicating that it should now acquire any
0N/A * system resources it requires and become operational.
0N/A *
0N/A * <p>An application opening a device explicitly with this call
0N/A * has to close the device by calling {@link #close}. This is
0N/A * necessary to release system resources and allow applications to
0N/A * exit cleanly.
0N/A *
0N/A * <p>
0N/A * Note that some devices, once closed, cannot be reopened. Attempts
0N/A * to reopen such a device will always result in a MidiUnavailableException.
0N/A *
0N/A * @throws MidiUnavailableException thrown if the device cannot be
0N/A * opened due to resource restrictions.
0N/A * @throws SecurityException thrown if the device cannot be
0N/A * opened due to security restrictions.
0N/A *
0N/A * @see #close
0N/A * @see #isOpen
0N/A */
0N/A public void open() throws MidiUnavailableException;
0N/A
0N/A
0N/A /**
0N/A * Closes the device, indicating that the device should now release
0N/A * any system resources it is using.
0N/A *
0N/A * <p>All <code>Receiver</code> and <code>Transmitter</code> instances
0N/A * open from this device are closed. This includes instances retrieved
0N/A * via <code>MidiSystem</code>.
0N/A *
0N/A * @see #open
0N/A * @see #isOpen
0N/A */
0N/A public void close();
0N/A
0N/A
0N/A /**
0N/A * Reports whether the device is open.
0N/A *
0N/A * @return <code>true</code> if the device is open, otherwise
0N/A * <code>false</code>
0N/A * @see #open
0N/A * @see #close
0N/A */
0N/A public boolean isOpen();
0N/A
0N/A
0N/A /**
0N/A * Obtains the current time-stamp of the device, in microseconds.
0N/A * If a device supports time-stamps, it should start counting at
0N/A * 0 when the device is opened and continue incrementing its
0N/A * time-stamp in microseconds until the device is closed.
0N/A * If it does not support time-stamps, it should always return
0N/A * -1.
0N/A * @return the current time-stamp of the device in microseconds,
0N/A * or -1 if time-stamping is not supported by the device.
0N/A */
0N/A public long getMicrosecondPosition();
0N/A
0N/A
0N/A /**
0N/A * Obtains the maximum number of MIDI IN connections available on this
0N/A * MIDI device for receiving MIDI data.
0N/A * @return maximum number of MIDI IN connections,
0N/A * or -1 if an unlimited number of connections is available.
0N/A */
0N/A public int getMaxReceivers();
0N/A
0N/A
0N/A /**
0N/A * Obtains the maximum number of MIDI OUT connections available on this
0N/A * MIDI device for transmitting MIDI data.
0N/A * @return maximum number of MIDI OUT connections,
0N/A * or -1 if an unlimited number of connections is available.
0N/A */
0N/A public int getMaxTransmitters();
0N/A
0N/A
0N/A /**
0N/A * Obtains a MIDI IN receiver through which the MIDI device may receive
0N/A * MIDI data. The returned receiver must be closed when the application
0N/A * has finished using it.
0N/A *
2719N/A * <p>Usually the returned receiver implements
2719N/A * the {@code MidiDeviceReceiver} interface.
2719N/A *
0N/A * <p>Obtaining a <code>Receiver</code> with this method does not
0N/A * open the device. To be able to use the device, it has to be
0N/A * opened explicitly by calling {@link #open}. Also, closing the
0N/A * <code>Receiver</code> does not close the device. It has to be
0N/A * closed explicitly by calling {@link #close}.
0N/A *
0N/A * @return a receiver for the device.
0N/A * @throws MidiUnavailableException thrown if a receiver is not available
0N/A * due to resource restrictions
0N/A * @see Receiver#close()
0N/A */
0N/A public Receiver getReceiver() throws MidiUnavailableException;
0N/A
0N/A
0N/A /**
0N/A * Returns all currently active, non-closed receivers
0N/A * connected with this MidiDevice.
0N/A * A receiver can be removed
0N/A * from the device by closing it.
2719N/A *
2719N/A * <p>Usually the returned receivers implement
2719N/A * the {@code MidiDeviceReceiver} interface.
2719N/A *
0N/A * @return an unmodifiable list of the open receivers
0N/A * @since 1.5
0N/A */
0N/A List<Receiver> getReceivers();
0N/A
0N/A
0N/A /**
0N/A * Obtains a MIDI OUT connection from which the MIDI device will transmit
0N/A * MIDI data The returned transmitter must be closed when the application
0N/A * has finished using it.
0N/A *
2719N/A * <p>Usually the returned transmitter implements
2719N/A * the {@code MidiDeviceTransmitter} interface.
2719N/A *
0N/A * <p>Obtaining a <code>Transmitter</code> with this method does not
0N/A * open the device. To be able to use the device, it has to be
0N/A * opened explicitly by calling {@link #open}. Also, closing the
0N/A * <code>Transmitter</code> does not close the device. It has to be
0N/A * closed explicitly by calling {@link #close}.
0N/A *
0N/A * @return a MIDI OUT transmitter for the device.
0N/A * @throws MidiUnavailableException thrown if a transmitter is not available
0N/A * due to resource restrictions
0N/A * @see Transmitter#close()
0N/A */
0N/A public Transmitter getTransmitter() throws MidiUnavailableException;
0N/A
0N/A
0N/A /**
0N/A * Returns all currently active, non-closed transmitters
0N/A * connected with this MidiDevice.
0N/A * A transmitter can be removed
0N/A * from the device by closing it.
2719N/A *
2719N/A * <p>Usually the returned transmitters implement
2719N/A * the {@code MidiDeviceTransmitter} interface.
2719N/A *
0N/A * @return an unmodifiable list of the open transmitters
0N/A * @since 1.5
0N/A */
0N/A List<Transmitter> getTransmitters();
0N/A
0N/A
0N/A
0N/A /**
0N/A * A <code>MidiDevice.Info</code> object contains assorted
0N/A * data about a <code>{@link MidiDevice}</code>, including its
0N/A * name, the company who created it, and descriptive text.
0N/A *
0N/A * @see MidiDevice#getDeviceInfo
0N/A */
0N/A public static class Info {
0N/A
0N/A /**
0N/A * The device's name.
0N/A */
0N/A private String name;
0N/A
0N/A /**
0N/A * The name of the company who provides the device.
0N/A */
0N/A private String vendor;
0N/A
0N/A /**
0N/A * A description of the device.
0N/A */
0N/A private String description;
0N/A
0N/A /**
0N/A * Device version.
0N/A */
0N/A private String version;
0N/A
0N/A
0N/A /**
0N/A * Constructs a device info object.
0N/A *
0N/A * @param name the name of the device
0N/A * @param vendor the name of the company who provides the device
0N/A * @param description a description of the device
0N/A * @param version version information for the device
0N/A */
0N/A protected Info(String name, String vendor, String description, String version) {
0N/A
0N/A this.name = name;
0N/A this.vendor = vendor;
0N/A this.description = description;
0N/A this.version = version;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Reports whether two objects are equal.
0N/A * Returns <code>true</code> if the objects are identical.
0N/A * @param obj the reference object with which to compare this
0N/A * object
0N/A * @return <code>true</code> if this object is the same as the
0N/A * <code>obj</code> argument; <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 * Obtains the name of the device.
0N/A *
0N/A * @return a string containing the device's name
0N/A */
0N/A public final String getName() {
0N/A return name;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains the name of the company who supplies the device.
0N/A * @return device the vendor's name
0N/A */
0N/A public final String getVendor() {
0N/A return vendor;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains the description of the device.
0N/A * @return a description of the device
0N/A */
0N/A public final String getDescription() {
0N/A return description;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains the version of the device.
0N/A * @return textual version information for the device.
0N/A */
0N/A public final String getVersion() {
0N/A return version;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Provides a string representation of the device information.
0N/A
0N/A * @return a description of the info object
0N/A */
0N/A public final String toString() {
0N/A return name;
0N/A }
0N/A } // class Info
0N/A
0N/A
0N/A}