Package net.paulhertz.pixelaudio.sampler

# Class PASamplerInstrumentPoolMulti

java.lang.Object
net.paulhertz.pixelaudio.sampler.PASamplerInstrumentPoolMulti

All Implemented Interfaces:
  `PAPlayable`, `PASamplerPlayable`

public class PASamplerInstrumentPoolMulti extends Object implements PASamplerPlayable, PAPlayable
PASamplerInstrumentPoolMulti Manages multiple PASamplerInstrumentPool instances, each keyed by name. Each sub-pool may represent a distinct sample source or timbral layer. Features: - Dynamic add/remove of sub-pools - Shared AudioOutput - Optional active-key routing (only one pool plays at a time) - Global stop, buffer, and sample-rate propagation - Graceful resizing using PASamplerInstrumentPool’s gentle reinit Thread-safe and compatible with both PAPlayable and PASamplerPlayable. TODO example sketches.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private String`
  `activeKey`
  `private boolean`
  `isClosed`
  `private float`
  `masterGain`
  `private final ddf.minim.AudioOutput`
  `out`
  `private final Map<String,PASamplerInstrumentPool>`
  `pools`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PASamplerInstrumentPoolMulti(ddf.minim.AudioOutput out)`
  `PASamplerInstrumentPoolMulti(String key, ddf.minim.MultiChannelBuffer buffer, float sampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams adsr)`
  Convenience constructor for single-pool initialization.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addPool(String key, ddf.minim.MultiChannelBuffer buffer, float bufferSampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams env)`
  `void`
  `close()`
  Close all sub-pools and release shared resources.
  `private PASamplerInstrumentPool`
  `current()`
  Returns the currently active sub-pool (may be null).
  `void`
  `debugPrintState()`
  `String`
  `getActiveKey()`
  `PASamplerInstrumentPool`
  `getPoolByTag(String tag)`
  `int`
  `getPoolCount()`
  `Map<String,PASamplerInstrumentPool>`
  `getPools()`
  `boolean`
  `hasPool(String tag)`
  `boolean`
  `isClosed()`
  `boolean`
  `isLooping()`
  `int`
  `play(float amplitude, float pitch, float pan)`
  Plays the instrument's entire buffer, from PAPlayable interface.
  `int`
  `play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)`
  PASamplerPlayable's play method, all six standard parameters in standard order, called by other methods.
  `int`
  `playSample(int samplePos, int sampleLen, float amplitude)`
  Play subrange with amplitude only.
  `int`
  `playSample(int samplePos, int sampleLen, float amplitude, float pitch)`
  Play subrange with amplitude and pitch (no envelope).
  `int`
  `playSample(int samplePos, int sampleLen, float amplitude, float pitch, float pan)`
  `int`
  `playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env)`
  `int`
  `playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch)`
  `int`
  `playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)`
  Play a subrange of the buffer with full parameters.
  `int`
  `playSample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch)`
  `int`
  `playSample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)`
  `int`
  `playSample(String tag, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)`
  `void`
  `removePool(String key)`
  Remove a pool by key and close it safely.
  `void`
  `resizeAllPools(int newPoolSize, int newVoicesPerInstrument)`
  Adjust size or polyphony of all sub-pools gracefully.
  `void`
  `setActive(String key)`
  Activate the given pool key for subsequent play() calls.
  `void`
  `setBuffer(float[] newBuffer, float newSampleRate)`
  Propagate float[] buffer to all sub-pools (mono assumption).
  `void`
  `setBuffer(ddf.minim.MultiChannelBuffer newBuffer)`
  Propagate new buffer to all sub-pools, keeping sample rates intact.
  `void`
  `setBuffer(ddf.minim.MultiChannelBuffer newBuffer, float newSampleRate)`
  Propagate new buffer and sample rate to all sub-pools.
  `void`
  `setMasterGain(float linear)`
  `void`
  `stop()`
  Stop playback immediately (implementation-defined).
  `void`
  `stopAll()`
  `void`
  `updateRateFromOutput()`
  Update sample rates of all sub-pools from AudioOutput.

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

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

  ### Methods inherited from interface net.paulhertz.pixelaudio.sampler.PAPlayable

  `play, play, play, play, play`

  ### Methods inherited from interface net.paulhertz.pixelaudio.sampler.PASamplerPlayable

  `playSample, playSample, playSample, playSample, playSample`

- ## Field Details

  - ### out

    private final ddf.minim.AudioOutput out

  - ### pools

    private final Map<String,PASamplerInstrumentPool> pools

  - ### activeKey

    private String activeKey

  - ### isClosed

    private boolean isClosed

  - ### masterGain

    private volatile float masterGain

- ## Constructor Details

  - ### PASamplerInstrumentPoolMulti

    public PASamplerInstrumentPoolMulti(ddf.minim.AudioOutput out)

  - ### PASamplerInstrumentPoolMulti

    public PASamplerInstrumentPoolMulti(String key, ddf.minim.MultiChannelBuffer buffer, float sampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams adsr)
    Convenience constructor for single-pool initialization.

- ## Method Details

  - ### addPool

    public void addPool(String key, ddf.minim.MultiChannelBuffer buffer, float bufferSampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams env)

  - ### removePool

    public void removePool(String key)
    Remove a pool by key and close it safely.

  - ### current

    private PASamplerInstrumentPool current()
    Returns the currently active sub-pool (may be null).

  - ### setActive

    public void setActive(String key)
    Activate the given pool key for subsequent play() calls.

  - ### getActiveKey

    public String getActiveKey()

  - ### play

    public int play(float amplitude, float pitch, float pan)
    Plays the instrument's entire buffer, from PAPlayable interface.
    Specified by:
      `play` in interface `PAPlayable`
    Parameters:
      `amplitude` - gain multiplier (0..1+)
      `pitch` - playback rate or pitch factor (implementation-defined)
      `pan` - stereo pan (-1 left .. +1 right)
    Returns:
      non-zero if a voice/event was triggered

  - ### stop

    public void stop()
    Description copied from interface: `PAPlayable`
    Stop playback immediately (implementation-defined).
    Specified by:
      `stop` in interface `PAPlayable`

  - ### play

    public int play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)
    PASamplerPlayable's play method, all six standard parameters in standard order, called by other methods.
    Specified by:
      `play` in interface `PASamplerPlayable`

  - ### isLooping

    public boolean isLooping()

  - ### stopAll

    public void stopAll()

  - ### playSample

    public int playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)
    Description copied from interface: `PASamplerPlayable`
    Play a subrange of the buffer with full parameters.
    Specified by:
      `playSample` in interface `PASamplerPlayable`

  - ### playSample

    public int playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch)

  - ### playSample

    public int playSample(int samplePos, int sampleLen, float amplitude, float pitch, float pan)

  - ### playSample

    public int playSample(int samplePos, int sampleLen, float amplitude)
    Description copied from interface: `PASamplerPlayable`
    Play subrange with amplitude only.
    Specified by:
      `playSample` in interface `PASamplerPlayable`

  - ### playSample

    public int playSample(int samplePos, int sampleLen, float amplitude, float pitch)
    Description copied from interface: `PASamplerPlayable`
    Play subrange with amplitude and pitch (no envelope).
    Specified by:
      `playSample` in interface `PASamplerPlayable`

  - ### playSample

    public int playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env)

  - ### playSample

    public int playSample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)

  - ### playSample

    public int playSample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch)

  - ### playSample

    public int playSample(String tag, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)

  - ### hasPool

    public boolean hasPool(String tag)

  - ### getPoolByTag

    public PASamplerInstrumentPool getPoolByTag(String tag)

  - ### setBuffer

    public void setBuffer(ddf.minim.MultiChannelBuffer newBuffer)
    Propagate new buffer to all sub-pools, keeping sample rates intact.

  - ### setBuffer

    public void setBuffer(ddf.minim.MultiChannelBuffer newBuffer, float newSampleRate)
    Propagate new buffer and sample rate to all sub-pools.

  - ### setBuffer

    public void setBuffer(float[] newBuffer, float newSampleRate)
    Propagate float[] buffer to all sub-pools (mono assumption).

  - ### updateRateFromOutput

    public void updateRateFromOutput()
    Update sample rates of all sub-pools from AudioOutput.

  - ### setMasterGain

    public void setMasterGain(float linear)

  - ### resizeAllPools

    public void resizeAllPools(int newPoolSize, int newVoicesPerInstrument)
    Adjust size or polyphony of all sub-pools gracefully.

  - ### close

    public void close()
    Close all sub-pools and release shared resources.

  - ### isClosed

    public boolean isClosed()

  - ### getPoolCount

    public int getPoolCount()

  - ### getPools

    public Map<String,PASamplerInstrumentPool> getPools()

  - ### debugPrintState

    public void debugPrintState()