Copyright | (c) Hans Hoglund, Edward Lilley 2012–2014 |
---|---|
License | BSD-style |
Maintainer | hans@hanshoglund.se |
Stability | experimental |
Portability | non-portable (TF,GNTD) |
Safe Haskell | None |
Language | Haskell2010 |
Provides a standard pitch representation.
- data Accidental
- natural :: Accidental
- flat :: Accidental
- sharp :: Accidental
- doubleFlat :: Accidental
- doubleSharp :: Accidental
- isNatural :: Accidental -> Bool
- isFlattened :: Accidental -> Bool
- isSharpened :: Accidental -> Bool
- isStandardAccidental :: Accidental -> Bool
- data Name
- data Pitch
- mkPitch :: Name -> Accidental -> Pitch
- name :: Pitch -> Name
- accidental :: Pitch -> Accidental
- upDiatonicP :: Pitch -> DiatonicSteps -> Pitch -> Pitch
- downDiatonicP :: Pitch -> DiatonicSteps -> Pitch -> Pitch
- upChromaticP :: Pitch -> ChromaticSteps -> Pitch -> Pitch
- downChromaticP :: Pitch -> ChromaticSteps -> Pitch -> Pitch
- invertDiatonicallyP :: Pitch -> Pitch -> Pitch
- invertChromaticallyP :: Pitch -> Pitch -> Pitch
- asPitch :: Pitch -> Pitch
Accidentals
data Accidental Source
An accidental is either flat, natural or sharp.
This representation allows for an arbitrary number of flats or sharps rather than just single and double.
The Num
and Enum
instances treat Accidental
as the number of altered semitones,
i.e. a double flat is -2
, natural 0
and so on.
Enum Accidental | |
Eq Accidental | |
Integral Accidental | |
Num Accidental | |
Ord Accidental | |
Real Accidental | |
Show Accidental | |
Alterable Accidental | |
(IsPitch a, Alterable a) => IsPitch (Accidental -> a) | Magic instance that allow us to write |
The natural accidental.
flat :: Accidental Source
The flat accidental.
The sharp accidental.
doubleFlat :: Accidental Source
The double flat accidental.
doubleSharp :: Accidental Source
The double sharp accidental.
Inspecting accidentals
isNatural :: Accidental -> Bool Source
Returns whether this is a natural accidental.
isFlattened :: Accidental -> Bool Source
Returns whether this is a flat, double flat etc.
isSharpened :: Accidental -> Bool Source
Returns whether this is a sharp, double sharp etc.
isStandardAccidental :: Accidental -> Bool Source
Returns whether this is a standard accidental, i.e. either a double flat, flat, natural, sharp or double sharp.
Name
Pitch
Common pitch representation.
Intervals and pitches can be added using .+^
. To get the interval between
two pitches, use .-.
.
Pitches are normally entered using the following literals.
c d e f g a b
Notes with accidentals can be written by adding the s
or b
suffices
(or two for double sharps and flats).
cs, ds, es ... -- sharp cb, db, eb ... -- flat css, dss, ess ... -- double sharp cbb, dbb, ebb ... -- double flat
There is also a convenience syntax for entering pitches one octave up or
down, using '
and _
respectively.
g a b c' d c b_ c
Because of some overloading magic, we can actually write sharp
and
flat
as postfix functions. This gives a better read:
cs == c sharp db == c flat
You can of course use typical functional transformation of pitch as well.
For example sharpen
and flatten
are the ordinary (prefix) versions of
sharp
and flat
sharpen c == c sharp == cs flatten d == d flat == ds (sharpen . sharpen) c == c doubleSharp == css (flatten . flatten) d == d doubleFlat == dss
Note that there is no guarantee that your pitch representation use
enharmonic equivalence, so cs == db
may or may not hold.
c .+^ minor third == eb f .-. c == perfect fourth
Pitches are described by name, accidental and octave number.
c == fromIntegral 0 _P4 == perfect fourth == interval Perfect 5 d5 == diminished fifth == diminish (perfect fifth)
mkPitch :: Name -> Accidental -> Pitch Source
Creates a pitch from name accidental.
accidental :: Pitch -> Accidental Source
Diatonic and chromatic pitch
upDiatonicP :: Pitch -> DiatonicSteps -> Pitch -> Pitch Source
downDiatonicP :: Pitch -> DiatonicSteps -> Pitch -> Pitch Source
upChromaticP :: Pitch -> ChromaticSteps -> Pitch -> Pitch Source
downChromaticP :: Pitch -> ChromaticSteps -> Pitch -> Pitch Source
invertDiatonicallyP :: Pitch -> Pitch -> Pitch Source
invertChromaticallyP :: Pitch -> Pitch -> Pitch Source