TuningFork.Sample.Bank (TuningFork v0.1.11)

Copy Markdown View Source

Recordings by name, for TuningFork.Kit to find.

TuningFork.Sample.Bank.put(:bell, "sounds/bell.flac", root: :a4)
TuningFork.Sample.Bank.put(:sd, ["sd/one.wav", "sd/two.wav"])
Kit.voice("sd:1", 0.25)

Summary

Functions

Returns a specification to start this module under a supervisor.

Forget every registration.

Register to with the same files as from; nothing happens when from is not registered.

How many files name holds; 0 for a name nobody registered.

The sample registered as name, read from disk or fetched if it has not been yet.

Whether name is registered, loaded or not.

Every registered name, sorted.

Which file of a pitched name plays midi, as {index, note}: the file recorded nearest the note, and the note it was recorded at; n picks among files sharing that note, wrapping. nil for a name that is not pitched.

The MIDI note each file of a pitched name was recorded at, in file order; nil for a name that is not pitched or not registered.

Start fetching every file of name still on the web, in the background.

Register name as one file, a list of files, a map of note names to files, or a sample already loaded.

Register every entry of a map or keyword of names to files.

Types

file()

@type file() :: Path.t() | TuningFork.Sample.t() | {Path.t(), keyword()}

name()

@type name() :: atom() | String.t()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Forget every registration.

copy(from, to)

@spec copy(name(), name()) :: :ok

Register to with the same files as from; nothing happens when from is not registered.

count(name)

@spec count(name()) :: non_neg_integer()

How many files name holds; 0 for a name nobody registered.

fetch(name, index \\ 0, opts \\ [])

@spec fetch(name(), integer(), keyword()) ::
  {:ok, TuningFork.Sample.t()} | :loading | :error

The sample registered as name, read from disk or fetched if it has not been yet.

index picks one of several files, wrapping round; default the first. :error for a name nobody registered, and for a file that will not read.

Options

  • :wait — whether to wait for a file still to be fetched from the web, default true. With false the fetch is started in the background and the answer is :loading until it is there; a file on disk is read either way

has?(name)

@spec has?(name()) :: boolean()

Whether name is registered, loaded or not.

names()

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

Every registered name, sorted.

nearest(name, midi, n)

@spec nearest(name(), number(), integer()) :: {non_neg_integer(), number()} | nil

Which file of a pitched name plays midi, as {index, note}: the file recorded nearest the note, and the note it was recorded at; n picks among files sharing that note, wrapping. nil for a name that is not pitched.

notes(name)

@spec notes(name()) :: [number()] | nil

The MIDI note each file of a pitched name was recorded at, in file order; nil for a name that is not pitched or not registered.

prefetch(name)

@spec prefetch(name()) :: :ok

Start fetching every file of name still on the web, in the background.

put(name, files, opts \\ [])

@spec put(
  name(),
  file() | [file()] | %{required(String.t()) => file() | [file()]},
  keyword()
) :: :ok

Register name as one file, a list of files, a map of note names to files, or a sample already loaded.

A file is a path or an http(s):// URL, which is fetched into the cache on first use, or {path, opts} with options of its own for TuningFork.Sample.load!/2 (:loop, :gain, :root). A list is read by index with fetch/2, wrapping. A map (%{"C3" => "c3.wav", "Fs3" => [...]}) is a pitched instrument: nearest/3 picks the file for a note, and each note may hold a list; a note is a name or a MIDI number, fractional when the recording lies between two. Registering a name again with the same files and options keeps what has been loaded; different files start it afresh.

Options, for files

put_all(entries)

@spec put_all(Enumerable.t()) :: :ok

Register every entry of a map or keyword of names to files.