NPVoicerSwitcher:
Filter:
Classes (extension) | Control | Live Coding

NPVoicerSwitcher
ExtensionExtension

Manages a pool of NPVoicer objects with atomic swap between current, saved, and released roles
Location: NOT INSTALLED!

Description

NPVoicerSwitcher maintains a pool of NPVoicer objects organised into three roles:

The core operation is -swapCurrentToSaved, which rotates the three roles atomically: the current voicer moves to the chosen saved slot, the previous saved voicer begins fading out and moves to the matching released slot, and the previous released voicer becomes the new current.

All Ndef proxies are created automatically in *new and are named with an optional prefix followed by an index starting at 0.

Class Methods

.new

Create a new NPVoicerSwitcher.

Arguments:

numSaves

Number of saved (and released) voicer slots. Default: 3.

voicerClass

The voicer class to instantiate for each slot. Default: NPVoicer.

prefix

A String prepended to the Ndef name of each internal voicer proxy. Default: "".

Returns:

An NPVoicerSwitcher instance.

Inherited class methods

Instance Methods

.current

Returns:

The voicer currently in the active role.

.saved

Returns:

An Array of numSaves voicers in the saved role.

.released

Returns:

An Array of numSaves voicers in the released (fading-out) role.

.allVoicers

Returns:

All managed voicers as a flat Array:. The order is always [current, saved..., released...].

.swapAction

A Function that is called after every successful -swapCurrentToSaved call. Passed arguments are:

Default: nil.

.swapCurrentToSaved

Atomically rotate the three roles for a given slot index.

Steps performed:

  1. Call releaseAll(fadeTime) on the voicer currently in saved[idx].
  2. Move that voicer to released[idx].
  3. Move the current voicer to saved[idx].
  4. Promote the voicer previously in released[idx] to current.
  5. Call -swapAction.

Arguments:

idx

Zero-based index into the saved/released arrays (0 to numSaves - 1).

fadeTime

Fade duration in seconds applied when releasing the outgoing saved voicer. Default: 5.

Returns:

The receiver.

.releaseAction

A Function that is called after every successful -releaseSaved call. Passed arguments are:

Default: nil.

.releaseSaved

Release a saved voicer by index, not moving it to the released role. This can be used to free up saved slots without affecting the current/released rotation.

Steps performed:

  1. Call releaseAll(fadeTime) on the voicer currently in saved[idx].
  2. Call -releaseAction.

Arguments:

idx

index of the saved slot to release.

Sound-related methods

.prime

Load a sound definition into the voicers. The call is forwarded to NPVoicer: -prime.

Arguments:

obj

The sound object to prime (e.g. a SynthDef name symbol).

useSpawn

Boolean — passed through to NPVoicer. Default: false.

which

Optional symbol restricting which role receives the prime call:

  • nil (default) — prime all voicers.
  • \current — prime only the current voicer.
  • \saved — prime only the saved voicers.
  • \released — prime only the released voicers.

.play

Forward a play call to every managed voicer.

Arguments:

outs

Output bus number or Array of bus numbers (wrapped if shorter than the voicer count).

numChannels

Passed through to NPVoicer. Default: nil.

group

Passed through to NPVoicer. Default: nil.

multi

Passed through to NPVoicer. Default: false.

vol

Passed through to NPVoicer. Default: nil.

fadeTime

Passed through to NPVoicer. Default: nil.

addAction

Passed through to NPVoicer. Default: nil.

.stop

Call stop(fadeTime) on every managed voicer.

Arguments:

fadeTime

Fade duration in seconds. Default: 5.

.releaseAll

Call releaseAll(fadeTime) on every managed voicer.

Arguments:

fadeTime

Fade duration in seconds. Default: 5.

Utility methods

.numSaves

Returns:

The number of saved (and released) slots.

.voicerClass

Returns:

The voicer class used when creating internal voicer objects.

.prefix

Returns:

The string prefix used for internal Ndef names.

Inherited instance methods

Examples

All examples assume the following setup:

first swap

Using swapAction to print current settings of swapped voicers

Inspect the voicer pool

Clean up