harmonex v0.1.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 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

alteration()
alteration ::
  :natural |
  :flat |
  :sharp |
  :double_flat |
  :double_sharp
bare_name()
bare_name() :: :a | :b | :c | :d | :e | :f | :g
interval_diatonic()
interval_diatonic() :: {quality, 1..7}
quality()
quality() :: :perfect | :diminished | :augmented | :minor | :major
semitones()
semitones() :: 0..11
t()
t ::
  %{bare_name: bare_name, alteration: alteration} |
  %{bare_name: bare_name} |
  atom

Functions

alteration(pitch)
alteration(%{alteration: alteration} | atom) :: alteration

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
bare_name(pitch)
bare_name(%{bare_name: bare_name} | atom) :: bare_name

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
enharmonic?(pitch1, pitch2)
enharmonic?(t, t) :: boolean

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
full_name(pitch)
full_name(t) :: atom

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(low_pitch, high_pitch)
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
{:error, "Not a diatonic interval"}
new(name)
new(atom) :: t | {:error, binary}

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)"}
new(bare_name, alteration)
new(bare_name, alteration) :: t | {:error, binary}

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, :double_sharp, :flat, :natural, :sharp]"}
semitones(low_pitch, high_pitch)
semitones(t, t) :: semitones

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