module Music.Theory.Interval.Barlow_1987 where
import Data.List
import Data.Ratio
import Text.Printf
import qualified Music.Theory.Math as T
import qualified Music.Theory.Math.Prime as T
import qualified Music.Theory.Tuning as T
barlow :: (Integral a,Fractional b) => a -> b
barlow :: forall a b. (Integral a, Fractional b) => a -> b
barlow a
p =
let p' :: b
p' = forall a b. (Integral a, Num b) => a -> b
fromIntegral a
p
square :: a -> a
square a
n = a
n forall a. Num a => a -> a -> a
* a
n
in b
2 forall a. Num a => a -> a -> a
* (forall {a}. Num a => a -> a
square (b
p' forall a. Num a => a -> a -> a
- b
1) forall a. Fractional a => a -> a -> a
/ b
p')
disharmonicity :: (Integral a,Num b) => (a -> b) -> (a,a) -> b
disharmonicity :: forall a b. (Integral a, Num b) => (a -> b) -> (a, a) -> b
disharmonicity a -> b
pv (a
p,a
q) =
let n :: [(a, Int)]
n = forall i. Integral i => (i, i) -> [(i, Int)]
T.rat_prime_factors_m (a
p,a
q)
in forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [forall {a}. Num a => a -> a
abs (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
j) forall a. Num a => a -> a -> a
* a -> b
pv a
i | (a
i,Int
j) <- [(a, Int)]
n]
harmonicity :: (Integral a,Fractional b) => (a -> b) -> (a,a) -> b
harmonicity :: forall a b. (Integral a, Fractional b) => (a -> b) -> (a, a) -> b
harmonicity a -> b
pv = forall a. Fractional a => a -> a
recip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => (a -> b) -> (a, a) -> b
disharmonicity a -> b
pv
harmonicity_m :: (Eq b,Integral a,Fractional b) => (a -> b) -> (a,a) -> Maybe b
harmonicity_m :: forall b a.
(Eq b, Integral a, Fractional b) =>
(a -> b) -> (a, a) -> Maybe b
harmonicity_m a -> b
pv = forall a. (Eq a, Fractional a) => a -> Maybe a
T.recip_m forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => (a -> b) -> (a, a) -> b
disharmonicity a -> b
pv
harmonicity_r :: (Integral a,Fractional b) => (a -> b) -> Ratio a -> b
harmonicity_r :: forall a b. (Integral a, Fractional b) => (a -> b) -> Ratio a -> b
harmonicity_r a -> b
pv = forall a b. (Integral a, Fractional b) => (a -> b) -> (a, a) -> b
harmonicity a -> b
pv forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Integral t => Ratio t -> (t, t)
T.rational_nd
harmonicity_r_100 :: (RealFrac b, Integral a) => (a -> b) -> Ratio a -> Int
harmonicity_r_100 :: forall b a. (RealFrac b, Integral a) => (a -> b) -> Ratio a -> Int
harmonicity_r_100 a -> b
pv Ratio a
x =
case forall b a.
(Eq b, Integral a, Fractional b) =>
(a -> b) -> (a, a) -> Maybe b
harmonicity_m a -> b
pv (forall t. Integral t => Ratio t -> (t, t)
T.rational_nd Ratio a
x) of
Maybe b
Nothing -> Int
100
Just b
y -> forall a b. (RealFrac a, Integral b) => a -> b
round (b
y forall a. Num a => a -> a -> a
* b
100)
type Table_2_Row = (Double,[Int],Rational,Double)
mk_table_2_row :: Rational -> Table_2_Row
mk_table_2_row :: Rational -> Table_2_Row
mk_table_2_row Rational
r =
(forall r n. (Real r, Floating n) => r -> n
T.fratio_to_cents Rational
r
,forall i. (Integral i, Show i) => Int -> (i, i) -> [Int]
T.rat_prime_factors_t Int
6 (forall t. Integral t => Ratio t -> (t, t)
T.rational_nd Rational
r)
,Rational
r
,forall a b. (Integral a, Fractional b) => (a -> b) -> Ratio a -> b
harmonicity_r forall a b. (Integral a, Fractional b) => a -> b
barlow Rational
r)
table_2 :: Double -> [Table_2_Row]
table_2 :: Double -> [Table_2_Row]
table_2 Double
z =
let g :: a -> Bool
g a
n = a
n forall a. Ord a => a -> a -> Bool
<= a
2 Bool -> Bool -> Bool
&& a
n forall a. Ord a => a -> a -> Bool
>= a
1
r :: [Rational]
r = forall a. Eq a => [a] -> [a]
nub (forall a. Ord a => [a] -> [a]
sort (forall a. (a -> Bool) -> [a] -> [a]
filter forall {a}. (Ord a, Num a) => a -> Bool
g [Integer
p forall a. Integral a => a -> a -> Ratio a
% Integer
q | Integer
p <- [Integer
1..Integer
81],Integer
q <- [Integer
1..Integer
81]]))
f :: (a, b, c, Double) -> Bool
f (a
_,b
_,c
_,Double
h) = Double
h forall a. Ord a => a -> a -> Bool
> Double
z
in forall a. (a -> Bool) -> [a] -> [a]
filter forall {a} {b} {c}. (a, b, c, Double) -> Bool
f (forall a b. (a -> b) -> [a] -> [b]
map Rational -> Table_2_Row
mk_table_2_row [Rational]
r)
table_2_pp :: Table_2_Row -> String
table_2_pp :: Table_2_Row -> String
table_2_pp (Double
i,[Int]
j,Rational
k,Double
l) =
let i' :: String
i' = forall r. PrintfType r => String -> r
printf String
"%8.3f" Double
i
j' :: String
j' = [String] -> String
unwords (forall a b. (a -> b) -> [a] -> [b]
map (forall r. PrintfType r => String -> r
printf String
"%2d") [Int]
j)
k' :: String
k' = let (Integer
p,Integer
q) = forall t. Integral t => Ratio t -> (t, t)
T.rational_nd Rational
k in forall r. PrintfType r => String -> r
printf String
"%2d:%-2d" Integer
q Integer
p
l' :: String
l' = forall r. PrintfType r => String -> r
printf String
"%1.6f" Double
l
in forall a. [a] -> [[a]] -> [a]
intercalate String
" | " [String
i',String
j',String
k',String
l']