com.groovemanager.midi
Class MIDIInReceiver

java.lang.Object
  extended by com.groovemanager.midi.MIDIInReceiver
All Implemented Interfaces:
javax.sound.midi.Receiver

class MIDIInReceiver
extends java.lang.Object
implements javax.sound.midi.Receiver

This class is a Receiver implementation for being connected to the MIDI Input of a MIDIManager. When added MIDIListeners to an instance of this class, it will ask the MIDIManager to open the input device. When all listeners have been removed, it will ask the MIDIManager to clode the input device. For an instance of this class the status bytes of the types of MIDI messages to listen to can be set. Also for any MIDIListener added to this instance, the accepted message types can be set. But a MIDIListener will not be notified of messages the MIDIInReceiver doesn´t acccept, even if he supports them.

Author:
Manu Robledo

Field Summary
private  int[] acceptStatus
          The status bytes of the messages to listen to
private  java.util.HashMap listeners
          The MIDIListeners registered with this Receiver
private  MIDIManager midiManager
          The MIDIManager to which this Receiver is connected
 
Constructor Summary
MIDIInReceiver(MIDIManager manager)
          Construct a new MIDIReciever that listens to all types of MIDI messages on the specified MIDIManager
MIDIInReceiver(MIDIManager manager, int[] acceptStatus)
          Construct a new MIDIReciever that listens to the specified types of MIDI messages on the specified MIDIManager
 
Method Summary
 void addMIDIListener(MIDIListener l, int[] acceptTypes)
          Add a MIDIListener that listens to the specified types of messages
protected static boolean checkStatus(int[] accepted, int status)
          Check, if given status accepted
 void close()
           
protected  void finalize()
           
 int[] getAcceptedStatus()
          Get the MIDI message types accepted by this Receveiver
 void removeMIDIListener(MIDIListener l)
          Remove the specified MIDIListener from the list of listeners.
 void send(javax.sound.midi.MidiMessage message, long timestamp)
           
 void setAcceptStatus(int[] status)
          Set the MIDI message types accepted by this Receveiver
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

acceptStatus

private int[] acceptStatus
The status bytes of the messages to listen to


listeners

private java.util.HashMap listeners
The MIDIListeners registered with this Receiver


midiManager

private final MIDIManager midiManager
The MIDIManager to which this Receiver is connected

Constructor Detail

MIDIInReceiver

MIDIInReceiver(MIDIManager manager)
Construct a new MIDIReciever that listens to all types of MIDI messages on the specified MIDIManager

Parameters:
manager - The MIDIManager to use

MIDIInReceiver

MIDIInReceiver(MIDIManager manager,
               int[] acceptStatus)
Construct a new MIDIReciever that listens to the specified types of MIDI messages on the specified MIDIManager

Parameters:
manager - The MIDIManager to use
acceptStatus - Array of status bytes to accept. Can be any of MetaMessage.META, SysexMessage.SYSTEM_EXCLUSIVE, SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE or ShortMessage.*. The array may also be null to indicate that all types of messages are accepted.
Method Detail

addMIDIListener

public void addMIDIListener(MIDIListener l,
                            int[] acceptTypes)
Add a MIDIListener that listens to the specified types of messages

Parameters:
l - The MIDIListener to add
acceptTypes - Array of status bytes this listener accepts. Can be any of MetaMessage.META, SysexMessage.SYSTEM_EXCLUSIVE, SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE or ShortMessage.*. The array may also be null to indicate that all types of messages are accepted.

checkStatus

protected static boolean checkStatus(int[] accepted,
                                     int status)
Check, if given status accepted

Parameters:
accepted - Array of accepted status bytes or null to indicate that all types of messages are accepted
status - The status byte to check for
Returns:
true, if the given Array is null or if the given status byte is contained inside the Array, false otherwise

close

public void close()
Specified by:
close in interface javax.sound.midi.Receiver
See Also:
Receiver.close()

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable
See Also:
Object.finalize()

getAcceptedStatus

public int[] getAcceptedStatus()
Get the MIDI message types accepted by this Receveiver

Returns:
status Array of status bytes to accept or null to indicate that all types are accepted

removeMIDIListener

public void removeMIDIListener(MIDIListener l)
Remove the specified MIDIListener from the list of listeners. If no listeners are left after this call, the MIDIManager will be asked to close the device if it is not needed elsewhere.

Parameters:
l - The MIDIListener to remove

send

public void send(javax.sound.midi.MidiMessage message,
                 long timestamp)
Specified by:
send in interface javax.sound.midi.Receiver
See Also:
Receiver.send(javax.sound.midi.MidiMessage, long)

setAcceptStatus

public void setAcceptStatus(int[] status)
Set the MIDI message types accepted by this Receveiver

Parameters:
status - Array of status bytes to accept or null to indicate that all types are accepted