music-suite / music-pitch

This repo has been merged into: https://github.com/music-suite/music-suite
http://music-suite.github.io
BSD 3-Clause "New" or "Revised" License
9 stars 9 forks source link

Diatonic transposition (and inversion) #24

Closed hanshoglund closed 10 years ago

hanshoglund commented 10 years ago

This is easy to define for Common:

upDiatonic :: Pitch -> Number -> Pitch -> Pitch
upDiatonic origin n = relative origin $ \x -> mkInterval (quality x) (number x + n)

Is there a more generic notion, i.e. using another type function?

upSteps :: LargeStep a -> a -> a
...

Inversion is similar

invertPitchesDiatonically :: Pitch -> Pitch -> Pitch
invertPitchesDiatonically origin n = relative origin $ \x -> mkInterval (quality x) (negate (number x))

More generally

diatonically :: Pitch -> (Number -> Number) -> Pitch -> Pitch
diatonically origin f = relative origin $ \x -> mkInterval (quality x) (f (number x))

TODO use an Iso Interval (Quality, Number) for more elegant definitions.

TODO neither of these work at the moment, as mkInterval is now strict enough to complain when given perfect instead of major and vice versa.