com.soundhelix.misc
Class ActivityVector

java.lang.Object
  extended by com.soundhelix.misc.ActivityVector

public class ActivityVector
extends Object

Represents a bit vector specifying for each tick whether a voice should be active or not. The bit vector grows dynamically as needed. This vector should be considered a strong hint for a SequenceEngine whether to add notes or to add pauses. However, it is not strictly forbidden to play notes while inactive. For example, after an activity interval, a final note could be played at the start of the following inactivity interval. An ActivityVector must always span the whole length of a song.

Author:
Thomas Schuerger (thomas@schuerger.com)
See Also:
SequenceEngine

Constructor Summary
ActivityVector(String name)
          Constructor.
ActivityVector(String name, int bits)
          Constructor.
 
Method Summary
 void addActivity(int ticks)
          Appends an activity interval with the specified number of ticks.
 void addInactivity(int ticks)
          Appends an inactivity interval with the specified number of ticks.
 int getActiveTicks()
          Returns the number of ticks this ActivityVector is active.
 int getActivitySegmentCount()
          Counts the number of activity segments, which is the number of consecutive blocks of activity in the vector.
 int getFirstActiveTick()
          Returns the tick where the ActivityVector becomes active for the first time.
 int getFirstInactiveTick()
          Returns the tick where the ActivityVector becomes inactive for the first time.
 int getIntervalLength(int tick)
          Returns the length of the interval beginning with the given tick, i.e., the number of ticks until the activity state changes or the end of the vector is reached.
 int getLastActiveTick()
          Returns the tick where the ActivityVector is active for the last time.
 String getName()
          Returns the name of this ActivityVector.
 int[] getSegmentLengths()
          Returns an array that contains all activity and pause segment lengths in ticks, sorted by starting tick number.
 int getTicks()
          Returns the total number of ticks this ActivityVector spans.
 boolean isActive(int tick)
          Returns the activity state of the specified tick.
 void setActivityState(int from, int till, boolean state)
          Modifies the ActivityVector so that it has the given state in the interval from from (inclusive) to till (exclusive).
 void shiftIntervalBoundaries(int startTicks, int stopTicks)
          Modifies the ActivityVector so that all interval changes from inactive to active are postponed by startTicks and all changes from active to inactive are postponed by stopTicks ticks. startTicks and stopTicks may also be negative to prepone instead of postpone.
 String toString()
          Returns a string representation of the ActivityVector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActivityVector

public ActivityVector(String name)
Constructor. Initializes the internal BitSet's initial size to the default number of bits.

Parameters:
name - the name

ActivityVector

public ActivityVector(String name,
                      int bits)
Constructor. Initializes the internal BitSet's initial size to the given number of bits.

Parameters:
name - the name
bits - the initial number of bits
Method Detail

addActivity

public void addActivity(int ticks)
Appends an activity interval with the specified number of ticks.

Parameters:
ticks - the number of ticks

addInactivity

public void addInactivity(int ticks)
Appends an inactivity interval with the specified number of ticks.

Parameters:
ticks - the number of ticks

isActive

public boolean isActive(int tick)
Returns the activity state of the specified tick. If the tick number is beyond the end of the vector, false is returned.

Parameters:
tick - the tick
Returns:
true if the tick is active, false otherwise

getIntervalLength

public int getIntervalLength(int tick)
Returns the length of the interval beginning with the given tick, i.e., the number of ticks until the activity state changes or the end of the vector is reached.

Parameters:
tick - the tick
Returns:
the number of ticks until the next change or the vector ends

getName

public String getName()
Returns the name of this ActivityVector.

Returns:
the name

getTicks

public int getTicks()
Returns the total number of ticks this ActivityVector spans.

Returns:
the total number of ticks

getActiveTicks

public int getActiveTicks()
Returns the number of ticks this ActivityVector is active.

Returns:
the number of active ticks

getFirstActiveTick

public int getFirstActiveTick()
Returns the tick where the ActivityVector becomes active for the first time. If the ActvityVector never becomes active, -1 is returned.

Returns:
the first activity tick (or -1)

getLastActiveTick

public int getLastActiveTick()
Returns the tick where the ActivityVector is active for the last time. If the ActvityVector never becomes active, -1 is returned.

Returns:
the last activity tick (or -1)

getFirstInactiveTick

public int getFirstInactiveTick()
Returns the tick where the ActivityVector becomes inactive for the first time. If the ActvityVector never becomes in inactive, -1 is returned.

Returns:
the first inactivity tick

setActivityState

public void setActivityState(int from,
                             int till,
                             boolean state)
Modifies the ActivityVector so that it has the given state in the interval from from (inclusive) to till (exclusive). The vector will be extended, if necessary.

Parameters:
from - the starting tick (inclusive)
till - the ending tick (exclusive)
state - the state of the interval

shiftIntervalBoundaries

public void shiftIntervalBoundaries(int startTicks,
                                    int stopTicks)
Modifies the ActivityVector so that all interval changes from inactive to active are postponed by startTicks and all changes from active to inactive are postponed by stopTicks ticks. startTicks and stopTicks may also be negative to prepone instead of postpone. The start of the first interval is never modified, whereas the end of the last interval is never postponed.

Parameters:
startTicks - the number of ticks to prepone or postpone starting
stopTicks - the number of ticks to prepone or postpone stopping

getActivitySegmentCount

public int getActivitySegmentCount()
Counts the number of activity segments, which is the number of consecutive blocks of activity in the vector.

Returns:
the number of activity segments

toString

public String toString()
Returns a string representation of the ActivityVector.

Overrides:
toString in class Object
Returns:
a string representation

getSegmentLengths

public int[] getSegmentLengths()
Returns an array that contains all activity and pause segment lengths in ticks, sorted by starting tick number. Every activity segment will have a positive length, every pause segment will have a negative length.

Returns:
the array containing the segment lengths