harmonex v0.2.0 Harmonex.Pitch
Provides functions for working with pitches on the Western dodecaphonic scale.
Summary
Functions
Computes the alteration of the specified pitch
Computes the bare name of the specified pitch
Determines whether the specified pitch1
and pitch2
are enharmonically
equivalent
Computes the enharmonic equivalents of the specified pitch
Computes the full name of the specified pitch
Computes the quality and number of the interval between the specified
low_pitch
and high_pitch
Constructs a new Harmonex.Pitch
with the specified name
Constructs a new Harmonex.Pitch
with the specified bare_name
and
alteration
Computes the distance in half steps between the specified low_pitch
and
high_pitch
Types
quality :: :perfect | :doubly_diminished | :diminished | :augmented | :doubly_augmented | :minor | :major
Functions
Computes the alteration of the specified pitch
.
Examples
iex> Harmonex.Pitch.alteration %{alteration: :flat}
:flat
iex> Harmonex.Pitch.alteration :a
:natural
iex> Harmonex.Pitch.alteration :a_flat
:flat
Computes the bare name of the specified pitch
.
Examples
iex> Harmonex.Pitch.bare_name %{bare_name: :a}
:a
iex> Harmonex.Pitch.bare_name :a
:a
iex> Harmonex.Pitch.bare_name :a_flat
:a
Determines whether the specified pitch1
and pitch2
are enharmonically
equivalent.
Examples
iex> Harmonex.Pitch.enharmonic? %{bare_name: :g, alteration: :sharp}, :a_flat
true
iex> Harmonex.Pitch.enharmonic? :c_flat, %{bare_name: :a, alteration: :double_sharp}
true
iex> Harmonex.Pitch.enharmonic? :b_sharp, :d_double_flat
true
iex> Harmonex.Pitch.enharmonic? :a_sharp, :a_natural
false
Computes the enharmonic equivalents of the specified pitch
.
Examples
iex> Harmonex.Pitch.enharmonics :f_double_sharp
[:g_natural, :a_double_flat]
iex> Harmonex.Pitch.enharmonics %{bare_name: :g, alteration: :sharp}
[%Harmonex.Pitch{bare_name: :a, alteration: :flat}]
iex> Harmonex.Pitch.enharmonics :c_flat
[:a_double_sharp, :b_natural]
iex> Harmonex.Pitch.enharmonics :b_sharp
[:c_natural, :d_double_flat]
iex> Harmonex.Pitch.enharmonics :a_sharp
[:b_flat, :c_double_flat]
Computes the full name of the specified pitch
.
Examples
iex> Harmonex.Pitch.full_name %{bare_name: :a, alteration: :flat}
:a_flat
iex> Harmonex.Pitch.full_name %{bare_name: :a}
:a
iex> Harmonex.Pitch.full_name :a
:a
iex> Harmonex.Pitch.full_name :a_flat
:a_flat
interval_diatonic(t, t) :: interval_diatonic | {:error, binary}
Computes the quality and number of the interval between the specified
low_pitch
and high_pitch
.
Examples
iex> Harmonex.Pitch.interval_diatonic %{bare_name: :a, alteration: :sharp}, %{bare_name: :c}
{:diminished, 3}
iex> Harmonex.Pitch.interval_diatonic :b_flat, :c
{:major, 2}
iex> Harmonex.Pitch.interval_diatonic :d_double_sharp, :a_double_sharp
{:perfect, 5}
iex> Harmonex.Pitch.interval_diatonic :c_flat, :c_natural
{:augmented, 1}
iex> Harmonex.Pitch.interval_diatonic :a_flat, :e_sharp
{:doubly_augmented, 5}
iex> Harmonex.Pitch.interval_diatonic :a_flat, :e_double_sharp
{:error, "Not a diatonic interval"}
Constructs a new Harmonex.Pitch
with the specified name
.
Examples
iex> Harmonex.Pitch.new :a
%Harmonex.Pitch{bare_name: :a, alteration: :natural}
iex> Harmonex.Pitch.new :a_flat
%Harmonex.Pitch{bare_name: :a, alteration: :flat}
iex> Harmonex.Pitch.new :h
{:error, "Invalid pitch name -- must be in [:a, :b, :c, :d, :e, :f, :g] with an optional alteration (e.g, :a_flat)"}
Constructs a new Harmonex.Pitch
with the specified bare_name
and
alteration
.
Examples
iex> Harmonex.Pitch.new :a, :flat
%Harmonex.Pitch{bare_name: :a, alteration: :flat}
iex> Harmonex.Pitch.new :a, :out_of_tune
{:error, "Invalid pitch alteration -- must be in [:double_flat, :flat, :natural, :sharp, :double_sharp]"}
Computes the distance in half steps between the specified low_pitch
and
high_pitch
.
Examples
iex> Harmonex.Pitch.semitones %{bare_name: :a, alteration: :flat}, %{bare_name: :c, alteration: :sharp}
5
iex> Harmonex.Pitch.semitones :a_flat, :b_flat
2
iex> Harmonex.Pitch.semitones :d_double_sharp, :b_double_sharp
9