MidiDevice
is the base interface for all MIDI devices. Common devices
include synthesizers, sequencers, MIDI input ports, and MIDI output ports.
A MidiDevice
can be a transmitter or a receiver of MIDI events, or
both. Therefore, it can provide Transmitter
or Receiver
instances (or both). Typically, MIDI IN ports provide transmitters, MIDI OUT
ports and synthesizers provide receivers. A Sequencer typically provides
transmitters for playback and receivers for recording.
A MidiDevice
can be opened and closed explicitly as well as
implicitly. Explicit opening is accomplished by calling open
,
explicit closing is done by calling close
on the MidiDevice
instance. If an application opens a MidiDevice
explicitly, it has to
close it explicitly to free system resources and enable the application to
exit cleanly. Implicit opening is done by calling
MidiSystem#getReceiver
and MidiSystem#getTransmitter
. The
MidiDevice
used by MidiSystem.getReceiver
and
MidiSystem.getTransmitter
is implementation-dependent unless the
properties javax.sound.midi.Receiver
and
javax.sound.midi.Transmitter
are used (see the description of
properties to select default providers in MidiSystem
). A
MidiDevice
that was opened implicitly, is closed implicitly by
closing the Receiver
or Transmitter
that resulted in opening
it. If more than one implicitly opening Receiver
or
Transmitter
were obtained by the application, the device is closed
after the last Receiver
or Transmitter
has been closed. On
the other hand, calling getReceiver
or getTransmitter
on the
device instance directly does not open the device implicitly. Closing these
Transmitter
s and Receiver
s does not close the device
implicitly. To use a device with Receiver
s or Transmitter
s
obtained this way, the device has to be opened and closed explicitly.
If implicit and explicit opening and closing are mixed on the same
MidiDevice
instance, the following rules apply:
MidiDevice device = ...;
if (!(device instanceof Sequencer) && !(device instanceof Synthesizer)) {
// we're now sure that device represents a MIDI port
// ...
}
A MidiDevice
includes a Info
object to provide manufacturer
information and so on.
Synthesizer
, Sequencer
, Receiver
, Transmitter
Modifier and Type | Class and Description |
---|---|
public static class | MidiDevice.
A |
Modifier and Type | Method and Description |
---|---|
public void | close()
Redeclares java. Closes the device, indicating that the device should now release any system resources it is using. |
public MidiDevice. | Returns: device infoObtains information about the device, including its Java class and
|
public int | Returns: maximum number of MIDI IN connections, or -1 if an unlimited number of connections is availableObtains the maximum number of MIDI IN connections available on this MIDI device for receiving MIDI data. |
public int | Returns: maximum number of MIDI OUT connections, or -1 if an unlimited number of connections is availableObtains the maximum number of MIDI OUT connections available on this MIDI device for transmitting MIDI data. |
public long | Returns: the current time-stamp of the device in microseconds, or -1 if time-stamping is not supported by the deviceObtains the current time-stamp of the device, in microseconds. |
public Receiver | Returns: a receiver for the deviceObtains a MIDI IN receiver through which the MIDI device may receive MIDI data. |
public List | Returns: an unmodifiable list of the open receiversReturns all currently active, non-closed receivers connected with this
|
public Transmitter | Returns: a MIDI OUT transmitter for the deviceObtains a MIDI OUT connection from which the MIDI device will transmit MIDI data. |
public List | Returns: an unmodifiable list of the open transmittersReturns all currently active, non-closed transmitters connected with this
|
public boolean | |
public void | open()
Opens the device, indicating that it should now acquire any system resources it requires and become operational. |
close | back to summary |
---|---|
public void close() Redeclares java. Closes the device, indicating that the device should now release any system resources it is using.
All |
getDeviceInfo | back to summary |
---|---|
public MidiDevice. Obtains information about the device, including its Java class and
|
getMaxReceivers | back to summary |
---|---|
public int getMaxReceivers() Obtains the maximum number of MIDI IN connections available on this MIDI device for receiving MIDI data.
|
getMaxTransmitters | back to summary |
---|---|
public int getMaxTransmitters() Obtains the maximum number of MIDI OUT connections available on this MIDI device for transmitting MIDI data.
|
getMicrosecondPosition | back to summary |
---|---|
public long getMicrosecondPosition() Obtains the current time-stamp of the device, in microseconds. If a device supports time-stamps, it should start counting at 0 when the device is opened and continue incrementing its time-stamp in microseconds until the device is closed. If it does not support time-stamps, it should always return -1.
|
getReceiver | back to summary |
---|---|
public Receiver getReceiver() throws MidiUnavailableException Obtains a MIDI IN receiver through which the MIDI device may receive MIDI data. The returned receiver must be closed when the application has finished using it.
Usually the returned receiver implements the
Obtaining a
|
getReceivers | back to summary |
---|---|
public List Returns all currently active, non-closed receivers connected with this
Usually the returned receivers implement the |
getTransmitter | back to summary |
---|---|
public Transmitter getTransmitter() throws MidiUnavailableException Obtains a MIDI OUT connection from which the MIDI device will transmit MIDI data. The returned transmitter must be closed when the application has finished using it.
Usually the returned transmitter implements the
Obtaining a
|
getTransmitters | back to summary |
---|---|
public List Returns all currently active, non-closed transmitters connected with this
Usually the returned transmitters implement the
|
isOpen | back to summary |
---|---|
public boolean isOpen() Reports whether the device is open. |
open | back to summary |
---|---|
public void open() throws MidiUnavailableException Opens the device, indicating that it should now acquire any system resources it requires and become operational.
An application opening a device explicitly with this call has to close
the device by calling
Note that some devices, once closed, cannot be reopened. Attempts to
reopen such a device will always result in a
|
MidiDevice.Info
object contains assorted data about a
MidiDevice
, including its name, the company who created it, and
descriptive text.
MidiDevice#getDeviceInfo
Modifier and Type | Field and Description |
---|---|
private final String | description
A description of the device. |
private final String | name
The device's name. |
private final String | vendor
The name of the company who provides the device. |
private final String | version
Device version. |
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public final boolean | Returns: true if the specified object is equal to this info
object; false otherwisethe reference object with which to compare obj)Overrides java. Indicates whether the specified object is equal to this info object,
returning |
public final String | |
public final String | |
public final String | Returns: device the vendor's nameObtains the name of the company who supplies the device. |
public final String | |
public final int | Returns: a hash code value for this info objectOverrides java. Returns a hash code value for this info object. |
public final String | Returns: a string representation of the info objectOverrides java. Returns a string representation of the info object. |
description | back to summary |
---|---|
private final String description A description of the device. |
name | back to summary |
---|---|
private final String name The device's name. |
vendor | back to summary |
---|---|
private final String vendor The name of the company who provides the device. |
version | back to summary |
---|---|
private final String version Device version. |
Info | back to summary |
---|---|
protected Info(String name, String vendor, String description, String version) Constructs a device info object. |
equals | back to summary |
---|---|
public final boolean equals(Object obj) Overrides java. Indicates whether the specified object is equal to this info object,
returning |
getDescription | back to summary |
---|---|
public final String getDescription() Obtains the description of the device.
|
getName | back to summary |
---|---|
public final String getName() Obtains the name of the device.
|
getVendor | back to summary |
---|---|
public final String getVendor() Obtains the name of the company who supplies the device.
|
getVersion | back to summary |
---|---|
public final String getVersion() Obtains the version of the device.
|
hashCode | back to summary |
---|---|
public final int hashCode() Overrides java. Returns a hash code value for this info object.
|
toString | back to summary |
---|---|
public final String toString() Overrides java. Returns a string representation of the info object. |