TuningFork.Composer.Track (TuningForkComposer v0.1.3)

Copy Markdown View Source

One row of the grid: an instrument, and what it plays on each step.

Track.new([kind: :pitched, sound: "bass", steps: [1, 0, {3, 2}, 0]], 4)

Summary

Functions

Whether it will be heard: it plays something, and it is not muted.

Which steps are covered by a note that began earlier, one boolean per step.

A track count steps wide.

What a step holds, as {degree, length in steps}.

Bring the track to count steps.

How many steps a note at step may occupy before it meets the next one, or the distance to the end of the track when nothing follows it.

Whether this track plays anything at all.

Which step a note covering step began on, or step itself when no note covers it.

A step from a degree and a length, in the shortest form: write(3, 1) is 3, write(3, 4) is {3, 4}, and a degree of 0 is 0 whatever the length.

Types

step()

@type step() :: non_neg_integer() | {pos_integer(), pos_integer()}

t()

@type t() :: %TuningFork.Composer.Track{
  gain: float(),
  kind: :drum | :pitched | :sample,
  muted: boolean(),
  path: String.t() | nil,
  plays: String.t() | nil,
  ring: float(),
  root: atom() | nil,
  sound: String.t() | nil,
  steps: [step()]
}

Functions

audible?(track)

@spec audible?(t()) :: boolean()

Whether it will be heard: it plays something, and it is not muted.

held(track)

@spec held(t()) :: [boolean()]

Which steps are covered by a note that began earlier, one boolean per step.

new(opts \\ [], count \\ 16)

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

A track count steps wide.

opts takes any field of the struct. Fields and defaults: :kind one of :drum, :pitched or :sample (:drum), :sound an id from Composer.drums/0 or Composer.instruments/0 ("kick"), :path WAV file for :sample (nil), :root the pitch a :sample was recorded at, nil playing it as-is (nil), :gain 0.0–1.0 (0.8), :ring how long notes sound in beats, ignored by :drum (2.0), :muted (false), :plays which repeats of the grid the track plays, as a string of x and . cycled over the bars, nil for all of them (nil), :steps one entry per step ([]). Any :steps given are grown with rests or cut short to count.

A step is 0 for silence, a scale degree for a note one step long, or {degree, length} for a note held over length steps. A :drum track holds only 0 or 1.

read(degree)

@spec read(step()) :: {non_neg_integer(), pos_integer()}

What a step holds, as {degree, length in steps}.

Accepts every step form: 0 gives {0, 1}, 3 gives {3, 1}, {3, 4} gives {3, 4}. Anything else reads as {0, 1}.

resize(track, count)

@spec resize(t() | [step()], pos_integer()) :: t() | [step()]

Bring the track to count steps.

Grown with rests, or cut short. Cutting discards whatever was past the new end.

room_at(track, step)

@spec room_at(t(), non_neg_integer()) :: pos_integer()

How many steps a note at step may occupy before it meets the next one, or the distance to the end of the track when nothing follows it.

silent?(track)

@spec silent?(t()) :: boolean()

Whether this track plays anything at all.

start_of(track, step)

@spec start_of(t(), non_neg_integer()) :: non_neg_integer()

Which step a note covering step began on, or step itself when no note covers it.

write(degree, length)

@spec write(non_neg_integer(), pos_integer()) :: step()

A step from a degree and a length, in the shortest form: write(3, 1) is 3, write(3, 4) is {3, 4}, and a degree of 0 is 0 whatever the length.