TuningFork.Session (TuningFork v0.1.11)

Copy Markdown View Source

Rows of live-coded source, and the one pattern they add up to.

rows = [%{source: "s(\"bd*4\")"}, %{source: "|> gain(0.8)"}, %{source: "-- hh*8"}]
TuningFork.Session.combined(rows)

Summary

Types

A chain of rows folded into the source it makes: {first row, last row, source}.

A row of a session. Only :source is required; checked/1 writes :error. Any other key is left alone.

Functions

What a row has asked to be drawn as: :pianoroll, :scope or nil.

The whole source a row belongs to, continuations and all, or nil when it plays nothing.

The rows with :error set on the ones that will not parse and cleared on the ones that will.

Every switched-on row stacked into one pattern. A row that will not parse is left out.

Put a row's marker on, or take off whichever of off/0 is there.

Whether a row carries on the one above it rather than starting its own: it begins with |>.

Why source will not read, in one line, or nil when it reads.

The rows folded into the sources they make, as {first, last, source} chains.

Whether a row is switched on and has something in it: not blank and not beginning with one of off/0.

The markers that switch a row off, longest first.

The cycles per second the rows ask for, or nil when they do not: Strudel's setcps.

Types

chain()

@type chain() :: {non_neg_integer(), non_neg_integer(), String.t()}

A chain of rows folded into the source it makes: {first row, last row, source}.

row()

@type row() :: %{:source => String.t(), optional(:error) => String.t() | nil}

A row of a session. Only :source is required; checked/1 writes :error. Any other key is left alone.

Functions

asks?(row)

@spec asks?(row() | String.t()) :: :pianoroll | :scope | nil

What a row has asked to be drawn as: :pianoroll, :scope or nil.

Read from the parsed pattern, not from the text. nil for a row that is off or will not parse.

iex> TuningFork.Session.asks?(%{source: "s(\"bd*4\") |> scope()"})
:scope
iex> TuningFork.Session.asks?(%{source: "s(\"bd*4\")"})
nil

chain(rows, index)

@spec chain([row()], non_neg_integer()) :: String.t() | nil

The whole source a row belongs to, continuations and all, or nil when it plays nothing.

checked(rows)

@spec checked([row()]) :: [row()]

The rows with :error set on the ones that will not parse and cleared on the ones that will.

An error is reported on the row a chain starts, trimmed to one line of at most 70 characters.

combined(rows)

@spec combined([row()]) :: TuningFork.Pattern.t()

Every switched-on row stacked into one pattern. A row that will not parse is left out.

comment(source)

@spec comment(String.t()) :: String.t()

Put a row's marker on, or take off whichever of off/0 is there.

iex> TuningFork.Session.comment("s(\"bd\")")
"-- s(\"bd\")"
iex> TuningFork.Session.comment("-- s(\"bd\")")
"s(\"bd\")"
iex> TuningFork.Session.comment("_ s(\"bd\")")
"s(\"bd\")"

continues?(source)

@spec continues?(row() | String.t()) :: boolean()

Whether a row carries on the one above it rather than starting its own: it begins with |>.

iex> TuningFork.Session.continues?(%{source: "  |> scale(\"g:minor\")"})
true
iex> TuningFork.Session.continues?(%{source: "s(\"bd\")"})
false

fault(source)

@spec fault(String.t()) :: String.t() | nil

Why source will not read, in one line, or nil when it reads.

iex> TuningFork.Session.fault("s(\"bd\")")
nil
iex> TuningFork.Session.fault("|> gain(0.5)")
"|> carries on the line above, and there is none"

joined(rows)

@spec joined([row()]) :: [chain()]

The rows folded into the sources they make, as {first, last, source} chains.

first and last are indexes into rows as given. Rows that are switched off are left out; a continuation with nothing live above it is dropped.

Rows that read as Strudel (TuningFork.Strudel.strudel?/1 on all of them together) are translated by TuningFork.Strudel.chains/1 instead, one chain per voice on the rows it came from. A piece that will not translate is one chain on the row of the fault, whose source is the whole text.

iex> TuningFork.Session.joined([%{source: "s(\"bd\")"}, %{source: "|> gain(0.5)"}])
[{0, 1, "s(\"bd\") |> gain(0.5)"}]

live?(source)

@spec live?(row() | String.t()) :: boolean()

Whether a row is switched on and has something in it: not blank and not beginning with one of off/0.

iex> TuningFork.Session.live?(%{source: "s(\"bd\")"})
true
iex> TuningFork.Session.live?(%{source: "_ s(\"bd\")"})
false
iex> TuningFork.Session.live?(%{source: "   "})
false

off()

@spec off() :: [String.t()]

The markers that switch a row off, longest first.

iex> TuningFork.Session.off()
["--", "//", "_"]

tempo(rows)

@spec tempo([row()]) :: number() | nil

The cycles per second the rows ask for, or nil when they do not: Strudel's setcps.