Class LXPeriodicModulator

All Implemented Interfaces:
LXComponent.Renamable, LXLoopTask, LXPath, LXSerializable, LXParameter, LXParameterListener
Direct Known Subclasses:
Click, Interval, LXRangeModulator, Randomizer, StepSequencer

public abstract class LXPeriodicModulator extends LXModulator
An LXPeriodicModulator is a modulator that moves through a cycle in a given amount of time. It may then repeat the cycle, or perform it once. The values are computed based upon a position in the cycle, internally referred to as a basis, which moves from 0 to 1. This can be thought of as equivalent to an angle moving from 0 to two times pi. The period itself is a parameter which may be a modulator or otherwise.
  • Field Details

  • Constructor Details

    • LXPeriodicModulator

      protected LXPeriodicModulator(String label, LXParameter period)
      Utility constructor with period
      Parameters:
      label - Label
      period - Parameter for period
  • Method Details

    • onParameterChanged

      public void onParameterChanged(LXParameter p)
      Description copied from class: LXComponent
      Subclasses are free to override this if desired. It will automatically fire for any listenable parameter that is registered with this component.
      Specified by:
      onParameterChanged in interface LXParameterListener
      Overrides:
      onParameterChanged in class LXRunnableComponent
      Parameters:
      p - Parameter that has a value change
    • setLooping

      public LXPeriodicModulator setLooping(boolean looping)
      Sets whether the modulator should loop after it completes a cycle or halt at the end position.
      Parameters:
      looping - Whether to loop
      Returns:
      this, for method chaining
    • disableAutoReset

      public LXPeriodicModulator disableAutoReset()
    • getBasis

      public final double getBasis()
      Accessor for the current basis
      Returns:
      The basis of the modulator
    • getBasisf

      public final float getBasisf()
      Accessor for basis as a float
      Returns:
      basis as float
    • onReset

      protected void onReset()
      Description copied from class: LXRunnableComponent
      Optional subclass method when reset happens.
      Overrides:
      onReset in class LXRunnableComponent
    • randomBasis

      public final LXPeriodicModulator randomBasis()
      Sets the basis to a random position
      Returns:
      this
    • setBasis

      public final LXPeriodicModulator setBasis(double basis)
      Set the modulator to a certain basis position in its cycle.
      Parameters:
      basis - Basis of modulator, from 0-1
      Returns:
      this
    • onSetValue

      public void onSetValue(double value)
      Set the modulator to a certain value in its cycle.
      Overrides:
      onSetValue in class LXModulator
      Parameters:
      value - The value to apply
    • updateBasis

      protected final void updateBasis(double value)
      Updates the basis of the modulator based on present values.
      Parameters:
      value - New value of the modulator
    • setPeriod

      public final LXPeriodicModulator setPeriod(double periodMs)
      Modify the period of this modulator
      Parameters:
      periodMs - New period, in milliseconds
      Returns:
      Modulator, for method chaining;
    • getPeriod

      public final double getPeriod()
      Returns:
      The period of this modulator
    • getPeriodf

      public final float getPeriodf()
      Returns:
      The period of this modulator as a floating point
    • setPeriod

      public final LXPeriodicModulator setPeriod(LXParameter period)
      Sets a parameter to the period of this modulator
      Parameters:
      period - Parameter for period value
      Returns:
      This modulator, for method chaining
    • loop

      public void loop(double deltaMs)
      Specified by:
      loop in interface LXLoopTask
      Overrides:
      loop in class LXModulator
    • computeValue

      protected final double computeValue(double deltaMs)
      Description copied from class: LXModulator
      Implementation method to advance the modulator's internal state. Subclasses must provide and update value appropriately.
      Specified by:
      computeValue in class LXModulator
      Parameters:
      deltaMs - Number of milliseconds to advance by
      Returns:
      Computed value
    • loop

      public final boolean loop()
      Returns true once each time this modulator loops through its starting position.
      Returns:
      true if the modulator just looped
    • numLoops

      public final int numLoops()
      Returns the number of times the modulator looped on the last cycle; should be 0 or 1 unless the period's extremely short and/or the machine is overworked.
      Returns:
      number of loops on the last cycle
    • finished

      public final boolean finished()
      For envelope modulators, which are not looping, this returns true if they finished on this frame.
      Returns:
      true if the modulator just finished its operation on this frame
    • computeValue

      protected abstract double computeValue(double deltaMs, double basis)
      Implementation method to compute the value of a modulator given its basis.
      Parameters:
      deltaMs - Milliseconds elapsed
      basis - Basis of the modulator
      Returns:
      Value of modulator
    • computeBasis

      protected abstract double computeBasis(double basis, double value)
      Implementation method to compute the appropriate basis for a modulator given its current basis and value.
      Parameters:
      basis - Last basis of modulator
      value - Current value of modulator
      Returns:
      Basis of modulator
    • save

      public void save(LX lx, JsonObject object)
      Description copied from class: LXComponent
      Serializes the LX component. By default, all internal and user-facing parameters are serialized, as well as any explicitly registered child components. Note that child arrays are not serialized, or any other dynamic components. Subclasses may override to perform more saving, and are expected to call super.save(lx, obj) at the appropriate time.
      Specified by:
      save in interface LXSerializable
      Overrides:
      save in class LXComponent
      Parameters:
      lx - LX instance
      object - Object to serialize into
    • load

      public void load(LX lx, JsonObject object)
      Description copied from class: LXComponent
      Loads the LX component. Restores the ID of the component, as well as its internal and user-facing parameters. Any explicitly registered children will be automatically loaded, so long as they are direct descendants. Dynamic arrays will not be automatically loaded, this is left to subclasses to implement.
      Specified by:
      load in interface LXSerializable
      Overrides:
      load in class LXComponent
      Parameters:
      lx - LX instance
      object - Object to deserialize