org.tritonus.share.midi
Class TSequencer

java.lang.Object
  extended byorg.tritonus.share.midi.TMidiDevice
      extended byorg.tritonus.share.midi.TSequencer
All Implemented Interfaces:
MidiDevice, Sequencer
Direct Known Subclasses:
AlsaSequencer, JavaSequencer, TPreloadingSequencer

public abstract class TSequencer
extends TMidiDevice
implements Sequencer


Nested Class Summary
 
Nested classes inherited from class org.tritonus.share.midi.TMidiDevice
TMidiDevice.Info, TMidiDevice.TReceiver, TMidiDevice.TTransmitter
 
Nested classes inherited from class javax.sound.midi.Sequencer
Sequencer.SyncMode
 
Nested classes inherited from class javax.sound.midi.MidiDevice
MidiDevice.Info
 
Field Summary
 
Fields inherited from interface javax.sound.midi.Sequencer
LOOP_CONTINUOUSLY
 
Constructor Summary
protected TSequencer(MidiDevice.Info info, Collection masterSyncModes, Collection slaveSyncModes)
           
 
Method Summary
 int[] addControllerEventListener(ControllerEventListener listener, int[] anControllers)
           
 boolean addMetaEventListener(MetaEventListener listener)
           
protected  void checkOpen()
          Checks if the Sequencer is open.
 int getLatency()
          Get the preloading intervall.
 int getLoopCount()
           
 long getLoopEndPoint()
           
 long getLoopStartPoint()
           
 Sequencer.SyncMode getMasterSyncMode()
           
 Sequencer.SyncMode[] getMasterSyncModes()
           
protected  Iterator getMetaEventListeners()
           
 long getMicrosecondLength()
           
protected  int getResolution()
          Returns the resolution (ticks per quarter) of the current sequence.
 Sequence getSequence()
           
 Sequencer.SyncMode getSlaveSyncMode()
           
 Sequencer.SyncMode[] getSlaveSyncModes()
           
 float getTempoFactor()
           
 float getTempoInBPM()
           
 float getTempoInMPQ()
           
 long getTickLength()
           
 boolean getTrackMute(int nTrack)
           
 boolean getTrackSolo(int nTrack)
           
 boolean isRunning()
           
protected  boolean isTrackEnabled(int nTrack)
           
protected  void notifyListeners(MidiMessage message)
           
 int[] removeControllerEventListener(ControllerEventListener listener, int[] anControllers)
           
 void removeMetaEventListener(MetaEventListener listener)
           
protected  void sendControllerEvent(ShortMessage message)
           
protected  void sendMetaMessage(MetaMessage message)
           
 void setLatency(int nMilliseconds)
          Sets the preloading intervall.
 void setLoopCount(int nLoopCount)
           
 void setLoopEndPoint(long lTick)
           
 void setLoopStartPoint(long lTick)
           
 void setMasterSyncMode(Sequencer.SyncMode syncMode)
           
protected  void setMasterSyncModeImpl(Sequencer.SyncMode syncMode)
           
protected  void setRealTempo()
           
 void setSequence(InputStream inputStream)
           
 void setSequence(Sequence sequence)
           
protected  void setSequenceImpl()
          Set Sequence.
 void setSlaveSyncMode(Sequencer.SyncMode syncMode)
           
protected  void setSlaveSyncModeImpl(Sequencer.SyncMode syncMode)
           
 void setTempoFactor(float fFactor)
           
protected abstract  void setTempoImpl(float fMPQ)
          Change the tempo of the native sequencer part.
 void setTempoInBPM(float fBPM)
           
 void setTempoInMPQ(float fMPQ)
          Sets the tempo.
protected  void setTrackEnabledImpl(int nTrack, boolean bEnabled)
          Shows that a track state has changed.
 void setTrackMute(int nTrack, boolean bMute)
           
protected  void setTrackMuteImpl(int nTrack, boolean bMute)
           
 void setTrackSolo(int nTrack, boolean bSolo)
           
protected  void setTrackSoloImpl(int nTrack, boolean bSolo)
           
 void start()
           
protected  void startImpl()
          Subclasses have to override this method to be notified of starting.
 void stop()
           
protected  void stopImpl()
          Subclasses have to override this method to be notified of stopping.
 
Methods inherited from class org.tritonus.share.midi.TMidiDevice
close, closeImpl, getDeviceInfo, getMaxReceivers, getMaxTransmitters, getMicrosecondPosition, getReceiver, getReceivers, getTransmitter, getTransmitters, getUseIn, getUseOut, isOpen, open, openImpl, receive, sendImpl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.sound.midi.Sequencer
getMicrosecondPosition, getTickPosition, isRecording, recordDisable, recordEnable, setMicrosecondPosition, setTickPosition, startRecording, stopRecording
 
Methods inherited from interface javax.sound.midi.MidiDevice
close, getDeviceInfo, getMaxReceivers, getMaxTransmitters, getReceiver, getReceivers, getTransmitter, getTransmitters, isOpen, open
 

Constructor Detail

TSequencer

protected TSequencer(MidiDevice.Info info,
                     Collection masterSyncModes,
                     Collection slaveSyncModes)
Method Detail

setSequence

public void setSequence(Sequence sequence)
                 throws InvalidMidiDataException
Specified by:
setSequence in interface Sequencer
Throws:
InvalidMidiDataException

setSequenceImpl

protected void setSequenceImpl()
Set Sequence. Subclasses that need to be informed when a Sequence is set should override this method. It is called by setSequence(). Subclasses can find out the new Sequence by calling getSequence().


setSequence

public void setSequence(InputStream inputStream)
                 throws InvalidMidiDataException,
                        IOException
Specified by:
setSequence in interface Sequencer
Throws:
InvalidMidiDataException
IOException

getSequence

public Sequence getSequence()
Specified by:
getSequence in interface Sequencer

setLoopStartPoint

public void setLoopStartPoint(long lTick)
Specified by:
setLoopStartPoint in interface Sequencer

getLoopStartPoint

public long getLoopStartPoint()
Specified by:
getLoopStartPoint in interface Sequencer

setLoopEndPoint

public void setLoopEndPoint(long lTick)
Specified by:
setLoopEndPoint in interface Sequencer

getLoopEndPoint

public long getLoopEndPoint()
Specified by:
getLoopEndPoint in interface Sequencer

setLoopCount

public void setLoopCount(int nLoopCount)
Specified by:
setLoopCount in interface Sequencer

getLoopCount

public int getLoopCount()
Specified by:
getLoopCount in interface Sequencer

start

public void start()
Specified by:
start in interface Sequencer

startImpl

protected void startImpl()
Subclasses have to override this method to be notified of starting.


stop

public void stop()
Specified by:
stop in interface Sequencer

stopImpl

protected void stopImpl()
Subclasses have to override this method to be notified of stopping.


isRunning

public boolean isRunning()
Specified by:
isRunning in interface Sequencer

checkOpen

protected void checkOpen()
Checks if the Sequencer is open. This method is intended to be called by start, stop, startRecording and stopRecording.

Throws:
IllegalStateException - if the Sequencer is not open

getResolution

protected int getResolution()
Returns the resolution (ticks per quarter) of the current sequence. If no sequence is set, a bogus default value != 0 is returned.


setRealTempo

protected void setRealTempo()

getTempoInBPM

public float getTempoInBPM()
Specified by:
getTempoInBPM in interface Sequencer

setTempoInBPM

public void setTempoInBPM(float fBPM)
Specified by:
setTempoInBPM in interface Sequencer

getTempoInMPQ

public float getTempoInMPQ()
Specified by:
getTempoInMPQ in interface Sequencer

setTempoInMPQ

public void setTempoInMPQ(float fMPQ)
Sets the tempo. Implementation classes are required to call this method for changing the tempo in reaction to a tempo change event.

Specified by:
setTempoInMPQ in interface Sequencer

setTempoFactor

public void setTempoFactor(float fFactor)
Specified by:
setTempoFactor in interface Sequencer

getTempoFactor

public float getTempoFactor()
Specified by:
getTempoFactor in interface Sequencer

setTempoImpl

protected abstract void setTempoImpl(float fMPQ)
Change the tempo of the native sequencer part. This method has to be defined by subclasses according to the native facilities they use for sequenceing. The implementation should not take into account the tempo factor. This is handled elsewhere.


getTickLength

public long getTickLength()
Specified by:
getTickLength in interface Sequencer

getMicrosecondLength

public long getMicrosecondLength()
Specified by:
getMicrosecondLength in interface Sequencer

addMetaEventListener

public boolean addMetaEventListener(MetaEventListener listener)
Specified by:
addMetaEventListener in interface Sequencer

removeMetaEventListener

public void removeMetaEventListener(MetaEventListener listener)
Specified by:
removeMetaEventListener in interface Sequencer

getMetaEventListeners

protected Iterator getMetaEventListeners()

sendMetaMessage

protected void sendMetaMessage(MetaMessage message)

addControllerEventListener

public int[] addControllerEventListener(ControllerEventListener listener,
                                        int[] anControllers)
Specified by:
addControllerEventListener in interface Sequencer

removeControllerEventListener

public int[] removeControllerEventListener(ControllerEventListener listener,
                                           int[] anControllers)
Specified by:
removeControllerEventListener in interface Sequencer

sendControllerEvent

protected void sendControllerEvent(ShortMessage message)

notifyListeners

protected void notifyListeners(MidiMessage message)

getMasterSyncMode

public Sequencer.SyncMode getMasterSyncMode()
Specified by:
getMasterSyncMode in interface Sequencer

setMasterSyncMode

public void setMasterSyncMode(Sequencer.SyncMode syncMode)
Specified by:
setMasterSyncMode in interface Sequencer

setMasterSyncModeImpl

protected void setMasterSyncModeImpl(Sequencer.SyncMode syncMode)

getMasterSyncModes

public Sequencer.SyncMode[] getMasterSyncModes()
Specified by:
getMasterSyncModes in interface Sequencer

getSlaveSyncMode

public Sequencer.SyncMode getSlaveSyncMode()
Specified by:
getSlaveSyncMode in interface Sequencer

setSlaveSyncMode

public void setSlaveSyncMode(Sequencer.SyncMode syncMode)
Specified by:
setSlaveSyncMode in interface Sequencer

setSlaveSyncModeImpl

protected void setSlaveSyncModeImpl(Sequencer.SyncMode syncMode)

getSlaveSyncModes

public Sequencer.SyncMode[] getSlaveSyncModes()
Specified by:
getSlaveSyncModes in interface Sequencer

getTrackSolo

public boolean getTrackSolo(int nTrack)
Specified by:
getTrackSolo in interface Sequencer

setTrackSolo

public void setTrackSolo(int nTrack,
                         boolean bSolo)
Specified by:
setTrackSolo in interface Sequencer

setTrackSoloImpl

protected void setTrackSoloImpl(int nTrack,
                                boolean bSolo)

getTrackMute

public boolean getTrackMute(int nTrack)
Specified by:
getTrackMute in interface Sequencer

setTrackMute

public void setTrackMute(int nTrack,
                         boolean bMute)
Specified by:
setTrackMute in interface Sequencer

setTrackMuteImpl

protected void setTrackMuteImpl(int nTrack,
                                boolean bMute)

setTrackEnabledImpl

protected void setTrackEnabledImpl(int nTrack,
                                   boolean bEnabled)
Shows that a track state has changed. This method is called for each track where the enabled state (calculated from mute and solo) has changed. The boolean value passed represents the new state.

Parameters:
nTrack - The track number for which the enabled status has changed.
bEnabled - The new enabled state for this track.

isTrackEnabled

protected boolean isTrackEnabled(int nTrack)

setLatency

public void setLatency(int nMilliseconds)
Sets the preloading intervall. This is the time span between preloading events to an internal queue and playing them. This intervall should be kept constant by the implementation. However, this cannot be guaranteed.


getLatency

public int getLatency()
Get the preloading intervall.

Returns:
the preloading intervall in milliseconds, or -1 if the sequencer doesn't repond to changes in the Sequence at all.