Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/midi/MidiDevice.java
38830 views
/*1* Copyright (c) 1999, 2013, 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.midi;2627import java.util.List;2829/**30* <code>MidiDevice</code> is the base interface for all MIDI devices.31* Common devices include synthesizers, sequencers, MIDI input ports, and MIDI32* output ports.33*34* <p>A <code>MidiDevice</code> can be a transmitter or a receiver of35* MIDI events, or both. Therefore, it can provide {@link Transmitter}36* or {@link Receiver} instances (or both). Typically, MIDI IN ports37* provide transmitters, MIDI OUT ports and synthesizers provide38* receivers. A Sequencer typically provides transmitters for playback39* and receivers for recording.40*41* <p>A <code>MidiDevice</code> can be opened and closed explicitly as42* well as implicitly. Explicit opening is accomplished by calling43* {@link #open}, explicit closing is done by calling {@link44* #close} on the <code>MidiDevice</code> instance.45* If an application opens a <code>MidiDevice</code>46* explicitly, it has to close it explicitly to free system resources47* and enable the application to exit cleanly. Implicit opening is48* done by calling {@link javax.sound.midi.MidiSystem#getReceiver49* MidiSystem.getReceiver} and {@link50* javax.sound.midi.MidiSystem#getTransmitter51* MidiSystem.getTransmitter}. The <code>MidiDevice</code> used by52* <code>MidiSystem.getReceiver</code> and53* <code>MidiSystem.getTransmitter</code> is implementation-dependant54* unless the properties <code>javax.sound.midi.Receiver</code>55* and <code>javax.sound.midi.Transmitter</code> are used (see the56* description of properties to select default providers in57* {@link javax.sound.midi.MidiSystem}). A <code>MidiDevice</code>58* that was opened implicitly, is closed implicitly by closing the59* <code>Receiver</code> or <code>Transmitter</code> that resulted in60* opening it. If more than one implicitly opening61* <code>Receiver</code> or <code>Transmitter</code> were obtained by62* the application, the device is closed after the last63* <code>Receiver</code> or <code>Transmitter</code> has been64* closed. On the other hand, calling <code>getReceiver</code> or65* <code>getTransmitter</code> on the device instance directly does66* not open the device implicitly. Closing these67* <code>Transmitter</code>s and <code>Receiver</code>s does not close68* the device implicitly. To use a device with <code>Receiver</code>s69* or <code>Transmitter</code>s obtained this way, the device has to70* be opened and closed explicitly.71*72* <p>If implicit and explicit opening and closing are mixed on the73* same <code>MidiDevice</code> instance, the following rules apply:74*75* <ul>76* <li>After an explicit open (either before or after implicit77* opens), the device will not be closed by implicit closing. The only78* way to close an explicitly opened device is an explicit close.</li>79*80* <li>An explicit close always closes the device, even if it also has81* been opened implicitly. A subsequent implicit close has no further82* effect.</li>83* </ul>84*85* To detect if a MidiDevice represents a hardware MIDI port, the86* following programming technique can be used:87*88* <pre>{@code89* MidiDevice device = ...;90* if ( ! (device instanceof Sequencer) && ! (device instanceof Synthesizer)) {91* // we're now sure that device represents a MIDI port92* // ...93* }94* }</pre>95*96* <p>97* A <code>MidiDevice</code> includes a <code>{@link MidiDevice.Info}</code> object98* to provide manufacturer information and so on.99*100* @see Synthesizer101* @see Sequencer102* @see Receiver103* @see Transmitter104*105* @author Kara Kytle106* @author Florian Bomers107*/108109public interface MidiDevice extends AutoCloseable {110111112/**113* Obtains information about the device, including its Java class and114* <code>Strings</code> containing its name, vendor, and description.115*116* @return device info117*/118public Info getDeviceInfo();119120121/**122* Opens the device, indicating that it should now acquire any123* system resources it requires and become operational.124*125* <p>An application opening a device explicitly with this call126* has to close the device by calling {@link #close}. This is127* necessary to release system resources and allow applications to128* exit cleanly.129*130* <p>131* Note that some devices, once closed, cannot be reopened. Attempts132* to reopen such a device will always result in a MidiUnavailableException.133*134* @throws MidiUnavailableException thrown if the device cannot be135* opened due to resource restrictions.136* @throws SecurityException thrown if the device cannot be137* opened due to security restrictions.138*139* @see #close140* @see #isOpen141*/142public void open() throws MidiUnavailableException;143144145/**146* Closes the device, indicating that the device should now release147* any system resources it is using.148*149* <p>All <code>Receiver</code> and <code>Transmitter</code> instances150* open from this device are closed. This includes instances retrieved151* via <code>MidiSystem</code>.152*153* @see #open154* @see #isOpen155*/156public void close();157158159/**160* Reports whether the device is open.161*162* @return <code>true</code> if the device is open, otherwise163* <code>false</code>164* @see #open165* @see #close166*/167public boolean isOpen();168169170/**171* Obtains the current time-stamp of the device, in microseconds.172* If a device supports time-stamps, it should start counting at173* 0 when the device is opened and continue incrementing its174* time-stamp in microseconds until the device is closed.175* If it does not support time-stamps, it should always return176* -1.177* @return the current time-stamp of the device in microseconds,178* or -1 if time-stamping is not supported by the device.179*/180public long getMicrosecondPosition();181182183/**184* Obtains the maximum number of MIDI IN connections available on this185* MIDI device for receiving MIDI data.186* @return maximum number of MIDI IN connections,187* or -1 if an unlimited number of connections is available.188*/189public int getMaxReceivers();190191192/**193* Obtains the maximum number of MIDI OUT connections available on this194* MIDI device for transmitting MIDI data.195* @return maximum number of MIDI OUT connections,196* or -1 if an unlimited number of connections is available.197*/198public int getMaxTransmitters();199200201/**202* Obtains a MIDI IN receiver through which the MIDI device may receive203* MIDI data. The returned receiver must be closed when the application204* has finished using it.205*206* <p>Usually the returned receiver implements207* the {@code MidiDeviceReceiver} interface.208*209* <p>Obtaining a <code>Receiver</code> with this method does not210* open the device. To be able to use the device, it has to be211* opened explicitly by calling {@link #open}. Also, closing the212* <code>Receiver</code> does not close the device. It has to be213* closed explicitly by calling {@link #close}.214*215* @return a receiver for the device.216* @throws MidiUnavailableException thrown if a receiver is not available217* due to resource restrictions218* @see Receiver#close()219*/220public Receiver getReceiver() throws MidiUnavailableException;221222223/**224* Returns all currently active, non-closed receivers225* connected with this MidiDevice.226* A receiver can be removed227* from the device by closing it.228*229* <p>Usually the returned receivers implement230* the {@code MidiDeviceReceiver} interface.231*232* @return an unmodifiable list of the open receivers233* @since 1.5234*/235List<Receiver> getReceivers();236237238/**239* Obtains a MIDI OUT connection from which the MIDI device will transmit240* MIDI data The returned transmitter must be closed when the application241* has finished using it.242*243* <p>Usually the returned transmitter implements244* the {@code MidiDeviceTransmitter} interface.245*246* <p>Obtaining a <code>Transmitter</code> with this method does not247* open the device. To be able to use the device, it has to be248* opened explicitly by calling {@link #open}. Also, closing the249* <code>Transmitter</code> does not close the device. It has to be250* closed explicitly by calling {@link #close}.251*252* @return a MIDI OUT transmitter for the device.253* @throws MidiUnavailableException thrown if a transmitter is not available254* due to resource restrictions255* @see Transmitter#close()256*/257public Transmitter getTransmitter() throws MidiUnavailableException;258259260/**261* Returns all currently active, non-closed transmitters262* connected with this MidiDevice.263* A transmitter can be removed264* from the device by closing it.265*266* <p>Usually the returned transmitters implement267* the {@code MidiDeviceTransmitter} interface.268*269* @return an unmodifiable list of the open transmitters270* @since 1.5271*/272List<Transmitter> getTransmitters();273274275276/**277* A <code>MidiDevice.Info</code> object contains assorted278* data about a <code>{@link MidiDevice}</code>, including its279* name, the company who created it, and descriptive text.280*281* @see MidiDevice#getDeviceInfo282*/283public static class Info {284285/**286* The device's name.287*/288private String name;289290/**291* The name of the company who provides the device.292*/293private String vendor;294295/**296* A description of the device.297*/298private String description;299300/**301* Device version.302*/303private String version;304305306/**307* Constructs a device info object.308*309* @param name the name of the device310* @param vendor the name of the company who provides the device311* @param description a description of the device312* @param version version information for the device313*/314protected Info(String name, String vendor, String description, String version) {315316this.name = name;317this.vendor = vendor;318this.description = description;319this.version = version;320}321322323/**324* Reports whether two objects are equal.325* Returns <code>true</code> if the objects are identical.326* @param obj the reference object with which to compare this327* object328* @return <code>true</code> if this object is the same as the329* <code>obj</code> argument; <code>false</code> otherwise330*/331public final boolean equals(Object obj) {332return super.equals(obj);333}334335336/**337* Finalizes the hashcode method.338*/339public final int hashCode() {340return super.hashCode();341}342343344/**345* Obtains the name of the device.346*347* @return a string containing the device's name348*/349public final String getName() {350return name;351}352353354/**355* Obtains the name of the company who supplies the device.356* @return device the vendor's name357*/358public final String getVendor() {359return vendor;360}361362363/**364* Obtains the description of the device.365* @return a description of the device366*/367public final String getDescription() {368return description;369}370371372/**373* Obtains the version of the device.374* @return textual version information for the device.375*/376public final String getVersion() {377return version;378}379380381/**382* Provides a string representation of the device information.383384* @return a description of the info object385*/386public final String toString() {387return name;388}389} // class Info390391392}393394395