Class Cursor

java.lang.Object
heronarts.lx.clip.Cursor
All Implemented Interfaces:
LXSerializable
Direct Known Subclasses:
Cursor.Immutable

public class Cursor extends Object implements LXSerializable
A cursor can keep track of time in two ways - either raw wall-clock milliseconds or a tempo-based beat count plus position within the beat.
  • Field Details

  • Constructor Details

    • Cursor

      public Cursor()
    • Cursor

      protected Cursor(double millis, int beatCount, double beatBasis)
  • Method Details

    • assertMutable

      protected void assertMutable()
    • clone

      public Cursor clone()
      Overrides:
      clone in class Object
    • immutable

      public Cursor.Immutable immutable()
      Return an immutable version of this cursor, typically a copy unless the cursor is already itself immutable.
      Returns:
      Immutable version of this cursor
    • getMillis

      public double getMillis()
      Gets the absolute time millisecond timestamp of this cursor
      Returns:
      Absolute time of this cursor in milliseconds
    • getBeatCount

      public int getBeatCount()
      Gets the discrete beat-count of this cursor, greater than or equal to 0
      Returns:
      Beat count, non-negative
    • getBeatBasis

      public double getBeatBasis()
      Gets the position of the cursor within a beat, bounded in the range [0,1)
      Returns:
      Position of the cursor within the beat
    • constrain

      public Cursor constrain(LXClip clip)
      Constrain the position of this cursor to the length of the clip. This is a potentially destructive operation which may modify the value if this cursor.
      Parameters:
      clip - Clip to constrain the cursor to
      Returns:
      This cursor, for method chaining
    • bound

      public Cursor bound(LXClip clip)
      Non-destructive version of constrain, bounds the cursor by the length of the given clip. If this cursor is out of bounds, then either Cursor.ZERO or clip.length.cursor will be returned instead.
      Parameters:
      clip - Clip to bound the cursor to
      Returns:
      This cursor if in bounds, otherwise clip.length.cursor
    • reset

      public void reset()
      Reset the cursor to zero
    • set

      public Cursor set(Cursor that)
      Set the value of the cursor to the value held by another
      Parameters:
      that - Other cursor
      Returns:
      This cursor, updated
    • setLerp

      public Cursor setLerp(Cursor from, Cursor to, double scale)
      Set the value of this cursor to the interpolation of two cursors
      Parameters:
      from - Source cursor
      to - Target cursor
      scale - Interpolation factor
      Returns:
      This cursor, modified, for method chaining
    • scale

      public Cursor scale(double factor)
      Creates a new cursor that's a copy of this cursor scaled by the given factor
      Parameters:
      factor - Time scaling factor
      Returns:
      New cursor scaled by the given amount
    • scaleInt

      public Cursor scaleInt(int factor)
      Creates a cursor that is an integer set of multiples of this cursor
      Parameters:
      factor - Multiples of this cursor
      Returns:
      New cursor scaled by the number of multiples
    • advance

      public Cursor advance(Cursor that)
      Destructively modifies this cursor, advancing it by the amount specified
      Parameters:
      that - Cursor specifying amount to advance
      Returns:
      This cursor, modified
    • add

      public Cursor add(Cursor that)
      Creates a new cursor that sums the two
      Parameters:
      that - Cursor to add
      Returns:
      New cursor representing sum of this cursor with the other
    • inc

      public Cursor inc(Cursor that, boolean add)
      Increments a new cursor that adds or subtracts the two, bounded to zero minimum
      Parameters:
      that - Cursor to add or subtract
      add - True to add, if false then subtraction
      Returns:
      New cursor representing the result of the operation
    • subtract

      public Cursor subtract(Cursor that)
    • getDeltaMillis

      public double getDeltaMillis(Cursor that)
      Returns the absolute time difference between these cursors
      Parameters:
      that - Other cursor
      Returns:
      Millisecond difference between these two cursors
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • save

      public void save(LX lx, JsonObject obj)
      Description copied from interface: LXSerializable
      Serializes this instance into the JSON object
      Specified by:
      save in interface LXSerializable
      Parameters:
      lx - LX instance
      obj - Object to serialize into
    • load

      public void load(LX lx, JsonObject obj)
      Description copied from interface: LXSerializable
      Restores this instance from a JSON object
      Specified by:
      load in interface LXSerializable
      Parameters:
      lx - LX instance
      obj - Object to deserialize