TuningFork.Sample.Font (TuningFork v0.1.4)

Copy Markdown View Source

Soundfont instruments as Strudel plays them: one file per instrument, a zone per key range, each zone a recording with its root pitch and loop.

{:ok, sample} = TuningFork.Sample.Font.sample("0040_JCLive_sf2_file", 60)

Summary

Functions

Returns a specification to start this module under a supervisor.

Forget every font loaded.

The zone's recording as a TuningFork.Sample, decoded through TuningFork.Sample.Decode when it is a compressed file. index names it in the cache.

Fetch, decode and keep the font name; :ok when it is there, {:error, reason} when not.

Whether the font name is loaded.

The zones written in a webaudiofont file, undecoded. {:error, reason} for text that is not one.

Start loading the font name in the background and return at once.

The recording to play midi on the font name, decoded and kept once fetched.

Where font files are fetched from; source/1 changes it.

Fetch font files from url instead of Strudel's host.

The zone of zones covering midi, or nil.

Types

zone()

@type zone() :: %{
  low: integer(),
  high: integer(),
  root: float(),
  rate: pos_integer(),
  loop: {non_neg_integer(), pos_integer()} | nil,
  data: {:file, binary()} | {:pcm, binary()},
  sample: TuningFork.Sample.t() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Forget every font loaded.

decode(zone, name, index)

@spec decode(zone(), String.t(), non_neg_integer()) ::
  {:ok, TuningFork.Sample.t()} | {:error, term()}

The zone's recording as a TuningFork.Sample, decoded through TuningFork.Sample.Decode when it is a compressed file. index names it in the cache.

load(name)

@spec load(String.t()) :: :ok | {:error, term()}

Fetch, decode and keep the font name; :ok when it is there, {:error, reason} when not.

loaded?(name)

@spec loaded?(String.t()) :: boolean()

Whether the font name is loaded.

parse(text)

@spec parse(String.t()) :: {:ok, [zone()]} | {:error, term()}

The zones written in a webaudiofont file, undecoded. {:error, reason} for text that is not one.

prefetch(name)

@spec prefetch(String.t()) :: :ok

Start loading the font name in the background and return at once.

sample(name, midi, opts \\ [])

@spec sample(String.t(), number(), keyword()) ::
  {:ok, TuningFork.Sample.t()} | :loading | :error

The recording to play midi on the font name, decoded and kept once fetched.

Options

  • :wait — whether to fetch and decode a font not loaded yet, default true. With false that starts in the background and the answer is :loading until it is done

:error for a font that cannot be fetched or a note no zone covers.

source()

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

Where font files are fetched from; source/1 changes it.

source(url)

@spec source(String.t()) :: :ok

Fetch font files from url instead of Strudel's host.

zone_for(zones, midi)

@spec zone_for([zone()], number()) :: zone() | nil

The zone of zones covering midi, or nil.