module Music.Theory.Tuning.Meyer_1929 where
import Data.List
import Data.Ratio
import qualified Music.Theory.Tuning as T
odd_to :: (Num t, Enum t) => t -> [t]
odd_to :: forall t. (Num t, Enum t) => t -> [t]
odd_to t
n = [t
1,t
3 .. t
n]
row :: Integral i => i -> [Ratio i]
row :: forall i. Integral i => i -> [Ratio i]
row = 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 forall n. (Ord n, Fractional n) => n -> n
T.fold_ratio_to_octave_err forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (Num t, Enum t) => t -> [t]
odd_to forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Integral a => a -> a -> Ratio a
% i
1)
column :: Integral i => i -> [Ratio i]
column :: forall i. Integral i => i -> [Ratio i]
column = forall a b. (a -> b) -> [a] -> [b]
map (forall n. (Ord n, Fractional n) => n -> n
T.fold_ratio_to_octave_err forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Fractional a => a -> a
recip) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => i -> [Ratio i]
row
in_oct_mul :: Integral i => Ratio i -> Ratio i -> Ratio i
in_oct_mul :: forall i. Integral i => Ratio i -> Ratio i -> Ratio i
in_oct_mul Ratio i
i Ratio i
j = forall n. (Ord n, Fractional n) => n -> n
T.fold_ratio_to_octave_err (Ratio i
i forall a. Num a => a -> a -> a
* Ratio i
j)
inner :: Integral i => ([Ratio i],[Ratio i]) -> (i,i) -> Ratio i
inner :: forall i. Integral i => ([Ratio i], [Ratio i]) -> (i, i) -> Ratio i
inner ([Ratio i]
r,[Ratio i]
c) (i
i,i
j) = forall i. Integral i => Ratio i -> Ratio i -> Ratio i
in_oct_mul ([Ratio i]
r forall i a. Integral i => [a] -> i -> a
`genericIndex` i
j) ([Ratio i]
c forall i a. Integral i => [a] -> i -> a
`genericIndex` i
i)
meyer_table_rck :: Integral i => i -> ([Ratio i],[Ratio i],i)
meyer_table_rck :: forall i. Integral i => i -> ([Ratio i], [Ratio i], i)
meyer_table_rck i
n =
let r :: [Ratio i]
r = forall i. Integral i => i -> [Ratio i]
row i
n
c :: [Ratio i]
c = forall i. Integral i => i -> [Ratio i]
column i
n
k :: i
k = i
n forall a. Integral a => a -> a -> a
`div` i
2
in ([Ratio i]
r,[Ratio i]
c,i
k)
meyer_table_indices :: Integral i => i -> [(i,i,Ratio i)]
meyer_table_indices :: forall i. Integral i => i -> [(i, i, Ratio i)]
meyer_table_indices i
n =
let ([Ratio i]
r,[Ratio i]
c,i
k) = forall i. Integral i => i -> ([Ratio i], [Ratio i], i)
meyer_table_rck i
n
in [(i
i,i
j,forall i. Integral i => ([Ratio i], [Ratio i]) -> (i, i) -> Ratio i
inner ([Ratio i]
r,[Ratio i]
c) (i
i,i
j)) | i
i <- [i
0..i
k], i
j <- [i
0..i
k]]
meyer_table_rows :: Integral a => a -> [[Ratio a]]
meyer_table_rows :: forall a. Integral a => a -> [[Ratio a]]
meyer_table_rows a
n =
let ([Ratio a]
r,[Ratio a]
c,a
k) = forall i. Integral i => i -> ([Ratio i], [Ratio i], i)
meyer_table_rck a
n
rn :: a -> [Ratio a]
rn a
i = [forall i. Integral i => ([Ratio i], [Ratio i]) -> (i, i) -> Ratio i
inner ([Ratio a]
r,[Ratio a]
c) (a
i,a
j) | a
j <- [a
0..a
k]]
in forall a b. (a -> b) -> [a] -> [b]
map a -> [Ratio a]
rn [a
0..a
k]
t3_3 :: (t1,t2,t3) -> t3
t3_3 :: forall t1 t2 t3. (t1, t2, t3) -> t3
t3_3 (t1
_,t2
_,t3
i) = t3
i
elements :: Integral i => i -> [Ratio i]
elements :: forall i. Integral i => i -> [Ratio i]
elements = forall a. Eq a => [a] -> [a]
nub 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 (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> [[Ratio a]]
meyer_table_rows
degree :: Integral i => i -> i
degree :: forall i. Integral i => i -> i
degree = forall i a. Num i => [a] -> i
genericLength forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => i -> [Ratio i]
elements
farey_sequence :: Integral a => a -> [Ratio a]
farey_sequence :: forall i. Integral i => i -> [Ratio i]
farey_sequence a
k = Ratio a
0 forall a. a -> [a] -> [a]
: forall a. Eq a => [a] -> [a]
nub (forall a. Ord a => [a] -> [a]
sort [a
nforall a. Integral a => a -> a -> Ratio a
%a
d | a
d <- [a
1..a
k], a
n <- [a
1..a
d]])