module Music.Theory.Tuning.Gann_1993 where
import Data.List
import Data.Maybe
import qualified Music.Theory.List as T
import qualified Music.Theory.Math as T
import qualified Music.Theory.Pitch as T
import qualified Music.Theory.Tuning as T
import qualified Music.Theory.Tuning.Graph.Euler as T
import qualified Music.Theory.Tuning.Type as T
lmy_wtp_r :: [Rational]
lmy_wtp_r :: [Rational]
lmy_wtp_r =
[Rational
1,Rational
567forall a. Fractional a => a -> a -> a
/Rational
512
,Rational
9forall a. Fractional a => a -> a -> a
/Rational
8,Rational
147forall a. Fractional a => a -> a -> a
/Rational
128
,Rational
21forall a. Fractional a => a -> a -> a
/Rational
16
,Rational
1323forall a. Fractional a => a -> a -> a
/Rational
1024,Rational
189forall a. Fractional a => a -> a -> a
/Rational
128
,Rational
3forall a. Fractional a => a -> a -> a
/Rational
2,Rational
49forall a. Fractional a => a -> a -> a
/Rational
32
,Rational
7forall a. Fractional a => a -> a -> a
/Rational
4,Rational
441forall a. Fractional a => a -> a -> a
/Rational
256
,Rational
63forall a. Fractional a => a -> a -> a
/Rational
32]
lmy_wtp_ratio_to_pc :: Rational -> Maybe T.PitchClass
lmy_wtp_ratio_to_pc :: Rational -> Maybe PitchClass
lmy_wtp_ratio_to_pc Rational
r = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall i. Integral i => i -> i
T.mod12 forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
+ PitchClass
3)) (forall a. Eq a => a -> [a] -> Maybe PitchClass
elemIndex Rational
r [Rational]
lmy_wtp_r)
lmy_wtp_ratio_to_pc_err :: Rational -> T.PitchClass
lmy_wtp_ratio_to_pc_err :: Rational -> PitchClass
lmy_wtp_ratio_to_pc_err = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => [Char] -> a
error [Char]
"lmy_wtp_ratio_to_pc") forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Maybe PitchClass
lmy_wtp_ratio_to_pc
lmy_wtp_univ :: [(Rational,(T.PitchClass,T.PitchClass))]
lmy_wtp_univ :: [(Rational, (PitchClass, PitchClass))]
lmy_wtp_univ =
let f :: (Rational, Rational) -> Maybe (Rational, (PitchClass, PitchClass))
f (Rational
p,Rational
q) = if Rational
p forall a. Ord a => a -> a -> Bool
< Rational
q
then forall a. a -> Maybe a
Just (forall i. Integral i => Ratio i -> Ratio i
T.ratio_interval_class (Rational
pforall a. Fractional a => a -> a -> a
/Rational
q)
,(Rational -> PitchClass
lmy_wtp_ratio_to_pc_err Rational
p
,Rational -> PitchClass
lmy_wtp_ratio_to_pc_err Rational
q))
else forall a. Maybe a
Nothing
in forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Rational, Rational) -> Maybe (Rational, (PitchClass, PitchClass))
f (forall t u. [t] -> [u] -> [(t, u)]
T.all_pairs [Rational]
lmy_wtp_r [Rational]
lmy_wtp_r)
lmy_wtp_uniq :: [(Rational,[(T.PitchClass,T.PitchClass)])]
lmy_wtp_uniq :: [(Rational, [(PitchClass, PitchClass)])]
lmy_wtp_uniq = forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (forall t. Integral t => Ratio t -> t
T.ratio_nd_sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) (forall k a v. Ord k => (a -> k) -> (a -> v) -> [a] -> [(k, [v])]
T.collate_on forall a b. (a, b) -> a
fst forall a b. (a, b) -> b
snd [(Rational, (PitchClass, PitchClass))]
lmy_wtp_univ)
lmy_wtp :: T.Tuning
lmy_wtp :: Tuning
lmy_wtp = Either [Rational] [Cents]
-> Maybe (Either Rational Cents) -> Tuning
T.Tuning (forall a b. a -> Either a b
Left [Rational]
lmy_wtp_r) forall a. Maybe a
Nothing
lmy_wtp_1964_r :: [Rational]
lmy_wtp_1964_r :: [Rational]
lmy_wtp_1964_r =
let n :: [Rational]
n = [Rational
1,Rational
279,Rational
9,Rational
147,Rational
21,Rational
93,Rational
189,Rational
3,Rational
49,Rational
7,Rational
31,Rational
63]
d :: [Rational]
d = [Rational
1,Rational
256,Rational
8,Rational
128,Rational
16,Rational
64,Rational
128,Rational
2,Rational
32,Rational
4,Rational
16,Rational
32]
in forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. Fractional a => a -> a -> a
(/) [Rational]
n [Rational]
d
lmy_wtp_1964 :: T.Tuning
lmy_wtp_1964 :: Tuning
lmy_wtp_1964 = Either [Rational] [Cents]
-> Maybe (Either Rational Cents) -> Tuning
T.Tuning (forall a b. a -> Either a b
Left [Rational]
lmy_wtp_1964_r) forall a. Maybe a
Nothing
lmy_wtp_euler :: T.Euler_Plane Rational
lmy_wtp_euler :: Euler_Plane Rational
lmy_wtp_euler =
let {l1 :: [Rational]
l1 = PitchClass -> Rational -> Rational -> [Rational]
T.tun_seq PitchClass
4 (Rational
3forall a. Fractional a => a -> a -> a
/Rational
2) (Rational
49forall a. Fractional a => a -> a -> a
/Rational
32)
;l2 :: [Rational]
l2 = PitchClass -> Rational -> Rational -> [Rational]
T.tun_seq PitchClass
5 (Rational
3forall a. Fractional a => a -> a -> a
/Rational
2) (Rational
7forall a. Fractional a => a -> a -> a
/Rational
4)
;l3 :: [Rational]
l3 = PitchClass -> Rational -> Rational -> [Rational]
T.tun_seq PitchClass
3 (Rational
3forall a. Fractional a => a -> a -> a
/Rational
2) Rational
1
;([(Rational, Rational)]
c1,[(Rational, Rational)]
c2) = (Rational, Rational)
-> T3 [Rational]
-> ([(Rational, Rational)], [(Rational, Rational)])
T.euler_align_rat (Rational
7forall a. Fractional a => a -> a -> a
/Rational
4,Rational
7forall a. Fractional a => a -> a -> a
/Rational
4) ([Rational]
l1,[Rational]
l2,[Rational]
l3)}
in ([[Rational]
l1,[Rational]
l2,[Rational]
l3],[(Rational, Rational)]
c1 forall a. [a] -> [a] -> [a]
++ [(Rational, Rational)]
c2)