Package net.paulhertz.pixelaudio.curves
Class PAKeyframeControlCurve
java.lang.Object
net.paulhertz.pixelaudio.curves.PAKeyframeControlCurve
- All Implemented Interfaces:
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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static floatclamp01(float u) static float[]expandToSchedule(PAControlCurve curve, GestureSchedule sched) private intfindSegment(float u) Find the largest i such thattimes01[i] <= u, with the guarantee thati < count - 1for in-range queries.intfloat[]float[]private static floatlerp(float a, float b, float u) floatsample(float u) Sample the control curve at parameter u ∈ [0,1].floatsampleUnit(float u) Convenience for dynamics-style use where values are expected in [0,1].private static voidvalidate(float[] times01, float[] values)
-
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:
samplein interfacePAControlCurve
-
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].- Parameters:
u- value to clamp to interval [0,1]- Returns:
- value clamped to [0,1]
-
findSegment
private int findSegment(float u) Find the largest i such thattimes01[i] <= u, with the guarantee thati < count - 1for in-range queries.- Parameters:
u- find largest index in times01[] that is less than u- Returns:
- largest index less than u over times01[]
-
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
-