hmt-0.15: Haskell Music Theory

Safe Haskell | Safe
Language | Haskell98

Music.Theory.Pitch.Note

Contents

- Note
- Alteration
- Generalised Alteration

Description

Common music notation note and alteration values.

Synopsis

- data Note_T
  - = C
  - | D
  - | E
  - | F
  - | G
  - | A
  - | B
- note_to_pc :: Integral i => Note_T -> i
- note_t_transpose :: Note_T -> Int -> Note_T
- data Alteration_T
  - = DoubleFlat
  - | ThreeQuarterToneFlat
  - | Flat
  - | QuarterToneFlat
  - | Natural
  - | QuarterToneSharp
  - | Sharp
  - | ThreeQuarterToneSharp
  - | DoubleSharp
- generic_alteration_to_diff :: Integral i => Alteration_T -> Maybe i
- alteration_to_diff :: Alteration_T -> Maybe Int
- alteration_is_12et :: Alteration_T -> Bool
- alteration_to_diff_err :: Integral i => Alteration_T -> i
- alteration_to_fdiff :: Fractional n => Alteration_T -> n
- fdiff_to_alteration :: (Fractional n, Eq n) => n -> Maybe Alteration_T
- alteration_raise_quarter_tone :: Alteration_T -> Maybe Alteration_T
- alteration_lower_quarter_tone :: Alteration_T -> Maybe Alteration_T
- alteration_edit_quarter_tone :: (Fractional n, Eq n) => n -> Alteration_T -> Maybe Alteration_T
- alteration_clear_quarter_tone :: Alteration_T -> Alteration_T
- alteration_symbol :: Alteration_T -> Char
- alteration_iso_m :: Alteration_T -> Maybe String
- alteration_iso :: Alteration_T -> String
- alteration_tonh :: Alteration_T -> String
- type Alteration_T' = (Rational, String)
- alteration_t' :: Alteration_T -> Alteration_T'
- type Spelling n = n -> (Note_T, Alteration_T)

# Note

data Note_T Source #

Enumeration of common music notation note names (`C` to `B`).

Constructors

C |
D |
E |
F |
G |
A |
B |

Instances

Bounded Note_T Source # |
Methods minBound :: Note_T # maxBound :: Note_T #
Enum Note_T Source # |
Methods succ :: Note_T -> Note_T # pred :: Note_T -> Note_T # toEnum :: Int -> Note_T # fromEnum :: Note_T -> Int # enumFrom :: Note_T -> [Note_T] # enumFromThen :: Note_T -> Note_T -> [Note_T] # enumFromTo :: Note_T -> Note_T -> [Note_T] # enumFromThenTo :: Note_T -> Note_T -> Note_T -> [Note_T] #
Eq Note_T Source # |
Methods (==) :: Note_T -> Note_T -> Bool # (/=) :: Note_T -> Note_T -> Bool #
Ord Note_T Source # |
Methods compare :: Note_T -> Note_T -> Ordering # (<) :: Note_T -> Note_T -> Bool # (<=) :: Note_T -> Note_T -> Bool # (>) :: Note_T -> Note_T -> Bool # (>=) :: Note_T -> Note_T -> Bool # max :: Note_T -> Note_T -> Note_T # min :: Note_T -> Note_T -> Note_T #
Show Note_T Source # |
Methods showsPrec :: Int -> Note_T -> ShowS # show :: Note_T -> String # showList :: [Note_T] -> ShowS #

note_to_pc :: Integral i => Note_T -> i Source #

Transform `Note_T` to pitch-class number.

    map note_to_pc [C,E,G] == [0,4,7]

note_t_transpose :: Note_T -> Int -> Note_T Source #

Modal transposition of `Note_T` value.

    note_t_transpose C 2 == E

# Alteration

data Alteration_T Source #

Enumeration of common music notation note alterations.

Constructors

DoubleFlat |
ThreeQuarterToneFlat |
Flat |
QuarterToneFlat |
Natural |
QuarterToneSharp |
Sharp |
ThreeQuarterToneSharp |
DoubleSharp |

Instances

Bounded Alteration_T Source # |
Methods minBound :: Alteration_T # maxBound :: Alteration_T #
Enum Alteration_T Source # |

Methods

succ :: Alteration_T -> Alteration_T #

pred :: Alteration_T -> Alteration_T #

toEnum :: Int -> Alteration_T #

fromEnum :: Alteration_T -> Int #

enumFrom :: Alteration_T -> [Alteration_T] #

enumFromThen :: Alteration_T -> Alteration_T -> [Alteration_T] #

enumFromTo :: Alteration_T -> Alteration_T -> [Alteration_T] #

enumFromThenTo :: Alteration_T -> Alteration_T -> Alteration_T -> [Alteration_T] #

Eq Alteration_T Source # |
Methods (==) :: Alteration_T -> Alteration_T -> Bool # (/=) :: Alteration_T -> Alteration_T -> Bool #
Ord Alteration_T Source # |
Methods compare :: Alteration_T -> Alteration_T -> Ordering # (<) :: Alteration_T -> Alteration_T -> Bool # (<=) :: Alteration_T -> Alteration_T -> Bool # (>) :: Alteration_T -> Alteration_T -> Bool # (>=) :: Alteration_T -> Alteration_T -> Bool # max :: Alteration_T -> Alteration_T -> Alteration_T # min :: Alteration_T -> Alteration_T -> Alteration_T #
Show Alteration_T Source # |
Methods showsPrec :: Int -> Alteration_T -> ShowS # show :: Alteration_T -> String # showList :: [Alteration_T] -> ShowS #

generic_alteration_to_diff :: Integral i => Alteration_T -> Maybe i Source #

Generic form.

alteration_to_diff :: Alteration_T -> Maybe Int Source #

Transform `Alteration_T` to semitone alteration. Returns `Nothing` for non-semitone alterations.

    map alteration_to_diff [Flat,QuarterToneSharp] == [Just (-1),Nothing]

alteration_is_12et :: Alteration_T -> Bool Source #

Is `Alteration_T` 12-ET.

alteration_to_diff_err :: Integral i => Alteration_T -> i Source #

Transform `Alteration_T` to semitone alteration.

    map alteration_to_diff_err [Flat,Sharp] == [-1,1]

alteration_to_fdiff :: Fractional n => Alteration_T -> n Source #

Transform `Alteration_T` to fractional semitone alteration, ie. allow quarter tones.

    alteration_to_fdiff QuarterToneSharp == 0.5

fdiff_to_alteration :: (Fractional n, Eq n) => n -> Maybe Alteration_T Source #

Transform fractional semitone alteration to `Alteration_T`, ie. allow quarter tones.

    map fdiff_to_alteration [-0.5,0.5] == [Just QuarterToneFlat
                                          ,Just QuarterToneSharp]

alteration_raise_quarter_tone :: Alteration_T -> Maybe Alteration_T Source #

Raise `Alteration_T` by a quarter tone where possible.

    alteration_raise_quarter_tone Flat == Just QuarterToneFlat
    alteration_raise_quarter_tone DoubleSharp == Nothing

alteration_lower_quarter_tone :: Alteration_T -> Maybe Alteration_T Source #

Lower `Alteration_T` by a quarter tone where possible.

    alteration_lower_quarter_tone Sharp == Just QuarterToneSharp
    alteration_lower_quarter_tone DoubleFlat == Nothing

alteration_edit_quarter_tone :: (Fractional n, Eq n) => n -> Alteration_T -> Maybe Alteration_T Source #

Edit `Alteration_T` by a quarter tone where possible, `-0.5` lowers, `0` retains, `0.5` raises.

    import Data.Ratio
    alteration_edit_quarter_tone (-1 % 2) Flat == Just ThreeQuarterToneFlat

alteration_clear_quarter_tone :: Alteration_T -> Alteration_T Source #

Simplify `Alteration_T` to standard 12ET by deleting quarter tones.

    Data.List.nub (map alteration_clear_quarter_tone [minBound..maxBound])

alteration_symbol :: Alteration_T -> Char Source #

Unicode has entries for Musical Symbols in the range `U+1D100` through `U+1D1FF`. The `3/4` symbols are non-standard, here they correspond to `MUSICAL SYMBOL FLAT DOWN` and `MUSICAL SYMBOL SHARP UP`.

    map alteration_symbol [minBound .. maxBound] == "𝄫𝄭♭𝄳♮𝄲♯𝄰𝄪"

alteration_iso_m :: Alteration_T -> Maybe String Source #

The `ISO` ASCII spellings for alterations. Naturals as written as the empty string.

    mapMaybe alteration_iso_m [Flat .. Sharp] == ["b","","#"]

alteration_iso :: Alteration_T -> String Source #

The `ISO` ASCII spellings for alterations.

alteration_tonh :: Alteration_T -> String Source #

The Tonhöhe ASCII spellings for alterations.

See http://www.musiccog.ohio-state.edu/Humdrum/guide04.html and http://lilypond.org/doc/v2.16/Documentation/notation/writing-pitches

    map alteration_tonh [Flat .. Sharp] == ["es","eh","","ih","is"]

# Generalised Alteration

type Alteration_T' = (Rational, String) Source #

Generalised alteration, given as a rational semitone difference and a string representation of the alteration.

alteration_t' :: Alteration_T -> Alteration_T' Source #

Transform `Alteration_T` to `Alteration_T'`.

    let r = [(-1,"♭"),(0,"♮"),(1,"♯")]
    in map alteration_t' [Flat,Natural,Sharp] == r

type Spelling n = n -> (Note_T, Alteration_T) Source #

Function to spell a `PitchClass`.