org.tritonus.share.midi
Class TMidiDevice

java.lang.Object
  extended byorg.tritonus.share.midi.TMidiDevice
All Implemented Interfaces:
MidiDevice
Direct Known Subclasses:
AlsaMidiDevice, TDirectSynthesizer, TSequencer

public abstract class TMidiDevice
extends Object
implements MidiDevice

Base class for MidiDevice implementations. The goal of this class is to supply the common functionality for classes that implement the interface MidiDevice.


Nested Class Summary
static class TMidiDevice.Info
           
 class TMidiDevice.TReceiver
          Receiver proxy class.
 class TMidiDevice.TTransmitter
           
 
Constructor Summary
TMidiDevice(MidiDevice.Info info)
          Initialize this class.
TMidiDevice(MidiDevice.Info info, boolean bUseIn, boolean bUseOut)
          Initialize this class.
 
Method Summary
 void close()
           
protected  void closeImpl()
          Subclasses have to override this method to be notified of closeing.
 MidiDevice.Info getDeviceInfo()
          Retrieves a description of this instance.
 int getMaxReceivers()
           
 int getMaxTransmitters()
           
 long getMicrosecondPosition()
          Returns the device time in microseconds.
 Receiver getReceiver()
          Creates a new Receiver object associated with this instance.
 List<Receiver> getReceivers()
           
 Transmitter getTransmitter()
          Creates a new Transmitter object associated with this instance.
 List<Transmitter> getTransmitters()
           
protected  boolean getUseIn()
          Returns whether to handle input.
protected  boolean getUseOut()
          Returns whether to handle output.
 boolean isOpen()
           
 void open()
           
protected  void openImpl()
          Subclasses have to override this method to be notified of opening.
protected  void receive(MidiMessage message, long lTimeStamp)
           
protected  void sendImpl(MidiMessage message, long lTimeStamp)
          Send a MidiMessage to all Transmitters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TMidiDevice

public TMidiDevice(MidiDevice.Info info)
Initialize this class. This sets the info from the passed one, sets the open status to false, the number of Receivers to zero and the collection of Transmitters to be empty.

Parameters:
info - The info object that describes this instance.

TMidiDevice

public TMidiDevice(MidiDevice.Info info,
                   boolean bUseIn,
                   boolean bUseOut)
Initialize this class. This sets the info from the passed one, sets the open status to false, the number of Receivers to zero and the collection of Transmitters to be empty.

Parameters:
info - The info object that describes this instance.
Method Detail

getDeviceInfo

public MidiDevice.Info getDeviceInfo()
Retrieves a description of this instance. This returns the info object passed to the constructor.

Specified by:
getDeviceInfo in interface MidiDevice
Returns:
the description
See Also:
TMidiDevice(javax.sound.midi.MidiDevice.Info, boolean, boolean)

open

public void open()
          throws MidiUnavailableException
Specified by:
open in interface MidiDevice
Throws:
MidiUnavailableException

openImpl

protected void openImpl()
                 throws MidiUnavailableException
Subclasses have to override this method to be notified of opening.

Throws:
MidiUnavailableException

close

public void close()
Specified by:
close in interface MidiDevice

closeImpl

protected void closeImpl()
Subclasses have to override this method to be notified of closeing.


isOpen

public boolean isOpen()
Specified by:
isOpen in interface MidiDevice

getUseIn

protected boolean getUseIn()
Returns whether to handle input. If this is true, retrieving Transmitters is possible and input from the physical port is passed to them.

See Also:
getUseOut()

getUseOut

protected boolean getUseOut()
Returns whether to handle output. If this is true, retrieving Receivers is possible and output to them is passed to the physical port.

See Also:
getUseIn()

getMicrosecondPosition

public long getMicrosecondPosition()
Returns the device time in microseconds. This is a default implementation, telling the application program that the device doesn't track time. If a device wants to give timing information, it has to override this method.

Specified by:
getMicrosecondPosition in interface MidiDevice

getMaxReceivers

public int getMaxReceivers()
Specified by:
getMaxReceivers in interface MidiDevice

getMaxTransmitters

public int getMaxTransmitters()
Specified by:
getMaxTransmitters in interface MidiDevice

getReceiver

public Receiver getReceiver()
                     throws MidiUnavailableException
Creates a new Receiver object associated with this instance. In this implementation, an unlimited number of Receivers per MidiDevice can be created.

Specified by:
getReceiver in interface MidiDevice
Throws:
MidiUnavailableException

getTransmitter

public Transmitter getTransmitter()
                           throws MidiUnavailableException
Creates a new Transmitter object associated with this instance. In this implementation, an unlimited number of Transmitters per MidiDevice can be created.

Specified by:
getTransmitter in interface MidiDevice
Throws:
MidiUnavailableException

getReceivers

public List<Receiver> getReceivers()
Specified by:
getReceivers in interface MidiDevice

getTransmitters

public List<Transmitter> getTransmitters()
Specified by:
getTransmitters in interface MidiDevice

receive

protected void receive(MidiMessage message,
                       long lTimeStamp)

sendImpl

protected void sendImpl(MidiMessage message,
                        long lTimeStamp)
Send a MidiMessage to all Transmitters. This method should be called by subclasses when they get a message from a physical MIDI port.