MIDI background music: music: "song.mid" is rendered to WAV with
fluidsynth and the WAV then goes through the
normal music pipeline (loop/trim, fades, ducking; see PhxDemo.Render).
The WAV is cached under <output_dir>/.tts_cache, next to narration clips,
keyed on the MIDI bytes, the soundfont (path, size and mtime) and the sample
rate. Re-recording an unchanged demo doesn't run fluidsynth again.
Soundfont
Resolved in this order:
- the
:soundfontsetting (use PhxDemo.Case, soundfont: "..."orconfig :phx_demo, :soundfont, "...") - the soundfont downloaded by
mix phx_demo.soundfont.setup - common system locations (
/usr/share/sounds/sf2/FluidR3_GM.sf2,/opt/homebrew/share/soundfonts/..., ...)
Summary
Functions
Cache key for a rendered MIDI: a hash of the MIDI bytes, the soundfont's path, size and mtime, and the sample rate.
Pre-flight for MIDI music. Returns :ok when music isn't MIDI, otherwise
checks that fluidsynth is on PATH and a soundfont resolves. settings is a
map with atom or string keys (PhxDemo.settings/1, or a timeline's).
Like check/2, raising PhxDemo.Env.Error.
Where mix phx_demo.soundfont.setup puts the default soundfont.
The fluidsynth argument list for rendering midi to out.
Whether a music: value is a MIDI file, judged by extension.
Renders midi to a WAV in cache_dir (or reuses the cached one). Returns
{:ok, wav_path} or {:error, message}. Options: :soundfont (the
setting), :rate.
Finds a soundfont. setting is the :soundfont setting (a path, or
nil/false). Options (for testing): :downloaded and :system, to override
those locations.
Directory for the soundfont downloaded by mix phx_demo.soundfont.setup.
Common system soundfont locations, in search order.
Functions
Cache key for a rendered MIDI: a hash of the MIDI bytes, the soundfont's path, size and mtime, and the sample rate.
Pre-flight for MIDI music. Returns :ok when music isn't MIDI, otherwise
checks that fluidsynth is on PATH and a soundfont resolves. settings is a
map with atom or string keys (PhxDemo.settings/1, or a timeline's).
Like check/2, raising PhxDemo.Env.Error.
Where mix phx_demo.soundfont.setup puts the default soundfont.
The fluidsynth argument list for rendering midi to out.
Whether a music: value is a MIDI file, judged by extension.
iex> PhxDemo.Midi.midi?("a/song.MID")
true
iex> PhxDemo.Midi.midi?("song.midi")
true
iex> PhxDemo.Midi.midi?("song.mp3")
false
iex> PhxDemo.Midi.midi?(false)
false
Renders midi to a WAV in cache_dir (or reuses the cached one). Returns
{:ok, wav_path} or {:error, message}. Options: :soundfont (the
setting), :rate.
Finds a soundfont. setting is the :soundfont setting (a path, or
nil/false). Options (for testing): :downloaded and :system, to override
those locations.
Returns {:ok, path}, or {:error, message}. An explicit setting that
points at a missing file is an error; it doesn't fall through.
Directory for the soundfont downloaded by mix phx_demo.soundfont.setup.
Common system soundfont locations, in search order.