Class PAKeyframeControlCurve

java.lang.Object
net.paulhertz.pixelaudio.curves.PAKeyframeControlCurve
All Implemented Interfaces:
PAControlCurve

public final class PAKeyframeControlCurve extends Object implements PAControlCurve
Models piecewise-linear scalar control curve defined by keyframes. u ∈ [0,1] -> value where: - times01 is a strictly ascending list of control times in [0,1] - values is a list of corresponding scalar values Typical uses: - gesture dynamics / gain shaping - pan curves - pitch modulation - other normalized control data This class makes no strong assumptions about the range of values. For dynamics, values will usually be in [0,1], but other ranges are allowed.
See Also:
  • example code.
  • Field Details

    • times01

      private final float[] times01
    • values

      private final float[] values
    • count

      private final int count
  • Constructor Details

    • PAKeyframeControlCurve

      public PAKeyframeControlCurve(float[] times01, float[] values)
      Parameters:
      times01 - strictly ascending control times in [0,1]
      values - scalar values corresponding to each entry in times01
  • Method Details

    • getPointCount

      public int getPointCount()
      Returns:
      number of keyframes
    • getTimes01

      public float[] getTimes01()
      Returns:
      defensive copy of normalized keyframe times
    • getValues

      public float[] getValues()
      Returns:
      defensive copy of keyframe values
    • sample

      public float sample(float u)
      Sample the control curve at parameter u ∈ [0,1]. Values outside [0,1] are clamped before sampling.
      Specified by:
      sample in interface PAControlCurve
    • sampleUnit

      public float sampleUnit(float u)
      Convenience for dynamics-style use where values are expected in [0,1]. The returned sample is clamped to [0,1].
    • findSegment

      private int findSegment(float u)
      Find the largest i such that times01[i] <= u, with the guarantee that i < count - 1 for in-range queries.
    • validate

      private static void validate(float[] times01, float[] values)
    • clamp01

      private static float clamp01(float u)
    • lerp

      private static float lerp(float a, float b, float u)
    • expandToSchedule

      public static float[] expandToSchedule(PAControlCurve curve, GestureSchedule sched)