music-pitch-1.9.0: Musical pitch representation.

Safe HaskellNone
LanguageHaskell2010

Music.Pitch.Common.Interval

Contents

Description

Common intervals.

Synopsis

Intervals

data Interval Source

Interval type.

Instances

Eq Interval 
Num Interval

Avoid using '(*)', or signum on intervals.

Ord Interval

Lexicographical ordering, comparing the d2 component of the Interval first, as it's tied to the Number which is expected to be bigger than the Quality, assuming ordinary tuning systems

Show Interval 
Monoid Interval 
AdditiveGroup Interval 
IsInterval Interval 
Augmentable Interval 
Semigroup Interval 
HasNumber Interval 
HasQuality Interval 
HasSemitones Interval 
VectorSpace Interval 
HasBasis Interval 
ToJSON Interval 
FromJSON Interval 
Typeable * Interval 
type Scalar Interval = Integer 
type Basis Interval = IntervalBasis 

Creating intervals

interval :: Iso' (Quality, Number) Interval Source

View an interval as a pair of quality and number or vice versa.

interval' :: Iso' (ChromaticSteps, DiatonicSteps) Interval Source

View an interval as a pair of alteration and diatonic steps or vice versa.

interval'' :: Iso' (ChromaticSteps, DiatonicSteps) Interval Source

View an interval as a pair of total number of chromatic and diatonic steps.

_number :: Lens' Interval Number Source

View or set the number component of an interval.

_quality :: Lens' Interval Quality Source

View or set the quality of an interval.

_steps :: Lens' Interval DiatonicSteps Source

View or set the number of chromatic steps in an interval.

_alteration :: Lens' Interval ChromaticSteps Source

View or set the alteration (i.e. the number of chromatic steps differing from the excepted number) in an interval.

Synonyms

perfect :: Number -> Interval Source

Creates a perfect interval. If given an inperfect number, constructs a major interval.

major :: Number -> Interval Source

Creates a major interval. If given a perfect number, constructs a perfect interval.

minor :: Number -> Interval Source

Creates a minor interval. If given a perfect number, constructs a diminished interval.

augmented :: Number -> Interval Source

Creates an augmented interval.

diminished :: Number -> Interval Source

Creates a diminished interval.

doublyAugmented :: Number -> Interval Source

Creates a doubly augmented interval.

doublyDiminished :: Number -> Interval Source

Creates a doubly diminished interval.

Inspecting intervals

isNegative :: Interval -> Bool Source

Returns whether the given interval is negative.

isPositive :: Interval -> Bool Source

Returns whether the given interval is positive.

isNonNegative :: Interval -> Bool Source

Returns whether the given interval is non-negative. This implies that it is either positive or a perfect unison.

isPerfectUnison :: Interval -> Bool Source

Returns whether the given interval a perfect unison.

isStep :: Interval -> Bool Source

Returns whether the given interval is a step (a second or smaller).

Only diatonic number is taken into account, so _A2 is considered a step and m3 a leap, even though they have the same number of semitones.

isLeap :: Interval -> Bool Source

Returns whether the given interval is a leap (larger than a second).

Only the diatonic number is taken into account, so _A2 is considered a step and m3 a leap, even though they have the same number of semitones.

Simple and compound intervals

isSimple :: Interval -> Bool Source

Returns whether the given interval is simple.

A simple interval is a non-negative interval spanning less than one octave.

isCompound :: Interval -> Bool Source

Returns whether the given interval is compound.

A compound interval is either a negative interval, or a positive interval spanning one octave or more. Note that compound intervals may be smaller than an octave if they are negative, so

>>> isCompound (-m3)
True 
>>> isCompound $ abs (-m3)
False 

separate :: Interval -> (Octaves, Interval) Source

Separate a compound interval into octaves and a simple interval.

x*^_P8 + y = z  iff  (x, y) = separate z
>>> separate (2*^_P8+m3)
(2,m3)
>>> separate (3*^_P8+m3)
(3,m3)
>>> separate (0*^_P8+m3)
(0,m3)
>>> separate ((-1)*^_P8+m3)

simple :: Interval -> Interval Source

Returns the simple part of an interval.

(perfect octave)^*x + y = z  iff  y = simple z

octaves :: Interval -> Octaves Source

Returns the non-simple part of an interval.

_P8^*octaves x ^+^ simple x = x

Inversion

invert :: Interval -> Interval Source

Intervallic inversion.

The inversion an interval is determined as follows:

  • The number of a simple interval the difference of nine and the number of its inversion.
  • The quality of a simple interval is the inversion of the quality of its inversion.
  • The inversion of a compound interval is the inversion of its simple component.

Basis values

data IntervalBasis Source

This type represents standard basis for intervbals.

Constructors

Chromatic 
Diatonic 

Converting basis

convertBasis :: Interval -> Interval -> Interval -> Maybe (Int, Int) Source

Represent an interval i in a new basis (j, k).

We want x,y where i = x*j + y*k

e.g., convertBasis basis_d2 _P5 basis_P8 == Just (-12,7), as expected.

convertBasisFloat :: (Fractional t, Eq t) => Interval -> Interval -> Interval -> Maybe (t, t) Source

Same as above, but don't worry if new interval has non-integer coefficients -- useful when getting a value to use as a frequency ratio in a tuning system.

intervalDiv :: Interval -> Interval -> Int Source

Integer div of intervals: i / di = x, where x is an integer