micromod
Class Sequencer

java.lang.Object
  extended bymicromod.Sequencer

public class Sequencer
extends java.lang.Object

The Sequencer interprets a Sequence a "tick" at a time. There is usually more than one tick per row.


Field Summary
protected  int currentRow
           
protected  int patternBreak
           
protected  int patternLoopChannel
           
protected  int patternLoopCounter
           
protected  boolean patternLoopEngaged
           
protected  int[] patternLoopRow
           
protected  int positionJump
           
protected  int rowJump
           
static int SEQFX_PATBREAK
           
static int SEQFX_PATDELAY
           
static int SEQFX_PATLOOP
           
static int SEQFX_POSJUMP
           
static int SEQFX_SETSPEED
           
protected  Sequence sequence
           
protected  int[] sequenceCounter
           
protected  int sequencePosition
           
protected  Synthesizer synthesizer
           
protected  int tempo
           
protected  int tempoCounter
           
 
Constructor Summary
Sequencer(Module module, Synthesizer synthesizer)
           
 
Method Summary
 int getSequenceCounter()
           
 int getSequencePosition()
           
 int getSongLengthPatterns()
           
protected  boolean handlePatternLoop(int channel, int parameter)
          Some modules do some very sick things with pattern loops, so it must be implemented correctly.
protected  void initializeRowFX()
          Process any sequencer commands on the current row and set flags to indicate what nextRow() should do next.
protected  void nextRow()
          Move to the next row, or perform a jump if one is requested.
protected  void nextSequencePosition()
           
 void reset()
          Reset the Sequencer and Synthesizer to their initial states.
protected  void resetPatternLoop()
          Reset all loop markers to row 0, as would happen when a new sequence position is entered.
protected  void resetSequenceCounter()
          Zero the sequence counter.
 void setModule(Module module)
          Initialise the Sequencer to play a new module.
 void setSequencePosition(int pos)
          Set the current sequence position to be played.
 void update()
          Update the Sequencer for a single tick.
protected  void updateRow(int row)
          Set the current row, and handle any necessary state changes.
protected  void updateSequencePosition(int pos)
          Set the current sequence position, and handle any necessary state changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEQFX_POSJUMP

public static final int SEQFX_POSJUMP
See Also:
Constant Field Values

SEQFX_PATBREAK

public static final int SEQFX_PATBREAK
See Also:
Constant Field Values

SEQFX_SETSPEED

public static final int SEQFX_SETSPEED
See Also:
Constant Field Values

SEQFX_PATLOOP

public static final int SEQFX_PATLOOP
See Also:
Constant Field Values

SEQFX_PATDELAY

public static final int SEQFX_PATDELAY
See Also:
Constant Field Values

sequence

protected Sequence sequence

synthesizer

protected Synthesizer synthesizer

sequenceCounter

protected int[] sequenceCounter

sequencePosition

protected int sequencePosition

currentRow

protected int currentRow

tempo

protected int tempo

tempoCounter

protected int tempoCounter

patternBreak

protected int patternBreak

positionJump

protected int positionJump

rowJump

protected int rowJump

patternLoopRow

protected int[] patternLoopRow

patternLoopChannel

protected int patternLoopChannel

patternLoopCounter

protected int patternLoopCounter

patternLoopEngaged

protected boolean patternLoopEngaged
Constructor Detail

Sequencer

public Sequencer(Module module,
                 Synthesizer synthesizer)
Method Detail

setModule

public void setModule(Module module)
Initialise the Sequencer to play a new module.


reset

public void reset()
Reset the Sequencer and Synthesizer to their initial states. This method sets up the first tick, so you should extract audio from the Synthesizer before calling update().


update

public void update()
Update the Sequencer for a single tick.


getSequenceCounter

public int getSequenceCounter()
Returns:
the number of times the current sequence position has been played. This can be used to determine whether the song is looping.

setSequencePosition

public void setSequencePosition(int pos)
Set the current sequence position to be played. This can be used to skip parts of a song, or to find "hidden" patterns. This method resets the "sequence counter".


getSongLengthPatterns

public int getSongLengthPatterns()
Returns:
The length, in patterns, of the current Sequence.

getSequencePosition

public int getSequencePosition()
Returns:
the sequence position currently being played.

resetSequenceCounter

protected void resetSequenceCounter()
Zero the sequence counter.


nextRow

protected void nextRow()
Move to the next row, or perform a jump if one is requested.


nextSequencePosition

protected void nextSequencePosition()

initializeRowFX

protected void initializeRowFX()
Process any sequencer commands on the current row and set flags to indicate what nextRow() should do next.


updateSequencePosition

protected void updateSequencePosition(int pos)
Set the current sequence position, and handle any necessary state changes.


updateRow

protected void updateRow(int row)
Set the current row, and handle any necessary state changes.


handlePatternLoop

protected boolean handlePatternLoop(int channel,
                                    int parameter)
Some modules do some very sick things with pattern loops, so it must be implemented correctly. While I'm not 100% sure, this algorithm works with all the patternloop-bending I know of (including the sick BETA-3, which uses an arrangement that causes a pattern to play through with lots of stuttering, then the same pattern plays through without stuttering. ModPlug can play this tune correctly, the version of MikIT I have can't, but to be fair it doesn't sound any worse.) Pattern loop works by having a loop marker for each channel. Once a pattern loop is started, loop commands on other channels are ignored. Issuing a pattern loop without setting a marker loops from row zero. The loop markers are reset for each pattern. Loops on the leftmost channels take precedence, so on a row with a pattern loop on each channel, the pattern is looped using the channel 0 markers, then it is looped with the channel 1 markers and so on.

Returns:
true if a jump is to be made to the marker set in patternLoopRow[channel].

resetPatternLoop

protected void resetPatternLoop()
Reset all loop markers to row 0, as would happen when a new sequence position is entered.