TuningFork.Stage.Bed (TuningFork v0.1.0)

Copy Markdown View Source

The looping layers under a TuningFork.Stage: named PCM buffers read from one playhead, each at its own gain, replaceable at a bar boundary with a cross-fade.

A bed is nil when nothing loops. chunk/3 produces the next chunk of the mix and the bed to carry forward; replace/3 and gains/2 change what plays.

Summary

Functions

The next frames frames of the mix, and the bed to carry forward.

Set the gain of the named layers; names not playing are ignored.

The playhead in frames, or nil for no bed.

Replace, or with keep: true extend, the playing set with pcms, a map of name to PCM.

Types

fade()

@type fade() :: %{
  layers: %{required(term()) => layer()},
  position: non_neg_integer(),
  left: non_neg_integer(),
  total: pos_integer()
}

layer()

@type layer() :: %{pcm: binary(), gain: float()}

t()

@type t() :: %TuningFork.Stage.Bed{
  fade: nil | fade(),
  layers: %{required(term()) => layer()},
  pending:
    nil | {%{required(term()) => layer()}, pos_integer(), non_neg_integer()},
  position: non_neg_integer()
}

Functions

chunk(bed, frames, channels)

@spec chunk(t() | nil, pos_integer(), pos_integer()) :: {binary(), t() | nil}

The next frames frames of the mix, and the bed to carry forward.

gains(bed, gains)

@spec gains(t() | nil, %{required(term()) => number()}) :: t() | nil

Set the gain of the named layers; names not playing are ignored.

position(arg1)

@spec position(t() | nil) :: non_neg_integer() | nil

The playhead in frames, or nil for no bed.

replace(bed, pcms, opts)

@spec replace(t() | nil, %{required(term()) => binary()}, keyword()) :: t()

Replace, or with keep: true extend, the playing set with pcms, a map of name to PCM.

opts are those of TuningFork.Stage.layers/3 plus :rate, needed to turn :fade_ms into frames.