module Music.Theory.Tuning.Hs where
import Data.List
import Data.Ratio
import qualified Safe
import qualified Music.Theory.Pitch as T
import Music.Theory.Tuning
import Music.Theory.Tuning.Type
harmonic_series :: Integer -> Maybe Rational -> Tuning
harmonic_series :: Integer -> Maybe Rational -> Tuning
harmonic_series Integer
n Maybe Rational
o = Either [Rational] [Cents]
-> Maybe (Either Rational Cents) -> Tuning
Tuning (forall a b. a -> Either a b
Left [Rational
1 .. Integer
nforall a. Integral a => a -> a -> Ratio a
%Integer
1]) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. a -> Either a b
Left Maybe Rational
o)
harmonic_series_cps :: (Num t, Enum t) => t -> [t]
harmonic_series_cps :: forall t. (Num t, Enum t) => t -> [t]
harmonic_series_cps t
n = [t
n,t
n forall a. Num a => a -> a -> a
* t
2 ..]
harmonic_series_cps_n :: (Num a, Enum a) => Int -> a -> [a]
harmonic_series_cps_n :: forall a. (Num a, Enum a) => Int -> a -> [a]
harmonic_series_cps_n Int
n = forall a. Int -> [a] -> [a]
take Int
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (Num t, Enum t) => t -> [t]
harmonic_series_cps
subharmonic_series_cps :: (Fractional t,Enum t) => t -> [t]
subharmonic_series_cps :: forall t. (Fractional t, Enum t) => t -> [t]
subharmonic_series_cps t
n = forall a b. (a -> b) -> [a] -> [b]
map ((forall a. Num a => a -> a -> a
* t
n) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Fractional a => a -> a
recip) [t
1..]
subharmonic_series_cps_n :: (Fractional t,Enum t) => Int -> t -> [t]
subharmonic_series_cps_n :: forall t. (Fractional t, Enum t) => Int -> t -> [t]
subharmonic_series_cps_n Int
n = forall a. Int -> [a] -> [a]
take Int
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (Fractional t, Enum t) => t -> [t]
subharmonic_series_cps
partial :: (Num a, Enum a) => a -> Int -> a
partial :: forall a. (Num a, Enum a) => a -> Int -> a
partial a
f1 Int
k = forall t. (Num t, Enum t) => t -> [t]
harmonic_series_cps a
f1 forall a. Partial => [a] -> Int -> a
`Safe.at` (Int
k forall a. Num a => a -> a -> a
- Int
1)
harmonic_series_cps_derived :: (RealFrac a, Floating a, Enum a) => Int -> a -> [a]
harmonic_series_cps_derived :: forall a. (RealFrac a, Floating a, Enum a) => Int -> a -> [a]
harmonic_series_cps_derived Int
k a
f1 =
let f0 :: a
f0 = forall f. (Floating f, RealFrac f) => f -> f -> f
T.cps_in_octave_above a
f1 (forall a. (Num a, Enum a) => a -> Int -> a
partial a
f1 Int
k)
in forall t. (Num t, Enum t) => t -> [t]
harmonic_series_cps a
f0
harmonic_series_folded_r :: Integer -> [Rational]
harmonic_series_folded_r :: Integer -> [Rational]
harmonic_series_folded_r Integer
n = forall a. Eq a => [a] -> [a]
nub (forall a. Ord a => [a] -> [a]
sort (forall a b. (a -> b) -> [a] -> [b]
map forall n. (Ord n, Fractional n) => n -> n
fold_ratio_to_octave_err [Rational
1 .. Integer
nforall a. Integral a => a -> a -> Ratio a
%Integer
1]))
harmonic_series_folded_c :: Integer -> [Cents]
harmonic_series_folded_c :: Integer -> [Cents]
harmonic_series_folded_c = forall a b. (a -> b) -> [a] -> [b]
map forall i. Integral i => Ratio i -> Cents
ratio_to_cents forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> [Rational]
harmonic_series_folded_r
harmonic_series_folded :: Integer -> Tuning
harmonic_series_folded :: Integer -> Tuning
harmonic_series_folded Integer
n = Either [Rational] [Cents]
-> Maybe (Either Rational Cents) -> Tuning
Tuning (forall a b. a -> Either a b
Left (Integer -> [Rational]
harmonic_series_folded_r Integer
n)) forall a. Maybe a
Nothing
harmonic_series_folded_21 :: Tuning
harmonic_series_folded_21 :: Tuning
harmonic_series_folded_21 = Integer -> Tuning
harmonic_series_folded Integer
21