# `TuningFork.Sample.Bank`
[🔗](https://github.com/jaman/tuning_fork/blob/v0.1.11/tuning_fork/lib/tuning_fork/sample/bank.ex#L1)

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)

# `file`

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

# `name`

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

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear`

```elixir
@spec clear() :: :ok
```

Forget every registration.

# `copy`

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

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

# `count`

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

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

# `fetch`

```elixir
@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?`

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

Whether `name` is registered, loaded or not.

# `names`

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

Every registered name, sorted.

# `nearest`

```elixir
@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`

```elixir
@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`

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

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

# `put`

```elixir
@spec put(
  name(),
  file() | [file()] | %{required(String.t()) =&gt; 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

  * `:root` — the pitch the recording is, as `TuningFork.Sample.load!/2` takes it

# `put_all`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
