TuningFork.SonicPi.Thread (TuningFork v0.1.11)

Copy Markdown View Source

What one Sonic Pi thread carries while its code runs, and the score it played.

Summary

Functions

Put a voice, or several, at the thread's time under one node reference.

Close the innermost effect.

Change an open effect's options for everything played after this moment.

Record a change to every note under ref, taking effect at the thread's time.

Draw from the thread's generator with fun, keeping the generator that comes back.

A thread at time zero, seeded from seed. capture: true collects loops; ambient: true marks a thread nobody started a round or a buffer for.

Open an effect around what is played until close_fx/2.

What the thread played, as a score.

Seconds for beats at the thread's tempo.

Move the thread on by beats.

Types

event()

@type event() :: %{
  at: float(),
  voice: TuningFork.Voice.t(),
  ref: reference(),
  midi: number() | nil,
  amp: float(),
  segments: [reference()],
  controls: [{float(), keyword()}]
}

t()

@type t() :: %TuningFork.SonicPi.Thread{
  ambient: boolean(),
  bpm: float(),
  capture: boolean(),
  events: [event()],
  fx: %{
    required(reference()) => %{
      name: atom(),
      opts: keyword(),
      segment: reference()
    }
  },
  fx_stack: [reference()],
  loops: [{atom(), (-> term()), map(), float()}],
  now: float(),
  rand: TuningFork.Rand.t(),
  sample_defaults: keyword(),
  segments: %{required(reference()) => keyword()},
  synth: atom() | String.t() | TuningFork.Voice.t(),
  synth_defaults: keyword(),
  transpose: integer()
}

Functions

add(thread, voices, ref, opts)

@spec add(t(), TuningFork.Voice.t() | [TuningFork.Voice.t()], reference(), keyword()) ::
  t()

Put a voice, or several, at the thread's time under one node reference.

close_fx(thread, id)

@spec close_fx(t(), reference()) :: t()

Close the innermost effect.

control_fx(thread, id, opts)

@spec control_fx(t(), reference(), keyword()) :: t()

Change an open effect's options for everything played after this moment.

control_note(thread, ref, opts)

@spec control_note(t(), reference(), keyword()) :: t()

Record a change to every note under ref, taking effect at the thread's time.

draw(thread, fun)

@spec draw(t(), (TuningFork.Rand.t() -> {value, TuningFork.Rand.t()})) :: {value, t()}
when value: term()

Draw from the thread's generator with fun, keeping the generator that comes back.

new(seed, opts \\ [])

@spec new(term(), keyword()) :: t()

A thread at time zero, seeded from seed. capture: true collects loops; ambient: true marks a thread nobody started a round or a buffer for.

open_fx(thread, name, opts)

@spec open_fx(t(), atom(), keyword()) :: {reference(), t()}

Open an effect around what is played until close_fx/2.

score(thread, mode \\ :loop)

@spec score(t(), :loop | :once) :: {:ok, TuningFork.Score.t()} | {:error, String.t()}

What the thread played, as a score.

As a :loop, the default, the score is as long as the thread slept, and {:error, message} comes back when it never slept. Played :once, the score runs to the end of the last note if that is later, and only a thread that played nothing is an error.

seconds(thread, beats)

@spec seconds(t(), number()) :: float()

Seconds for beats at the thread's tempo.

sleep(thread, beats)

@spec sleep(t(), number()) :: t()

Move the thread on by beats.