APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.media.sound

pack-priv abstract Class AbstractMidiDevice

extends Object
implements MidiDevice, ReferenceCountingDevice
Class Inheritance
All Implemented Interfaces
com.sun.media.sound.ReferenceCountingDevice, javax.sound.midi.MidiDevice, java.lang.AutoCloseable
Known Direct Subclasses
com.sun.media.sound.MidiInDevice, com.sun.media.sound.MidiOutDevice, com.sun.media.sound.RealTimeSequencer
Imports
java.util.ArrayList, .Collections, .List, javax.sound.midi.InvalidMidiDataException, .MidiDevice, .MidiDeviceReceiver, .MidiDeviceTransmitter, .MidiMessage, .MidiUnavailableException, .Receiver, .Transmitter

Abstract AbstractMidiDevice class representing functionality shared by MidiInDevice and MidiOutDevice objects.
Authors
David Rivas, Kara Kytle, Matthias Pfisterer, Florian Bomers

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract class
AbstractMidiDevice.AbstractReceiver

Base class for Receivers.

pack-priv class
AbstractMidiDevice.BasicTransmitter

Transmitter base class.

pack-priv class
AbstractMidiDevice.TransmitterList

a class to manage a list of transmitters.

Field Summary

Modifier and TypeField and Description
protected volatile long
id

This is the device handle returned from native code.

private final MidiDevice.Info
private volatile boolean
private List<Object>
openKeepingObjects

List of Receivers and Transmitters that opened the device implicitly.

private int
private ArrayList<Receiver>
private AbstractMidiDevice.TransmitterList
private final Object

Constructor Summary

AccessConstructor and Description
protected
AbstractMidiDevice(MidiDevice.Info
the description of the device
info
)

Constructs an AbstractMidiDevice with the specified info object.

Method Summary

Modifier and TypeMethod and Description
public final void
close()

Implements javax.sound.midi.MidiDevice.close.

Closes the device, indicating that the device should now release any system resources it is using.

public final void
closeInternal(Object
The object that might have been opening the device implicitly (for now, this may be a Transmitter or receiver).
object
)

Close the device for an object that implicitly opened it.

protected Receiver
createReceiver()

Create a Receiver object.

protected Transmitter
createTransmitter()

Create a Transmitter object.

public final void
private void
protected final void
finalize()

Overrides java.lang.Object.finalize.

close this device if discarded by the garbage collector.

public final MidiDevice.Info
getDeviceInfo()

Implements javax.sound.midi.MidiDevice.getDeviceInfo.

Obtains information about the device, including its Java class and Strings containing its name, vendor, and description.

pack-priv final long
public final int
getMaxReceivers()

Implements javax.sound.midi.MidiDevice.getMaxReceivers.

Return the maximum number of Receivers supported by this device.

public final int
getMaxTransmitters()

Implements javax.sound.midi.MidiDevice.getMaxTransmitters.

Return the maximum number of Transmitters supported by this device.

public long
getMicrosecondPosition()

Implements javax.sound.midi.MidiDevice.getMicrosecondPosition.

This implementation always returns -1.

private synchronized List<Object>
getOpenKeepingObjects()

Return the list of objects that have opened the device implicitly.

public final Receiver
getReceiver()

Implements javax.sound.midi.MidiDevice.getReceiver.

Retrieve a Receiver for this device.

private List<Receiver>
getReceiverList()

Return the internal list of Receivers, possibly creating it first.

public final Receiver
getReceiverReferenceCounting()

Implements com.sun.media.sound.ReferenceCountingDevice.getReceiverReferenceCounting.

Retrieve a Receiver and open the device implicitly.

public final List<Receiver>
getReceivers()

Implements javax.sound.midi.MidiDevice.getReceivers.

Returns all currently active, non-closed receivers connected with this MidiDevice.

public final Transmitter
getTransmitter()

Implements javax.sound.midi.MidiDevice.getTransmitter.

This implementation uses createTransmitter, which may throw an exception.

pack-priv final AbstractMidiDevice.TransmitterList
getTransmitterList()

Return the internal list of Transmitters, possibly creating it first.

public final Transmitter
public final List<Transmitter>
getTransmitters()

Implements javax.sound.midi.MidiDevice.getTransmitters.

Returns all currently active, non-closed transmitters connected with this MidiDevice.

protected boolean

Returns:

true, if the device supports Receivers, false otherwise.
hasReceivers
()

Returns if this device supports Receivers.

protected boolean

Returns:

true, if the device supports Transmitters, false otherwise.
hasTransmitters
()

Returns if this device supports Transmitters.

protected void
protected abstract void
public final boolean
isOpen()

Implements javax.sound.midi.MidiDevice.isOpen.

Reports whether the device is open.

public final void
open()

Implements javax.sound.midi.MidiDevice.open.

Open the device from an application program.

private void
openInternal(Object object)

Open the device implicitly.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

idback to summary
protected volatile long id

This is the device handle returned from native code.

infoback to summary
private final MidiDevice.Info info
openback to summary
private volatile boolean open
openKeepingObjectsback to summary
private List<Object> openKeepingObjects

List of Receivers and Transmitters that opened the device implicitly.

openRefCountback to summary
private int openRefCount
receiverListback to summary
private ArrayList<Receiver> receiverList
transmitterListback to summary
private AbstractMidiDevice.TransmitterList transmitterList
traRecLockback to summary
private final Object traRecLock

Constructor Detail

AbstractMidiDeviceback to summary
protected AbstractMidiDevice(MidiDevice.Info info)

Constructs an AbstractMidiDevice with the specified info object.

Parameters
info:MidiDevice.Info

the description of the device

Method Detail

closeback to summary
public final void close()

Implements javax.sound.midi.MidiDevice.close.

Doc from javax.sound.midi.MidiDevice.close.

Closes the device, indicating that the device should now release any system resources it is using.

All Receiver and Transmitter instances open from this device are closed. This includes instances retrieved via MidiSystem.

Annotations
@Override
closeInternalback to summary
public final void closeInternal(Object object)

Close the device for an object that implicitly opened it. This method is intended to be used by Transmitter.close() and Receiver.close(). Those methods should pass this for the object parameter. Since Transmitters or Receivers do not know if their device has been opened implicitly because of them, they call this method in any case. This method now is able to separate Receivers/Transmitters that opened the device implicitly from those that didn't by looking up the R/T in the openKeepingObjects list. Only if the R/T is contained there, the reference count is reduced.

Parameters
object:Object

The object that might have been opening the device implicitly (for now, this may be a Transmitter or receiver).

createReceiverback to summary
protected Receiver createReceiver() throws MidiUnavailableException

Create a Receiver object. throwing an exception here means that Receivers aren't enabled. Subclasses that use Receivers should override this method with one that returns objects implementing Receiver. Classes overriding this method should also override hasReceivers() to return true.

createTransmitterback to summary
protected Transmitter createTransmitter() throws MidiUnavailableException

Create a Transmitter object. throwing an exception here means that Transmitters aren't enabled. Subclasses that use Transmitters should override this method with one that returns objects implementing Transmitters. Classes overriding this method should also override hasTransmitters() to return true.

doCloseback to summary
public final void doClose()
doOpenback to summary
private void doOpen() throws MidiUnavailableException
finalizeback to summary
protected final void finalize()

Overrides java.lang.Object.finalize.

close this device if discarded by the garbage collector.

Annotations
@Override
@SuppressWarnings:removal
getDeviceInfoback to summary
public final MidiDevice.Info getDeviceInfo()

Implements javax.sound.midi.MidiDevice.getDeviceInfo.

Doc from javax.sound.midi.MidiDevice.getDeviceInfo.

Obtains information about the device, including its Java class and Strings containing its name, vendor, and description.

Annotations
@Override
getIdback to summary
pack-priv final long getId()
getMaxReceiversback to summary
public final int getMaxReceivers()

Implements javax.sound.midi.MidiDevice.getMaxReceivers.

Return the maximum number of Receivers supported by this device. Depending on the return value of hasReceivers(), this method returns either 0 or -1. Subclasses should rather override hasReceivers() than override this method.

Annotations
@Override
getMaxTransmittersback to summary
public final int getMaxTransmitters()

Implements javax.sound.midi.MidiDevice.getMaxTransmitters.

Return the maximum number of Transmitters supported by this device. Depending on the return value of hasTransmitters(), this method returns either 0 or -1. Subclasses should override hasTransmitters().

Annotations
@Override
getMicrosecondPositionback to summary
public long getMicrosecondPosition()

Implements javax.sound.midi.MidiDevice.getMicrosecondPosition.

This implementation always returns -1. Devices that actually provide this should over-ride this method.

Annotations
@Override
getOpenKeepingObjectsback to summary
private synchronized List<Object> getOpenKeepingObjects()

Return the list of objects that have opened the device implicitly.

getReceiverback to summary
public final Receiver getReceiver() throws MidiUnavailableException

Implements javax.sound.midi.MidiDevice.getReceiver.

Retrieve a Receiver for this device. This method returns the value returned by createReceiver(), if it doesn't throw an exception. Subclasses should rather override createReceiver() than override this method. If createReceiver returns a Receiver, it is added to the internal list of Receivers (see getReceiversList)

Annotations
@Override
Exceptions
MidiUnavailableException:

Doc from javax.sound.midi.MidiDevice.getReceiver.

thrown if a receiver is not available due to resource restrictions

getReceiverListback to summary
private List<Receiver> getReceiverList()

Return the internal list of Receivers, possibly creating it first.

getReceiverReferenceCountingback to summary
public final Receiver getReceiverReferenceCounting() throws MidiUnavailableException

Implements com.sun.media.sound.ReferenceCountingDevice.getReceiverReferenceCounting.

Retrieve a Receiver and open the device implicitly. This method is called by MidiSystem.getReceiver().

Annotations
@Override
getReceiversback to summary
public final List<Receiver> getReceivers()

Implements javax.sound.midi.MidiDevice.getReceivers.

Doc from javax.sound.midi.MidiDevice.getReceivers.

Returns all currently active, non-closed receivers connected with this MidiDevice. A receiver can be removed from the device by closing it.

Usually the returned receivers implement the MidiDeviceReceiver interface.

Annotations
@Override
@SuppressWarnings:unchecked
getTransmitterback to summary
public final Transmitter getTransmitter() throws MidiUnavailableException

Implements javax.sound.midi.MidiDevice.getTransmitter.

This implementation uses createTransmitter, which may throw an exception. If a transmitter is returned in createTransmitter, it is added to the internal TransmitterList

Annotations
@Override
Exceptions
MidiUnavailableException:

Doc from javax.sound.midi.MidiDevice.getTransmitter.

thrown if a transmitter is not available due to resource restrictions

getTransmitterListback to summary
pack-priv final AbstractMidiDevice.TransmitterList getTransmitterList()

Return the internal list of Transmitters, possibly creating it first.

getTransmitterReferenceCountingback to summary
public final Transmitter getTransmitterReferenceCounting() throws MidiUnavailableException

Implements com.sun.media.sound.ReferenceCountingDevice.getTransmitterReferenceCounting.

Retrieve a Transmitter and open the device implicitly. This method is called by MidiSystem.getTransmitter().

Annotations
@Override
getTransmittersback to summary
public final List<Transmitter> getTransmitters()

Implements javax.sound.midi.MidiDevice.getTransmitters.

Doc from javax.sound.midi.MidiDevice.getTransmitters.

Returns all currently active, non-closed transmitters connected with this MidiDevice. A transmitter can be removed from the device by closing it.

Usually the returned transmitters implement the MidiDeviceTransmitter interface.

Annotations
@Override
@SuppressWarnings:unchecked
hasReceiversback to summary
protected boolean hasReceivers()

Returns if this device supports Receivers. Subclasses that use Receivers should override this method to return true. They also should override createReceiver().

Returns:boolean

true, if the device supports Receivers, false otherwise.

hasTransmittersback to summary
protected boolean hasTransmitters()

Returns if this device supports Transmitters. Subclasses that use Transmitters should override this method to return true. They also should override createTransmitter().

Returns:boolean

true, if the device supports Transmitters, false otherwise.

implCloseback to summary
protected void implClose()
implOpenback to summary
protected abstract void implOpen() throws MidiUnavailableException
isOpenback to summary
public final boolean isOpen()

Implements javax.sound.midi.MidiDevice.isOpen.

Doc from javax.sound.midi.MidiDevice.isOpen.

Reports whether the device is open.

Annotations
@Override
openback to summary
public final void open() throws MidiUnavailableException

Implements javax.sound.midi.MidiDevice.open.

Open the device from an application program. Setting the open reference count to -1 here prevents Transmitters and Receivers that opened the device implicitly from closing it. The only way to close the device after this call is a call to close().

Annotations
@Override
Exceptions
MidiUnavailableException:

Doc from javax.sound.midi.MidiDevice.open.

thrown if the device cannot be opened due to resource restrictions

openInternalback to summary
private void openInternal(Object object) throws MidiUnavailableException

Open the device implicitly. This method is intended to be used by AbstractReceiver and BasicTransmitter. Actually, it is called by getReceiverReferenceCounting() and getTransmitterReferenceCounting(). These, in turn, are called by MidiSytem on calls to getReceiver() and getTransmitter(). The former methods should pass the Receiver or Transmitter just created as the object parameter to this method. Storing references to these objects is necessary to be able to decide later (when it comes to closing) if R/T's are ones that opened the device implicitly.

com.sun.media.sound back to summary

pack-priv abstract Class AbstractMidiDevice.AbstractReceiver

extends Object
implements MidiDeviceReceiver
Class Inheritance
All Implemented Interfaces
javax.sound.midi.MidiDeviceReceiver, javax.sound.midi.Receiver, java.lang.AutoCloseable
Known Direct Subclasses
com.sun.media.sound.MidiOutDevice.MidiOutReceiver, com.sun.media.sound.RealTimeSequencer.SequencerReceiver

Base class for Receivers. Subclasses that use Receivers must use this base class, since it contains magic necessary to manage implicit closing the device. This is necessary for Receivers retrieved via MidiSystem.getReceiver() (which opens the device implicitly).

Field Summary

Modifier and TypeField and Description
private volatile boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final void
close()

Implements javax.sound.midi.Receiver.close.

Close the Receiver.

public final MidiDevice
getMidiDevice()

Implements javax.sound.midi.MidiDeviceReceiver.getMidiDevice.

Obtains a MidiDevice object which is an owner of this Receiver.

pack-priv abstract void
implSend(MidiMessage message, long timeStamp)

pack-priv final boolean
public final synchronized void
send(final MidiMessage message, final long timeStamp)

Implements javax.sound.midi.Receiver.send.

Deliver a MidiMessage.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

openback to summary
private volatile boolean open

Constructor Detail

AbstractReceiverback to summary
pack-priv AbstractReceiver()

Method Detail

closeback to summary
public final void close()

Implements javax.sound.midi.Receiver.close.

Close the Receiver. Here, the call to the magic method closeInternal() takes place. Therefore, subclasses that override this method must call 'super.close()'.

Annotations
@Override
getMidiDeviceback to summary
public final MidiDevice getMidiDevice()

Implements javax.sound.midi.MidiDeviceReceiver.getMidiDevice.

Doc from javax.sound.midi.MidiDeviceReceiver.getMidiDevice.

Obtains a MidiDevice object which is an owner of this Receiver.

Annotations
@Override
implSendback to summary
pack-priv abstract void implSend(MidiMessage message, long timeStamp)
isOpenback to summary
pack-priv final boolean isOpen()
sendback to summary
public final synchronized void send(final MidiMessage message, final long timeStamp)

Implements javax.sound.midi.Receiver.send.

Deliver a MidiMessage. This method contains magic related to the closed state of a Receiver. Therefore, subclasses should not override this method. Instead, they should implement implSend().

Annotations
@Override
com.sun.media.sound back to summary

pack-priv Class AbstractMidiDevice.BasicTransmitter

extends Object
implements MidiDeviceTransmitter
Class Inheritance
All Implemented Interfaces
javax.sound.midi.MidiDeviceTransmitter, javax.sound.midi.Transmitter, java.lang.AutoCloseable
Known Direct Subclasses
com.sun.media.sound.MidiInDevice.MidiInTransmitter, com.sun.media.sound.RealTimeSequencer.SequencerTransmitter

Transmitter base class. This class especially makes sure the device is closed if it has been opened implicitly by a call to MidiSystem.getTransmitter(). The logic of doing so is actually in closeInternal(). Also, it has some optimizations regarding sending to the Receivers, for known Receivers, and managing itself in the TransmitterList.

Field Summary

Modifier and TypeField and Description
private Receiver
pack-priv AbstractMidiDevice.TransmitterList

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public final void
close()

Implements javax.sound.midi.Transmitter.close.

Close the Transmitter.

public final MidiDevice
getMidiDevice()

Implements javax.sound.midi.MidiDeviceTransmitter.getMidiDevice.

Obtains a MidiDevice object which is an owner of this Transmitter.

public final Receiver
getReceiver()

Implements javax.sound.midi.Transmitter.getReceiver.

Obtains the current receiver to which this transmitter will deliver MIDI messages.

public final void
setReceiver(Receiver receiver)

Implements javax.sound.midi.Transmitter.setReceiver.

Sets the receiver to which this transmitter will deliver MIDI messages.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

receiverback to summary
private Receiver receiver
tlistback to summary
pack-priv AbstractMidiDevice.TransmitterList tlist

Constructor Detail

BasicTransmitterback to summary
protected BasicTransmitter()

Method Detail

closeback to summary
public final void close()

Implements javax.sound.midi.Transmitter.close.

Close the Transmitter. Here, the call to the magic method closeInternal() takes place. Therefore, subclasses that override this method must call 'super.close()'.

Annotations
@Override
getMidiDeviceback to summary
public final MidiDevice getMidiDevice()

Implements javax.sound.midi.MidiDeviceTransmitter.getMidiDevice.

Doc from javax.sound.midi.MidiDeviceTransmitter.getMidiDevice.

Obtains a MidiDevice object which is an owner of this Transmitter.

Annotations
@Override
getReceiverback to summary
public final Receiver getReceiver()

Implements javax.sound.midi.Transmitter.getReceiver.

Doc from javax.sound.midi.Transmitter.getReceiver.

Obtains the current receiver to which this transmitter will deliver MIDI messages.

Annotations
@Override
setReceiverback to summary
public final void setReceiver(Receiver receiver)

Implements javax.sound.midi.Transmitter.setReceiver.

Doc from javax.sound.midi.Transmitter.setReceiver.

Sets the receiver to which this transmitter will deliver MIDI messages. If a receiver is currently set, it is replaced with this one.

Annotations
@Override
setTransmitterListback to summary
private void setTransmitterList(AbstractMidiDevice.TransmitterList tlist)
com.sun.media.sound back to summary

pack-priv final Class AbstractMidiDevice.TransmitterList

extends Object
Class Inheritance

a class to manage a list of transmitters.

Field Summary

Modifier and TypeField and Description
private MidiOutDevice.MidiOutReceiver
private int
private final ArrayList<Transmitter>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
pack-priv void
close()

closes all transmitters and empties the list

private void
private void
pack-priv void
sendMessage(int packedMessage, long timeStamp)

Send this message to all receivers status = packedMessage & 0xFF data1 = (packedMessage & 0xFF00) >> 8; data1 = (packedMessage & 0xFF0000) >> 16;

pack-priv void
sendMessage(byte[] data, long timeStamp)

pack-priv void
sendMessage(MidiMessage message, long timeStamp)

Send this message to all transmitters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

midiOutReceiverback to summary
private MidiOutDevice.MidiOutReceiver midiOutReceiver
optimizedReceiverCountback to summary
private int optimizedReceiverCount
transmittersback to summary
private final ArrayList<Transmitter> transmitters

Constructor Detail

TransmitterListback to summary
pack-priv TransmitterList()

Method Detail

addback to summary
private void add(Transmitter t)
closeback to summary
pack-priv void close()

closes all transmitters and empties the list

receiverChangedback to summary
private void receiverChanged(AbstractMidiDevice.BasicTransmitter t, Receiver oldR, Receiver newR)
removeback to summary
private void remove(Transmitter t)
sendMessageback to summary
pack-priv void sendMessage(int packedMessage, long timeStamp)

Send this message to all receivers status = packedMessage & 0xFF data1 = (packedMessage & 0xFF00) >> 8; data1 = (packedMessage & 0xFF0000) >> 16;

sendMessageback to summary
pack-priv void sendMessage(byte[] data, long timeStamp)
sendMessageback to summary
pack-priv void sendMessage(MidiMessage message, long timeStamp)

Send this message to all transmitters.