module Music.Theory.Tuning.Partch where
import qualified Data.Map.Strict as M
import Data.Ratio
import qualified Music.Theory.Tuning as T
orelate :: Integral i => Ratio i -> i -> Ratio i
orelate :: forall i. Integral i => Ratio i -> i -> Ratio i
orelate Ratio i
r i
m = forall n. (Ord n, Fractional n) => n -> n
T.fold_ratio_to_octave_err (Ratio i
r forall a. Num a => a -> a -> a
* (i
m forall a. Integral a => a -> a -> Ratio a
% i
1))
urelate :: Integral i => Ratio i -> i -> Ratio i
urelate :: forall i. Integral i => Ratio i -> i -> Ratio i
urelate Ratio i
r i
m = forall n. (Ord n, Fractional n) => n -> n
T.fold_ratio_to_octave_err (Ratio i
r forall a. Num a => a -> a -> a
* (i
1 forall a. Integral a => a -> a -> Ratio a
% i
m))
itd_map :: [Integer] -> M.Map (Int,Int) Rational
itd_map :: [Integer] -> Map (Int, Int) Rational
itd_map [Integer]
relation =
let limit :: Int
limit = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Integer]
relation
z :: [Rational]
z = forall a b. (a -> b) -> [a] -> [b]
map (forall i. Integral i => Ratio i -> i -> Ratio i
orelate Rational
1) [Integer]
relation
c0 :: [((Int, Int), Rational)]
c0 = forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. (a -> b) -> [a] -> [b]
map (\Int
n -> (Int
n,Int
0)) [Int
0 .. Int
limit forall a. Num a => a -> a -> a
- Int
1]) [Rational]
z
cN :: [((Int, Int), Rational)]
cN = [((Int
i,Int
k),forall i. Integral i => Ratio i -> i -> Ratio i
urelate ([Rational]
z forall a. [a] -> Int -> a
!! Int
i) ([Integer]
relation forall a. [a] -> Int -> a
!! Int
k)) |
Int
i <- [Int
0 .. Int
limit forall a. Num a => a -> a -> a
- Int
1],
Int
k <- [Int
1 .. Int
limit forall a. Num a => a -> a -> a
- Int
1]]
in forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([((Int, Int), Rational)]
c0 forall a. [a] -> [a] -> [a]
++ [((Int, Int), Rational)]
cN)
map_to_table :: t -> (Int,Int) -> M.Map (Int,Int) t -> [[t]]
map_to_table :: forall t. t -> (Int, Int) -> Map (Int, Int) t -> [[t]]
map_to_table t
k (Int
nr,Int
nc) Map (Int, Int) t
m =
[[forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault t
k (Int
i,Int
j) Map (Int, Int) t
m | Int
j <- [Int
0 .. Int
nc forall a. Num a => a -> a -> a
- Int
1]] | Int
i <- [Int
0 .. Int
nr forall a. Num a => a -> a -> a
- Int
1]]
itd_tbl :: [Integer] -> [[Rational]]
itd_tbl :: [Integer] -> [[Rational]]
itd_tbl [Integer]
r =
let err :: a
err = forall a. HasCallStack => [Char] -> a
error [Char]
"itd_tbl"
n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Integer]
r
in forall t. t -> (Int, Int) -> Map (Int, Int) t -> [[t]]
map_to_table forall {a}. a
err (Int
n,Int
n) ([Integer] -> Map (Int, Int) Rational
itd_map [Integer]
r)