module Music.Pitch.Common.Number
(
Number,
HasNumber(..),
unison,
prime,
second,
third,
fourth,
fifth,
sixth,
seventh,
octave,
ninth,
tenth,
eleventh,
twelfth,
thirteenth,
fourteenth,
fifteenth,
diatonicSteps,
) where
import Control.Lens
import Music.Pitch.Common.Types
instance HasNumber Number where number = id
unison :: Number
unison = 1
prime :: Number
prime = 1
second :: Number
second = 2
third :: Number
third = 3
fourth :: Number
fourth = 4
fifth :: Number
fifth = 5
sixth :: Number
sixth = 6
seventh :: Number
seventh = 7
octave :: Number
octave = 8
ninth :: Number
ninth = 9
tenth :: Number
tenth = 10
eleventh :: Number
eleventh = 11
twelfth :: Number
twelfth = 12
duodecim :: Number
duodecim = 12
thirteenth :: Number
thirteenth = 13
fourteenth :: Number
fourteenth = 14
fifteenth :: Number
fifteenth = 15
class HasNumber a where
number :: a -> Number
diatonicSteps :: Iso' Number DiatonicSteps
diatonicSteps = iso n2d d2n
where
n2d n | n > 0 = fromIntegral (n 1)
n2d n | n == 0 = error "diatonicSteps: Invalid number 0"
n2d n | n < 0 = fromIntegral (n + 1)
d2n n | n >= 0 = fromIntegral (n + 1)
d2n n | n < 0 = fromIntegral (n 1)