harmonex v0.5.0 Harmonex.Interval View Source

Provides functions for working with intervals between pitches on the Western dodecaphonic scale.

Link to this section Summary

Types

The qualified variation of an interval’s size

t()

An expression describing an interval

Functions

Computes the interval between the specified low_pitch and high_pitch

Constructs a new interval with the specified definition

Constructs a new interval with the specified quality and size

Computes the distance in half steps across the specified interval

Computes the simple interval that corresponds to the specified interval. Simple intervals are no more than 11 semitones across (see semitones/1)

Link to this section Types

Link to this type interval() View Source
interval() :: %Harmonex.Interval{quality: quality, size: integer}

A Harmonex.Interval struct.

Link to this type quality() View Source
quality ::
  :perfect |
  :minor |
  :major |
  :diminished |
  :augmented |
  :doubly_diminished |
  :doubly_augmented

The qualified variation of an interval’s size.

Link to this type t() View Source
t() :: %{quality: quality, size: integer}

An expression describing an interval.

Link to this section Functions

Computes the interval between the specified low_pitch and high_pitch.

Examples

iex> Harmonex.Interval.from_pitches %{natural_name: :a, accidental: :sharp}, %{natural_name: :c}
%Harmonex.Interval{quality: :diminished, size: 3}

iex> Harmonex.Interval.from_pitches :b_flat, :c
%Harmonex.Interval{quality: :major, size: 2}

iex> Harmonex.Interval.from_pitches :d_double_sharp, :a_double_sharp
%Harmonex.Interval{quality: :perfect, size: 5}

iex> Harmonex.Interval.from_pitches :c_flat, :c_natural
%Harmonex.Interval{quality: :augmented, size: 1}

iex> Harmonex.Interval.from_pitches :a_flat, :e_sharp
%Harmonex.Interval{quality: :doubly_augmented, size: 5}

iex> Harmonex.Interval.from_pitches :a_flat, :e_double_sharp
{:error, "Invalid interval"}

Constructs a new interval with the specified definition.

Examples

iex> Harmonex.Interval.new %{quality: :perfect, size: 1}
%Harmonex.Interval{quality: :perfect, size: 1}

iex> Harmonex.Interval.new %{quality: :minor, size: -10}
%Harmonex.Interval{quality: :minor, size: -10}

iex> Harmonex.Interval.new %{quality: :perfect, size: 0}
{:error, "Size cannot be zero"}

iex> Harmonex.Interval.new %{quality: :minor, size: 1}
{:error, "Quality of unison must be in [:perfect, :augmented, :doubly_augmented]"}

iex> Harmonex.Interval.new %{quality: :major, size: 8}
{:error, "Quality of octave must be in [:perfect, :diminished, :augmented, :doubly_diminished, :doubly_augmented]"}

Constructs a new interval with the specified quality and size.

Examples

iex> Harmonex.Interval.new :perfect, 1
%Harmonex.Interval{quality: :perfect, size: 1}

iex> Harmonex.Interval.new :minor, -10
%Harmonex.Interval{quality: :minor, size: -10}

iex> Harmonex.Interval.new :perfect, 0
{:error, "Size cannot be zero"}

iex> Harmonex.Interval.new :minor, 1
{:error, "Quality of unison must be in [:perfect, :augmented, :doubly_augmented]"}

iex> Harmonex.Interval.new :major, 8
{:error, "Quality of octave must be in [:perfect, :diminished, :augmented, :doubly_diminished, :doubly_augmented]"}
Link to this function semitones(interval) View Source
semitones(t) :: integer | Harmonex.error

Computes the distance in half steps across the specified interval.

Examples

iex> Harmonex.Interval.semitones %{quality: :major, size: 3}
4

iex> Harmonex.Interval.semitones %{quality: :doubly_diminished, size: -9}
-11

iex> Harmonex.Interval.semitones %{quality: :doubly_diminished, size: 16}
23

iex> Harmonex.Interval.semitones %{quality: :augmented, size: -300}
-514

Computes the simple interval that corresponds to the specified interval. Simple intervals are no more than 11 semitones across (see semitones/1).

Examples

iex> Harmonex.Interval.simplify %{quality: :major, size: -10}
%Harmonex.Interval{quality: :major, size: -3}

iex> Harmonex.Interval.simplify %{quality: :major, size: 3}
%Harmonex.Interval{quality: :major, size: 3}

iex> Harmonex.Interval.simplify %{quality: :augmented, size: -8}
%Harmonex.Interval{quality: :augmented, size: -1}

iex> Harmonex.Interval.simplify %{quality: :diminished, size: 8}
%Harmonex.Interval{quality: :diminished, size: 8}