module Music.Theory.Tuning.Efg where
import Data.List
import qualified Music.Theory.List as T
import qualified Music.Theory.Set.List as T
import Music.Theory.Tuning
type Efg i = [(i,Int)]
efg_degree :: Efg i -> Int
efg_degree :: forall i. Efg i -> Int
efg_degree = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd
efg_tones :: Efg i -> Int
efg_tones :: forall i. Efg i -> Int
efg_tones = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map ((forall a. Num a => a -> a -> a
+ Int
1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd)
efg_collate :: Ord i => [i] -> Efg i
efg_collate :: forall i. Ord i => [i] -> Efg i
efg_collate = forall i. Ord i => [i] -> Efg i
T.histogram forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> [a]
sort
efg_factors :: Efg i -> [([Int],[i])]
efg_factors :: forall i. Efg i -> [([Int], [i])]
efg_factors Efg i
efg =
let k :: [[Int]]
k = forall a b. (a -> b) -> [a] -> [b]
map (\(i
_,Int
n) -> [Int
0 .. Int
n]) Efg i
efg
k' :: [[Int]]
k' = if forall (t :: * -> *) a. Foldable t => t a -> Int
length Efg i
efg forall a. Eq a => a -> a -> Bool
== Int
1
then forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *) a. Monad m => a -> m a
return) [[Int]]
k
else forall a. [[a]] -> [[a]]
T.nfold_cartesian_product [[Int]]
k
z :: [i]
z = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst Efg i
efg
f :: [Int] -> ([Int], [i])
f [Int]
ix = ([Int]
ix,forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Int
n Int
m -> forall a. Int -> a -> [a]
replicate Int
n ([i]
z forall a. [a] -> Int -> a
!! Int
m)) [Int]
ix [Int
0..]))
in forall a b. (a -> b) -> [a] -> [b]
map [Int] -> ([Int], [i])
f [[Int]]
k'
efg_ratios :: Real r => Rational -> Efg r -> [([Int],Rational)]
efg_ratios :: forall r. Real r => Rational -> Efg r -> [([Int], Rational)]
efg_ratios Rational
n =
let to_r :: [r] -> Rational
to_r = forall n. (Ord n, Fractional n) => n -> n
fold_ratio_to_octave_err forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Fractional a => a -> a -> a
/ Rational
n) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Real a => a -> Rational
toRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product
f :: (a, [r]) -> (a, Rational)
f (a
ix,[r]
i) = (a
ix,[r] -> Rational
to_r [r]
i)
in forall a b. (a -> b) -> [a] -> [b]
map forall {a}. (a, [r]) -> (a, Rational)
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Efg i -> [([Int], [i])]
efg_factors
efg_diagram_set :: (Enum n,Real n) => (Cents -> n,n,n,n) -> [Efg n] -> [(n,n,n,n)]
efg_diagram_set :: forall n.
(Enum n, Real n) =>
(Cents -> n, n, n, n) -> [Efg n] -> [(n, n, n, n)]
efg_diagram_set (Cents -> n
to_f,n
h,n
m,n
k) [Efg n]
e =
let f :: Efg n -> [n]
f = (forall a. [a] -> [a] -> [a]
++ [n
1200]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (Cents -> n
to_f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => Ratio i -> Cents
ratio_to_cents forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Real r => Rational -> Efg r -> [([Int], Rational)]
efg_ratios Rational
1
g :: ([c], n) -> [(c, n, c, n)]
g ([c]
c,n
y) = let y' :: n
y' = n
y forall a. Num a => a -> a -> a
+ n
h
b :: [(c, n, c, n)]
b = [(c
0,n
y,c
1200,n
y),(c
0,n
y',c
1200,n
y')]
in [(c, n, c, n)]
b forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (\c
x -> (c
x,n
y forall a. Num a => a -> a -> a
+ n
m,c
x,n
y' forall a. Num a => a -> a -> a
- n
m)) [c]
c
in forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {c}. Num c => ([c], n) -> [(c, n, c, n)]
g (forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. (a -> b) -> [a] -> [b]
map Efg n -> [n]
f [Efg n]
e) [n
0,n
k ..])