Package net.paulhertz.pixelaudio.granular

# Class PAGranularInstrumentDirector

java.lang.Object
net.paulhertz.pixelaudio.granular.PAGranularInstrumentDirector

public final class PAGranularInstrumentDirector extends Object
The top-level entry point for Granular Synthesis in the PixelAudio library, PAGranularInstrumentDirector acts as a facade to `PAGranularInstrument`, calling PAGranularInstrument.play(...) with a `PABurstGranularSource` instance as a PASource and all necessary gesture and timing data. Calling chain: PAGranularInstrumentDirector -> PAGranularInstrument -> PAGranularSampler -> PAGranularVoice, with PABurstGranularSource handling the complexities of the granular synthesis sample by sample. See the scheduleEvents method, below, for details.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private long[]`
  `cachedEventOffsetsSamples`
  `private static final ddf.minim.analysis.WindowFunction`
  `DEFAULT_GRAIN_WINDOW`
  `private final PAGranularInstrument`
  `instrument`
  `private GestureGranularParams`
  `lastOffsetsParamsRef`
  `private GestureSchedule`
  `lastOffsetsScheduleRef`
  `private GestureSchedule`
  `lastRawScheduleRef`
  `private float`
  `lastScheduleEndMs`
  `private int`
  `lastScheduleSize`
  `private GestureSchedule`
  `lastTransformedScheduleRef`
  `private final float`
  `sampleRate`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PAGranularInstrumentDirector(PAGranularInstrument instrument)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `private static GestureSchedule`
  `applyTimeTransform(GestureSchedule rawSchedule, GestureGranularParams ggParams)`
  `void`
  `cancelAndReleaseAll()`
  `void`
  `cancelAndStopAll()`
  `private static float`
  `clampPan(float p)`
  `void`
  `clearScheduled()`
  `private static float`
  `easeInOutPow(float u, float exp)`
  `private void`
  `ensureCache(GestureSchedule sched, GestureGranularParams params)`
  `PAGranularInstrument`
  `getInstrument()`
  `private static float`
  `lerp(float a, float b, float u)`
  `private static long`
  `msToSamples(float ms, float sr)`
  `void`
  `playGestureAtSampleTime(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices, float[] panValues, long startSampleTime)`
  `void`
  `playGestureAtSampleTime(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices, long startSampleTime)`
  `void`
  `playGestureAtSampleTime(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, GestureEventParams evtParams, long startSampleTime)`
  `void`
  `playGestureAtSampleTimeTransformed(float[] monoBuf, GestureSchedule transformedSchedule, GestureGranularParams params, GestureEventParams evtParams, long startSampleTime)`
  `void`
  `playGestureNow(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices)`
  `void`
  `playGestureNow(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices, float[] panValues)`
  `void`
  `playGestureNow(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, GestureEventParams evtParams)`
  `GestureSchedule`
  `prepareSchedule(GestureSchedule rawSchedule, GestureGranularParams params)`
  `void`
  `releaseAll()`
  `private static GestureSchedule`
  `resampleToCount(GestureSchedule in, int targetCount)`
  Placeholder resampler: you likely already have something better.
  `private static ddf.minim.analysis.WindowFunction`
  `resolveGrainWindow(GestureGranularParams params)`
  `private static GestureSchedule`
  `scaleToDuration(GestureSchedule in, float targetDurationMs)`
  `private void`
  `scheduleEvents(float[] monoBuf, GestureSchedule sched, GestureGranularParams params, GestureEventParams evtParams, ddf.minim.analysis.WindowFunction wf, long startSampleTime)`
  `private static GestureSchedule`
  `warpScheduleTimesMs(GestureSchedule in, GestureGranularParams.WarpShape shape, float exponent)`
  `private static float`
  `warpU(float u, GestureGranularParams.WarpShape shape, float exponent)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### instrument

    private final PAGranularInstrument instrument

  - ### sampleRate

    private final float sampleRate

  - ### lastScheduleSize

    private int lastScheduleSize

  - ### lastScheduleEndMs

    private float lastScheduleEndMs

  - ### cachedEventOffsetsSamples

    private long[] cachedEventOffsetsSamples

  - ### lastRawScheduleRef

    private GestureSchedule lastRawScheduleRef

  - ### lastOffsetsParamsRef

    private GestureGranularParams lastOffsetsParamsRef

  - ### lastTransformedScheduleRef

    private GestureSchedule lastTransformedScheduleRef

  - ### lastOffsetsScheduleRef

    private GestureSchedule lastOffsetsScheduleRef

  - ### DEFAULT_GRAIN_WINDOW

    private static final ddf.minim.analysis.WindowFunction DEFAULT_GRAIN_WINDOW

- ## Constructor Details

  - ### PAGranularInstrumentDirector

    public PAGranularInstrumentDirector(PAGranularInstrument instrument)

- ## Method Details

  - ### resolveGrainWindow

    private static ddf.minim.analysis.WindowFunction resolveGrainWindow(GestureGranularParams params)

  - ### playGestureNow

    public void playGestureNow(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices)

  - ### playGestureNow

    public void playGestureNow(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices, float[] panValues)

  - ### playGestureNow

    public void playGestureNow(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, GestureEventParams evtParams)

  - ### playGestureAtSampleTime

    public void playGestureAtSampleTime(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices, long startSampleTime)

  - ### playGestureAtSampleTime

    public void playGestureAtSampleTime(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, int[] startIndices, float[] panValues, long startSampleTime)

  - ### playGestureAtSampleTime

    public void playGestureAtSampleTime(float[] monoBuf, GestureSchedule schedule, GestureGranularParams params, GestureEventParams evtParams, long startSampleTime)

  - ### playGestureAtSampleTimeTransformed

    public void playGestureAtSampleTimeTransformed(float[] monoBuf, GestureSchedule transformedSchedule, GestureGranularParams params, GestureEventParams evtParams, long startSampleTime)

  - ### scheduleEvents

    private void scheduleEvents(float[] monoBuf, GestureSchedule sched, GestureGranularParams params, GestureEventParams evtParams, ddf.minim.analysis.WindowFunction wf, long startSampleTime)
    Parameters:
      `monoBuf` - a buffer of floating point values in audio signal range (-1.0 to 1.0)
      `sched` -
      `params` -
      `evtParams` -
      `wf` -
      `startSampleTime` -

  - ### ensureCache

    private void ensureCache(GestureSchedule sched, GestureGranularParams params)

  - ### applyTimeTransform

    private static GestureSchedule applyTimeTransform(GestureSchedule rawSchedule, GestureGranularParams ggParams)
    Parameters:
      `rawSchedule` -
      `ggParams` -
    Returns:

  - ### prepareSchedule

    public GestureSchedule prepareSchedule(GestureSchedule rawSchedule, GestureGranularParams params)

  - ### msToSamples

    private static long msToSamples(float ms, float sr)

  - ### resampleToCount

    private static GestureSchedule resampleToCount(GestureSchedule in, int targetCount)
    Placeholder resampler: you likely already have something better. Replace this with your existing GestureScheduleBuilder logic.

  - ### scaleToDuration

    private static GestureSchedule scaleToDuration(GestureSchedule in, float targetDurationMs)

  - ### warpScheduleTimesMs

    private static GestureSchedule warpScheduleTimesMs(GestureSchedule in, GestureGranularParams.WarpShape shape, float exponent)

  - ### warpU

    private static float warpU(float u, GestureGranularParams.WarpShape shape, float exponent)

  - ### easeInOutPow

    private static float easeInOutPow(float u, float exp)

  - ### lerp

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

  - ### clampPan

    private static float clampPan(float p)

  - ### getInstrument

    public PAGranularInstrument getInstrument()

  - ### clearScheduled

    public void clearScheduled()

  - ### releaseAll

    public void releaseAll()

  - ### cancelAndStopAll

    public void cancelAndStopAll()

  - ### cancelAndReleaseAll

    public void cancelAndReleaseAll()