module Music.Theory.Tuning.Anamark where
import Text.Printf
import qualified Music.Theory.List as T
tun_sec :: String -> String
tun_sec :: String -> String
tun_sec = forall r. PrintfType r => String -> r
printf String
"[%s]"
tun_attr_txt :: (String,String) -> String
tun_attr_txt :: (String, String) -> String
tun_attr_txt (String
k,String
v) = forall r. PrintfType r => String -> r
printf String
"%s = \"%s\"" String
k String
v
tun_attr_int :: (String,Int) -> String
tun_attr_int :: (String, Int) -> String
tun_attr_int (String
k,Int
v) = forall r. PrintfType r => String -> r
printf String
"%s = %d" String
k Int
v
tun_attr_real :: (String,Double) -> String
tun_attr_real :: (String, Double) -> String
tun_attr_real (String
k,Double
v) = forall r. PrintfType r => String -> r
printf String
"%s = %f" String
k Double
v
tun_begin :: [String]
tun_begin :: [String]
tun_begin =
[String -> String
tun_sec String
"Scale Begin"
,(String, String) -> String
tun_attr_txt (String
"Format",String
"AnaMark-TUN")
,(String, Int) -> String
tun_attr_int (String
"FormatVersion",Int
200)
,(String, String) -> String
tun_attr_txt (String
"FormatSpecs",String
"http://www.mark-henning.de/eternity/tuningspecs.html")]
tun_info :: (String,String) -> [String]
tun_info :: (String, String) -> [String]
tun_info (String
nm,String
k) =
[String -> String
tun_sec String
"Info"
,(String, String) -> String
tun_attr_txt (String
"Name",String
nm)
,(String, String) -> String
tun_attr_txt (String
"ID",String
k)]
tun_tuning :: [Int] -> [String]
tun_tuning :: [Int] -> [String]
tun_tuning =
let f :: t -> t -> t
f t
k t
c = forall r. PrintfType r => String -> r
printf String
"note %d = %d" t
k t
c
in (:) (String -> String
tun_sec String
"Tuning") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {t} {t} {t}.
(PrintfArg t, PrintfArg t, PrintfType t) =>
t -> t -> t
f [Int
0::Int .. Int
127]
tun_f0_default :: Double
tun_f0_default :: Double
tun_f0_default = Double
8.1757989156437073336
tun_exact_tuning :: Double -> [Double] -> [String]
tun_exact_tuning :: Double -> [Double] -> [String]
tun_exact_tuning Double
f0 =
let f :: t -> t -> t
f t
k t
c = forall r. PrintfType r => String -> r
printf String
"note %d = %f" t
k t
c
hdr :: [String]
hdr = [String -> String
tun_sec String
"Exact Tuning"
,(String, Double) -> String
tun_attr_real (String
"BaseFreq",Double
f0)]
in forall a. [a] -> [a] -> [a]
(++) [String]
hdr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {t} {t} {t}.
(PrintfArg t, PrintfArg t, PrintfType t) =>
t -> t -> t
f [Int
0::Int .. Int
127]
tun_functional_tuning :: Double -> [Double] -> [String]
tun_functional_tuning :: Double -> [Double] -> [String]
tun_functional_tuning Double
f0 =
let f :: t -> t -> t
f t
k t
c = forall r. PrintfType r => String -> r
printf String
"note %d = \"#x=%d %% %f\"" t
k (t
k forall a. Num a => a -> a -> a
- t
1) t
c
hdr :: [String]
hdr = [String -> String
tun_sec String
"Functional Tuning"
,forall r. PrintfType r => String -> r
printf String
"note 0 = \"# %f\"" Double
f0]
in forall a. [a] -> [a] -> [a]
(++) [String]
hdr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {t} {t} {t}.
(PrintfArg t, PrintfArg t, PrintfType t, Num t) =>
t -> t -> t
f [Int
1::Int .. Int
127] forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => [a] -> [a]
T.d_dx
tun_end :: [String]
tun_end :: [String]
tun_end =
[String -> String
tun_sec String
"Scale End"]
type TUN = [String]
tun_from_cents_version_one :: (Double, [Double]) -> TUN
tun_from_cents_version_one :: (Double, [Double]) -> [String]
tun_from_cents_version_one (Double
f0,[Double]
c) =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Int] -> [String]
tun_tuning (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (RealFrac a, Integral b) => a -> b
round [Double]
c)
,Double -> [Double] -> [String]
tun_exact_tuning Double
f0 [Double]
c]
tun_from_cents_version_two :: (String,String) -> (Double, [Double]) -> TUN
tun_from_cents_version_two :: (String, String) -> (Double, [Double]) -> [String]
tun_from_cents_version_two (String
nm,String
k) (Double
f0,[Double]
c) =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[String]
tun_begin
,(String, String) -> [String]
tun_info (String
nm,String
k)
,[Int] -> [String]
tun_tuning (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (RealFrac a, Integral b) => a -> b
round [Double]
c)
,Double -> [Double] -> [String]
tun_exact_tuning Double
f0 [Double]
c
,Double -> [Double] -> [String]
tun_functional_tuning Double
f0 [Double]
c
,[String]
tun_end]
tun_store :: FilePath -> TUN -> IO ()
tun_store :: String -> [String] -> IO ()
tun_store String
fn = String -> String -> IO ()
writeFile String
fn forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unlines