{-# Language LambdaCase #-}
module Csound.Tab (
Tab, noTab, isNoTab,
nsamp, ftlen, ftsr, ftchnls, ftcps, tabDur,
TabFi, fineFi, coarseFi,
doubles,
newTab, newGlobalTab, tabSizeSeconds, tabSizePower2, tabSizeSecondsPower2,
WavChn(..), Mp3Chn(..),
wavs, wavAll, wavLeft, wavRight, mp3s, mp3Left, mp3Right, mp3m,
readNumFile, readTrajectoryFile, readPvocex, readMultichannel,
PartialStrength, PartialNumber, PartialPhase, PartialDC,
sines, sines3, sines2, sines1, sines4, buzzes, bwSines, bwOddSines,
mixOnTab, mixTabs,
tabSines1, tabSines2,
waveletTab, rescaleWaveletTab,
sine, cosine, sigmoid, sigmoidRise, sigmoidFall, tanhSigmoid,
triTab, sawTab, sqrTab, pwTab,
tanhTab, rescaleTanhTab, expTab, rescaleExpTab, soneTab, rescaleSoneTab,
fareyTab,
consts, lins, cubes, exps, splines, startEnds, tabseg, bpLins, bpExps,
econsts, elins, ecubes, eexps, esplines, estartEnds, etabseg,
polys, chebs1, chebs2, bessels,
uniDist, linDist, triDist, expDist, biexpDist, gaussDist,
cauchyDist, pcauchyDist, betaDist, weibullDist, poissonDist,
tabDist,
uniDist', linDist', triDist', expDist', biexpDist', gaussDist',
cauchyDist', pcauchyDist', betaDist', weibullDist', poissonDist',
randDist, rangeDist,
winHamming, winHanning, winBartlett, winBlackman,
winHarris, winGauss, winKaiser, winRectangle, winSync,
padsynth, PadsynthSpec(..), PadsynthShape(..), defPadsynthSpec,
tabHarmonics,
normTab, NormTabSpec(..), scaleTab,
gen,
skipNorm, forceNorm, setSize, setDegree, guardPoint, gp,
lllofi, llofi, lofi, midfi, hifi, hhifi, hhhifi,
idWavs, idMp3s, idDoubles, idSines, idSines3, idSines2,
idPartials, idSines4, idBuzzes, idConsts, idLins, idCubes,
idExps, idSplines, idStartEnds, idPolys, idChebs1, idChebs2, idBessels, idWins,
idPadsynth, idTanh, idExp, idSone, idFarey, idWave,
sec2rel,
TabList, tabList, fromTabList, fromTabListD,
tablewa, tablew, readTab, readTable, readTable3, readTablei,
tableikt, tablekt, tablexkt,
cuserrnd, duserrnd
) where
import Control.Arrow(second)
import Control.Monad.Trans.Class
import Control.Monad.Trans.Reader
import Csound.Dynamic hiding (int, when1, whens, genId, pn)
import Data.Default
import Csound.Typed
import Data.Maybe
import Data.Boolean
import Data.Text (Text)
noTab :: Tab
noTab :: Tab
noTab = E -> Tab
forall a. Val a => E -> a
fromE (-E
1)
isNoTab :: Tab -> BoolD
isNoTab :: Tab -> BoolD
isNoTab = GE E -> BoolD
forall a. Val a => GE E -> a
fromGE (GE E -> BoolD) -> (Tab -> GE E) -> Tab -> BoolD
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (E -> E) -> GE E -> GE E
forall a b. (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (E -> E -> E
forall bool. (bool ~ BooleanOf E) => E -> E -> bool
forall a bool. (EqB a, bool ~ BooleanOf a) => a -> a -> bool
==* (-E
1)) (GE E -> GE E) -> (Tab -> GE E) -> Tab -> GE E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tab -> GE E
forall a. Val a => a -> GE E
toGE
tabSizeSeconds :: D -> D
tabSizeSeconds :: D -> D
tabSizeSeconds D
x = D
x D -> D -> D
forall a. Num a => a -> a -> a
* D
getSampleRate
tabSizePower2 :: D -> D
tabSizePower2 :: D -> D
tabSizePower2 D
x = D
2 D -> D -> D
forall a. Floating a => a -> a -> a
** (D -> D
forall a. SigOrD a => a -> a
ceil' (D -> D) -> D -> D
forall a b. (a -> b) -> a -> b
$ D -> D -> D
forall a. Floating a => a -> a -> a
logBase D
2 D
x)
tabSizeSecondsPower2 :: D -> D
tabSizeSecondsPower2 :: D -> D
tabSizeSecondsPower2 = D -> D
tabSizePower2 (D -> D) -> (D -> D) -> D -> D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. D -> D
tabSizeSeconds
data WavChn = WavLeft | WavRight | WavAll
deriving (Int -> WavChn -> ShowS
[WavChn] -> ShowS
WavChn -> String
(Int -> WavChn -> ShowS)
-> (WavChn -> String) -> ([WavChn] -> ShowS) -> Show WavChn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WavChn -> ShowS
showsPrec :: Int -> WavChn -> ShowS
$cshow :: WavChn -> String
show :: WavChn -> String
$cshowList :: [WavChn] -> ShowS
showList :: [WavChn] -> ShowS
Show, WavChn -> WavChn -> Bool
(WavChn -> WavChn -> Bool)
-> (WavChn -> WavChn -> Bool) -> Eq WavChn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WavChn -> WavChn -> Bool
== :: WavChn -> WavChn -> Bool
$c/= :: WavChn -> WavChn -> Bool
/= :: WavChn -> WavChn -> Bool
Eq)
instance Default WavChn where
def :: WavChn
def = WavChn
WavAll
fromWavChn :: WavChn -> Int
fromWavChn :: WavChn -> Int
fromWavChn WavChn
x = case WavChn
x of
WavChn
WavAll -> Int
0
WavChn
WavLeft -> Int
1
WavChn
WavRight -> Int
2
wavs :: String -> Double -> WavChn -> Tab
wavs :: String -> Double -> WavChn -> Tab
wavs String
filename Double
skiptime WavChn
channel = TabSize -> Int -> TabArgs -> Tab
preTab (Int -> TabSize
SizePlain Int
0) Int
idWavs
(String -> [Double] -> TabArgs
FileAccess String
filename [Double
skiptime, Double
format, Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> Int -> Double
forall a b. (a -> b) -> a -> b
$ WavChn -> Int
fromWavChn WavChn
channel])
where format :: Double
format = Double
0
data Mp3Chn = Mp3Mono | Mp3Stereo | Mp3Left | Mp3Right | Mp3All
deriving (Int -> Mp3Chn -> ShowS
[Mp3Chn] -> ShowS
Mp3Chn -> String
(Int -> Mp3Chn -> ShowS)
-> (Mp3Chn -> String) -> ([Mp3Chn] -> ShowS) -> Show Mp3Chn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Mp3Chn -> ShowS
showsPrec :: Int -> Mp3Chn -> ShowS
$cshow :: Mp3Chn -> String
show :: Mp3Chn -> String
$cshowList :: [Mp3Chn] -> ShowS
showList :: [Mp3Chn] -> ShowS
Show, Mp3Chn -> Mp3Chn -> Bool
(Mp3Chn -> Mp3Chn -> Bool)
-> (Mp3Chn -> Mp3Chn -> Bool) -> Eq Mp3Chn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Mp3Chn -> Mp3Chn -> Bool
== :: Mp3Chn -> Mp3Chn -> Bool
$c/= :: Mp3Chn -> Mp3Chn -> Bool
/= :: Mp3Chn -> Mp3Chn -> Bool
Eq)
fromMp3Chn :: Mp3Chn -> Int
fromMp3Chn :: Mp3Chn -> Int
fromMp3Chn Mp3Chn
x = case Mp3Chn
x of
Mp3Chn
Mp3Mono -> Int
1
Mp3Chn
Mp3Stereo -> Int
2
Mp3Chn
Mp3Left -> Int
3
Mp3Chn
Mp3Right -> Int
4
Mp3Chn
Mp3All -> Int
0
instance Default Mp3Chn where
def :: Mp3Chn
def = Mp3Chn
Mp3All
wavAll :: String -> Tab
wavAll :: String -> Tab
wavAll String
name = String -> Double -> WavChn -> Tab
wavs String
name Double
0 WavChn
WavAll
wavLeft :: String -> Tab
wavLeft :: String -> Tab
wavLeft String
file = String -> Double -> WavChn -> Tab
wavs String
file Double
0 WavChn
WavLeft
wavRight :: String -> Tab
wavRight :: String -> Tab
wavRight String
file = String -> Double -> WavChn -> Tab
wavs String
file Double
0 WavChn
WavRight
mp3s :: String -> Double -> Mp3Chn -> Tab
mp3s :: String -> Double -> Mp3Chn -> Tab
mp3s String
filename Double
skiptime Mp3Chn
channel = TabSize -> Int -> TabArgs -> Tab
preTab (Int -> TabSize
SizePlain Int
0) Int
idMp3s
(String -> [Double] -> TabArgs
FileAccess String
filename [Double
skiptime, Double
format])
where format :: Double
format = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> Int -> Double
forall a b. (a -> b) -> a -> b
$ Mp3Chn -> Int
fromMp3Chn Mp3Chn
channel
mp3Left :: String -> Tab
mp3Left :: String -> Tab
mp3Left String
file = String -> Double -> Mp3Chn -> Tab
mp3s String
file Double
0 Mp3Chn
Mp3Left
mp3Right :: String -> Tab
mp3Right :: String -> Tab
mp3Right String
file = String -> Double -> Mp3Chn -> Tab
mp3s String
file Double
0 Mp3Chn
Mp3Right
mp3m :: String -> Tab
mp3m :: String -> Tab
mp3m String
file = String -> Double -> Mp3Chn -> Tab
mp3s String
file Double
0 Mp3Chn
Mp3Mono
interp :: Int -> [Double] -> Tab
interp :: Int -> [Double] -> Tab
interp Int
genId [Double]
as = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
genId ([Double] -> TabArgs
relativeArgs [Double]
as)
plains :: Int -> [Double] -> Tab
plains :: Int -> [Double] -> Tab
plains Int
genId [Double]
as = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
genId (Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ [Double] -> Reader Int [Double]
forall a. a -> ReaderT Int Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [Double]
as)
insertOnes :: [Double] -> [Double]
insertOnes :: [Double] -> [Double]
insertOnes [Double]
xs = case [Double]
xs of
[] -> []
Double
a:[] -> [Double
a]
Double
a:[Double]
as -> Double
a Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: Double
1 Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: [Double] -> [Double]
insertOnes [Double]
as
findTableSize :: Int -> Int
findTableSize :: Int -> Int
findTableSize Int
n
| Int -> Bool
isPowerOfTwo Int
n = Int
n
| Int -> Bool
isPowerOfTwo (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) = Int
n
| Bool
otherwise = -Int
n
isPowerOfTwo :: Int -> Bool
isPowerOfTwo :: Int -> Bool
isPowerOfTwo Int
a
| [Int] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
zeroes = Bool
False
| Bool
otherwise = (Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ( Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0) [Int]
zeroes
where zeroes :: [Int]
zeroes = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Int -> Int -> Int) -> Int -> Int -> Int
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
2) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Int -> Int) -> Int -> [Int]
forall a. (a -> a) -> a -> [a]
iterate (\Int
x -> Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
x Int
2) Int
a
doubles :: [Double] -> Tab
doubles :: [Double] -> Tab
doubles [Double]
as = Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> Tab -> Tab
setSize (Int -> Int
findTableSize Int
n) (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
plains Int
idDoubles [Double]
as
where n :: Int
n = [Double] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Double]
as
exps :: [Double] -> Tab
exps :: [Double] -> Tab
exps = Int -> [Double] -> Tab
interp Int
idExps
eexps :: [Double] -> Tab
eexps :: [Double] -> Tab
eexps = [Double] -> Tab
exps ([Double] -> Tab) -> ([Double] -> [Double]) -> [Double] -> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> [Double]
insertOnes
cubes :: [Double] -> Tab
cubes :: [Double] -> Tab
cubes = Int -> [Double] -> Tab
interp Int
idCubes
ecubes :: [Double] -> Tab
ecubes :: [Double] -> Tab
ecubes = [Double] -> Tab
cubes ([Double] -> Tab) -> ([Double] -> [Double]) -> [Double] -> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> [Double]
insertOnes
lins :: [Double] -> Tab
lins :: [Double] -> Tab
lins = Int -> [Double] -> Tab
interp Int
idLins
elins :: [Double] -> Tab
elins :: [Double] -> Tab
elins = [Double] -> Tab
lins ([Double] -> Tab) -> ([Double] -> [Double]) -> [Double] -> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> [Double]
insertOnes
splines :: [Double] -> Tab
splines :: [Double] -> Tab
splines = Int -> [Double] -> Tab
interp Int
idSplines
esplines :: [Double] -> Tab
esplines :: [Double] -> Tab
esplines = [Double] -> Tab
splines ([Double] -> Tab) -> ([Double] -> [Double]) -> [Double] -> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> [Double]
insertOnes
consts :: [Double] -> Tab
consts :: [Double] -> Tab
consts = Int -> [Double] -> Tab
interp Int
idConsts
econsts :: [Double] -> Tab
econsts :: [Double] -> Tab
econsts = [Double] -> Tab
consts ([Double] -> Tab) -> ([Double] -> [Double]) -> [Double] -> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> [Double]
insertOnes
startEnds :: [Double] -> Tab
startEnds :: [Double] -> Tab
startEnds [Double]
as = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idStartEnds ([Double] -> TabArgs
relativeArgsGen16 [Double]
as)
estartEnds :: [Double] -> Tab
estartEnds :: [Double] -> Tab
estartEnds = [Double] -> Tab
startEnds ([Double] -> Tab) -> ([Double] -> [Double]) -> [Double] -> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> [Double]
forall {a}. Num a => [a] -> [a]
insertOnes16
where
insertOnes16 :: [a] -> [a]
insertOnes16 [a]
xs = case [a]
xs of
a
a:a
b:[a]
as -> a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
1 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
insertOnes16 [a]
as
[a]
_ -> [a]
xs
bpLins :: [Double] -> Tab
bpLins :: [Double] -> Tab
bpLins [Double]
xs = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idLinsBreakPoints (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ [Double] -> TabArgs
bpRelativeArgs [Double]
xs
bpExps :: [Double] -> Tab
bpExps :: [Double] -> Tab
bpExps [Double]
xs = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idExpsBreakPoints (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ [Double] -> TabArgs
bpRelativeArgs [Double]
xs
type PartialNumber = Double
type PartialStrength = Double
type PartialPhase = Double
type PartialDC = Double
sines :: [PartialStrength] -> Tab
sines :: [Double] -> Tab
sines = Int -> [Double] -> Tab
plains Int
idSines
sines1 :: [PartialNumber] -> Tab
sines1 :: [Double] -> Tab
sines1 [Double]
xs = [(Double, Double)] -> Tab
sines2 ([(Double, Double)] -> Tab) -> [(Double, Double)] -> Tab
forall a b. (a -> b) -> a -> b
$ [Double] -> [Double] -> [(Double, Double)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Double]
xs (Double -> [Double]
forall a. a -> [a]
repeat Double
1)
sines2 :: [(PartialNumber, PartialStrength)] -> Tab
sines2 :: [(Double, Double)] -> Tab
sines2 [(Double, Double)]
xs = [(Double, Double, Double)] -> Tab
sines3 [(Double
num, Double
strength, Double
0) | (Double
num, Double
strength) <- [(Double, Double)]
xs]
sines3 :: [(PartialNumber, PartialStrength, PartialPhase)] -> Tab
sines3 :: [(Double, Double, Double)] -> Tab
sines3 [(Double, Double, Double)]
xs = Int -> [Double] -> Tab
plains Int
idSines3 [Double
a | (Double
pn, Double
strength, Double
phs) <- [(Double, Double, Double)]
xs, Double
a <- [Double
pn, Double
strength, Double
phs]]
sines4 :: [(PartialNumber, PartialStrength, PartialPhase, PartialDC)] -> Tab
sines4 :: [(Double, Double, Double, Double)] -> Tab
sines4 [(Double, Double, Double, Double)]
xs = Int -> [Double] -> Tab
plains Int
idSines4 [Double
a | (Double
pn, Double
strength, Double
phs, Double
dc) <- [(Double, Double, Double, Double)]
xs, Double
a <- [Double
pn, Double
strength, Double
phs, Double
dc]]
bwSines :: [Double] -> Double -> Tab
bwSines :: [Double] -> Double -> Tab
bwSines [Double]
harmonics Double
bandwidth = PadsynthSpec -> Tab
padsynth (Double -> [Double] -> PadsynthSpec
defPadsynthSpec Double
bandwidth [Double]
harmonics)
bwOddSines :: [Double] -> Double -> Tab
bwOddSines :: [Double] -> Double -> Tab
bwOddSines [Double]
harmonics Double
bandwidth = PadsynthSpec -> Tab
padsynth ((Double -> [Double] -> PadsynthSpec
defPadsynthSpec Double
bandwidth [Double]
harmonics) { padsynthHarmonicStretch = 2 })
sine :: Tab
sine :: Tab
sine = [Double] -> Tab
sines [Double
1]
cosine :: Tab
cosine :: Tab
cosine = Double -> [Double] -> Tab
buzzes Double
1 []
sigmoid :: Tab
sigmoid :: Tab
sigmoid = [(Double, Double, Double, Double)] -> Tab
sines4 [(Double
0.5, Double
0.5, Double
270, Double
0.5)]
sigmoidRise :: Tab
sigmoidRise :: Tab
sigmoidRise = Tab -> Tab
guardPoint (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ [(Double, Double, Double, Double)] -> Tab
sines4 [(Double
0.5, Double
1, Double
270, Double
1)]
sigmoidFall :: Tab
sigmoidFall :: Tab
sigmoidFall = Tab -> Tab
guardPoint (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ [(Double, Double, Double, Double)] -> Tab
sines4 [(Double
0.5, Double
1, Double
90, Double
1)]
tanhSigmoid :: Double -> Tab
tanhSigmoid :: Double -> Tab
tanhSigmoid Double
x = [Double] -> Tab
esplines ((Double -> Double) -> [Double] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Double
forall a. Floating a => a -> a
tanh [-Double
x, (-Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
+Double
0.5) .. Double
x])
buzzes :: Double -> [Double] -> Tab
buzzes :: Double -> [Double] -> Tab
buzzes Double
nh [Double]
opts = Int -> [Double] -> Tab
plains Int
idBuzzes (Double
nh Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: Int -> [Double] -> [Double]
forall a. Int -> [a] -> [a]
take Int
2 [Double]
opts)
bessels :: Double -> Tab
bessels :: Double -> Tab
bessels Double
xint = Int -> [Double] -> Tab
plains Int
idBessels [Double
xint]
polys :: Double -> Double -> [Double] -> Tab
polys :: Double -> Double -> [Double] -> Tab
polys Double
x0 Double
x1 [Double]
cs = Int -> [Double] -> Tab
plains Int
idPolys (Double
x0Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
:Double
x1Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
:[Double]
cs)
chebs1 :: Double -> Double -> [Double] -> Tab
chebs1 :: Double -> Double -> [Double] -> Tab
chebs1 Double
xint Double
xamp [Double]
hs = Int -> [Double] -> Tab
plains Int
idChebs1 (Double
xint Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: Double
xamp Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: [Double]
hs)
chebs2 :: Double -> Double -> [Double] -> Tab
chebs2 :: Double -> Double -> [Double] -> Tab
chebs2 Double
xint Double
xamp [Double]
hs = Int -> [Double] -> Tab
plains Int
idChebs2 (Double
xint Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: Double
xamp Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: [Double]
hs)
winHamming :: Tab
winHamming :: Tab
winHamming = WinType -> [Double] -> Tab
wins WinType
Hamming [Double
1]
winHanning :: Tab
winHanning :: Tab
winHanning = WinType -> [Double] -> Tab
wins WinType
Hanning [Double
1]
winBartlett :: Tab
winBartlett :: Tab
winBartlett = WinType -> [Double] -> Tab
wins WinType
Bartlett [Double
1]
winBlackman :: Tab
winBlackman :: Tab
winBlackman = WinType -> [Double] -> Tab
wins WinType
Blackman [Double
1]
winHarris :: Tab
winHarris :: Tab
winHarris = WinType -> [Double] -> Tab
wins WinType
Harris [Double
1]
winRectangle :: Tab
winRectangle :: Tab
winRectangle = WinType -> [Double] -> Tab
wins WinType
Rectangle [Double
1]
winSync :: Tab
winSync :: Tab
winSync = WinType -> [Double] -> Tab
wins WinType
Sync [Double
1]
winGauss :: Double -> Tab
winGauss :: Double -> Tab
winGauss Double
a = WinType -> [Double] -> Tab
wins WinType
Gaussian [Double
1, Double
a]
winKaiser :: Double -> Tab
winKaiser :: Double -> Tab
winKaiser Double
openness = WinType -> [Double] -> Tab
wins WinType
Kaiser [Double
1, Double
openness]
data WinType
= Hamming | Hanning | Bartlett | Blackman
| Harris | Gaussian | Kaiser | Rectangle | Sync
winTypeId :: WinType -> Double
winTypeId :: WinType -> Double
winTypeId WinType
x = case WinType
x of
WinType
Hamming -> Double
1
WinType
Hanning -> Double
2
WinType
Bartlett -> Double
3
WinType
Blackman -> Double
4
WinType
Harris -> Double
5
WinType
Gaussian -> Double
6
WinType
Kaiser -> Double
7
WinType
Rectangle -> Double
8
WinType
Sync -> Double
9
wins :: WinType -> [Double] -> Tab
wins :: WinType -> [Double] -> Tab
wins WinType
ty [Double]
params = Int -> [Double] -> Tab
gen Int
idWins (WinType -> Double
winTypeId WinType
ty Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: [Double]
params)
data PadsynthSpec = PadsynthSpec
{ PadsynthSpec -> Double
padsynthFundamental :: Double
, PadsynthSpec -> Double
padsynthBandwidth :: Double
, PadsynthSpec -> Double
padsynthPartialScale :: Double
, PadsynthSpec -> Double
padsynthHarmonicStretch :: Double
, PadsynthSpec -> PadsynthShape
padsynthShape :: PadsynthShape
, PadsynthSpec -> Double
padsynthShapeParameter :: Double
, PadsynthSpec -> [Double]
padsynthHarmonics :: [Double]
} deriving (Int -> PadsynthSpec -> ShowS
[PadsynthSpec] -> ShowS
PadsynthSpec -> String
(Int -> PadsynthSpec -> ShowS)
-> (PadsynthSpec -> String)
-> ([PadsynthSpec] -> ShowS)
-> Show PadsynthSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PadsynthSpec -> ShowS
showsPrec :: Int -> PadsynthSpec -> ShowS
$cshow :: PadsynthSpec -> String
show :: PadsynthSpec -> String
$cshowList :: [PadsynthSpec] -> ShowS
showList :: [PadsynthSpec] -> ShowS
Show, PadsynthSpec -> PadsynthSpec -> Bool
(PadsynthSpec -> PadsynthSpec -> Bool)
-> (PadsynthSpec -> PadsynthSpec -> Bool) -> Eq PadsynthSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PadsynthSpec -> PadsynthSpec -> Bool
== :: PadsynthSpec -> PadsynthSpec -> Bool
$c/= :: PadsynthSpec -> PadsynthSpec -> Bool
/= :: PadsynthSpec -> PadsynthSpec -> Bool
Eq)
data PadsynthShape = GaussShape | SquareShape | ExpShape
deriving (Int -> PadsynthShape -> ShowS
[PadsynthShape] -> ShowS
PadsynthShape -> String
(Int -> PadsynthShape -> ShowS)
-> (PadsynthShape -> String)
-> ([PadsynthShape] -> ShowS)
-> Show PadsynthShape
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PadsynthShape -> ShowS
showsPrec :: Int -> PadsynthShape -> ShowS
$cshow :: PadsynthShape -> String
show :: PadsynthShape -> String
$cshowList :: [PadsynthShape] -> ShowS
showList :: [PadsynthShape] -> ShowS
Show, PadsynthShape -> PadsynthShape -> Bool
(PadsynthShape -> PadsynthShape -> Bool)
-> (PadsynthShape -> PadsynthShape -> Bool) -> Eq PadsynthShape
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PadsynthShape -> PadsynthShape -> Bool
== :: PadsynthShape -> PadsynthShape -> Bool
$c/= :: PadsynthShape -> PadsynthShape -> Bool
/= :: PadsynthShape -> PadsynthShape -> Bool
Eq, Eq PadsynthShape
Eq PadsynthShape =>
(PadsynthShape -> PadsynthShape -> Ordering)
-> (PadsynthShape -> PadsynthShape -> Bool)
-> (PadsynthShape -> PadsynthShape -> Bool)
-> (PadsynthShape -> PadsynthShape -> Bool)
-> (PadsynthShape -> PadsynthShape -> Bool)
-> (PadsynthShape -> PadsynthShape -> PadsynthShape)
-> (PadsynthShape -> PadsynthShape -> PadsynthShape)
-> Ord PadsynthShape
PadsynthShape -> PadsynthShape -> Bool
PadsynthShape -> PadsynthShape -> Ordering
PadsynthShape -> PadsynthShape -> PadsynthShape
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PadsynthShape -> PadsynthShape -> Ordering
compare :: PadsynthShape -> PadsynthShape -> Ordering
$c< :: PadsynthShape -> PadsynthShape -> Bool
< :: PadsynthShape -> PadsynthShape -> Bool
$c<= :: PadsynthShape -> PadsynthShape -> Bool
<= :: PadsynthShape -> PadsynthShape -> Bool
$c> :: PadsynthShape -> PadsynthShape -> Bool
> :: PadsynthShape -> PadsynthShape -> Bool
$c>= :: PadsynthShape -> PadsynthShape -> Bool
>= :: PadsynthShape -> PadsynthShape -> Bool
$cmax :: PadsynthShape -> PadsynthShape -> PadsynthShape
max :: PadsynthShape -> PadsynthShape -> PadsynthShape
$cmin :: PadsynthShape -> PadsynthShape -> PadsynthShape
min :: PadsynthShape -> PadsynthShape -> PadsynthShape
Ord, Int -> PadsynthShape
PadsynthShape -> Int
PadsynthShape -> [PadsynthShape]
PadsynthShape -> PadsynthShape
PadsynthShape -> PadsynthShape -> [PadsynthShape]
PadsynthShape -> PadsynthShape -> PadsynthShape -> [PadsynthShape]
(PadsynthShape -> PadsynthShape)
-> (PadsynthShape -> PadsynthShape)
-> (Int -> PadsynthShape)
-> (PadsynthShape -> Int)
-> (PadsynthShape -> [PadsynthShape])
-> (PadsynthShape -> PadsynthShape -> [PadsynthShape])
-> (PadsynthShape -> PadsynthShape -> [PadsynthShape])
-> (PadsynthShape
-> PadsynthShape -> PadsynthShape -> [PadsynthShape])
-> Enum PadsynthShape
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: PadsynthShape -> PadsynthShape
succ :: PadsynthShape -> PadsynthShape
$cpred :: PadsynthShape -> PadsynthShape
pred :: PadsynthShape -> PadsynthShape
$ctoEnum :: Int -> PadsynthShape
toEnum :: Int -> PadsynthShape
$cfromEnum :: PadsynthShape -> Int
fromEnum :: PadsynthShape -> Int
$cenumFrom :: PadsynthShape -> [PadsynthShape]
enumFrom :: PadsynthShape -> [PadsynthShape]
$cenumFromThen :: PadsynthShape -> PadsynthShape -> [PadsynthShape]
enumFromThen :: PadsynthShape -> PadsynthShape -> [PadsynthShape]
$cenumFromTo :: PadsynthShape -> PadsynthShape -> [PadsynthShape]
enumFromTo :: PadsynthShape -> PadsynthShape -> [PadsynthShape]
$cenumFromThenTo :: PadsynthShape -> PadsynthShape -> PadsynthShape -> [PadsynthShape]
enumFromThenTo :: PadsynthShape -> PadsynthShape -> PadsynthShape -> [PadsynthShape]
Enum)
padsynthShapeId :: PadsynthShape -> Double
padsynthShapeId :: PadsynthShape -> Double
padsynthShapeId PadsynthShape
shape = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> Int -> Double
forall a b. (a -> b) -> a -> b
$ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (PadsynthShape -> Int
forall a. Enum a => a -> Int
fromEnum PadsynthShape
shape)
defPadsynthSpec :: Double -> [Double] -> PadsynthSpec
defPadsynthSpec :: Double -> [Double] -> PadsynthSpec
defPadsynthSpec Double
partialBW [Double]
harmonics = Double
-> Double
-> Double
-> Double
-> PadsynthShape
-> Double
-> [Double]
-> PadsynthSpec
PadsynthSpec Double
261.625565 Double
partialBW Double
1 Double
1 PadsynthShape
GaussShape Double
1 [Double]
harmonics
padsynth :: PadsynthSpec -> Tab
padsynth :: PadsynthSpec -> Tab
padsynth (PadsynthSpec Double
fundamentalFreq Double
partialBW Double
partialScale Double
harmonicStretch PadsynthShape
shape Double
shapeParameter [Double]
harmonics) =
Text -> [Double] -> Tab
plainStringTab Text
idPadsynth ([Double
fundamentalFreq, Double
partialBW, Double
partialScale, Double
harmonicStretch, PadsynthShape -> Double
padsynthShapeId PadsynthShape
shape, Double
shapeParameter] [Double] -> [Double] -> [Double]
forall a. [a] -> [a] -> [a]
++ [Double]
harmonics)
plainStringTab :: Text -> [Double] -> Tab
plainStringTab :: Text -> [Double] -> Tab
plainStringTab Text
genId [Double]
as = TabSize -> Text -> TabArgs -> Tab
preStringTab TabSize
forall a. Default a => a
def Text
genId (Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ [Double] -> Reader Int [Double]
forall a. a -> ReaderT Int Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [Double]
as)
gen :: Int -> [Double] -> Tab
gen :: Int -> [Double] -> Tab
gen Int
genId [Double]
args = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
genId (Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ [Double] -> Reader Int [Double]
forall a. a -> ReaderT Int Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return [Double]
args)
guardPoint :: Tab -> Tab
guardPoint :: Tab -> Tab
guardPoint = (TabSize -> TabSize) -> Tab -> Tab
updateTabSize ((TabSize -> TabSize) -> Tab -> Tab)
-> (TabSize -> TabSize) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ \TabSize
x -> case TabSize
x of
SizePlain Int
n -> Int -> TabSize
SizePlain (Int -> TabSize) -> Int -> TabSize
forall a b. (a -> b) -> a -> b
$ Int -> Int
forall {a}. Integral a => a -> a
plainGuardPoint Int
n
TabSize
a -> TabSize
a{ hasGuardPoint = True }
where plainGuardPoint :: a -> a
plainGuardPoint a
n
| a -> Bool
forall a. Integral a => a -> Bool
even a
n = a
n a -> a -> a
forall a. Num a => a -> a -> a
+ a
1
| Bool
otherwise = a
n
gp :: Tab -> Tab
gp :: Tab -> Tab
gp = Tab -> Tab
guardPoint
setSize :: Int -> Tab -> Tab
setSize :: Int -> Tab -> Tab
setSize Int
n = (TabSize -> TabSize) -> Tab -> Tab
updateTabSize ((TabSize -> TabSize) -> Tab -> Tab)
-> (TabSize -> TabSize) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ TabSize -> TabSize -> TabSize
forall a b. a -> b -> a
const (Int -> TabSize
SizePlain Int
n)
setDegree :: Int -> Tab -> Tab
setDegree :: Int -> Tab -> Tab
setDegree Int
degree = (TabSize -> TabSize) -> Tab -> Tab
updateTabSize ((TabSize -> TabSize) -> Tab -> Tab)
-> (TabSize -> TabSize) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ \TabSize
x -> case TabSize
x of
SizePlain Int
n -> Int -> TabSize
SizePlain Int
n
TabSize
a -> TabSize
a{ sizeDegree = degree }
lllofi, llofi, lofi, midfi, hifi, hhifi, hhhifi :: Tab -> Tab
lllofi :: Tab -> Tab
lllofi = Int -> Tab -> Tab
setDegree (-Int
3)
llofi :: Tab -> Tab
llofi = Int -> Tab -> Tab
setDegree (-Int
2)
lofi :: Tab -> Tab
lofi = Int -> Tab -> Tab
setDegree (-Int
1)
midfi :: Tab -> Tab
midfi = Int -> Tab -> Tab
setDegree Int
0
hifi :: Tab -> Tab
hifi = Int -> Tab -> Tab
setDegree Int
1
hhifi :: Tab -> Tab
hhifi = Int -> Tab -> Tab
setDegree Int
2
hhhifi :: Tab -> Tab
hhhifi = Int -> Tab -> Tab
setDegree Int
3
tablewa :: Tab -> Sig -> Sig -> SE Sig
tablewa :: Tab -> Sig -> Sig -> SE Sig
tablewa Tab
b1 Sig
b2 Sig
b3 = (E -> Sig) -> SE E -> SE Sig
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> Sig
Sig (GE E -> Sig) -> (E -> GE E) -> E -> Sig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE Sig) -> SE E -> SE Sig
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E -> E
f (E -> E -> E -> E) -> GE E -> GE (E -> E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tab -> GE E
unTab Tab
b1 GE (E -> E -> E) -> GE E -> GE (E -> E)
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sig -> GE E
unSig Sig
b2 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sig -> GE E
unSig Sig
b3
where f :: E -> E -> E -> E
f E
a1 E
a2 E
a3 = Text -> Spec1 -> [E] -> E
opcs Text
"tablewa" [(Rate
Kr,[Rate
Kr,Rate
Ar,Rate
Kr])] [E
a1,E
a2,E
a3]
sec2rel :: Tab -> Sig -> Sig
sec2rel :: Tab -> Sig -> Sig
sec2rel Tab
tab Sig
x = Sig
x Sig -> Sig -> Sig
forall a. Fractional a => a -> a -> a
/ (D -> Sig
sig (D -> Sig) -> D -> Sig
forall a b. (a -> b) -> a -> b
$ Tab -> D
ftlen Tab
tab D -> D -> D
forall a. Fractional a => a -> a -> a
/ D
getSampleRate)
tabDur :: Tab -> D
tabDur :: Tab -> D
tabDur Tab
t = Tab -> D
ftlen Tab
t D -> D -> D
forall a. Fractional a => a -> a -> a
/ (Tab -> D
ftsr Tab
t D -> D -> D
forall a. Num a => a -> a -> a
* Tab -> D
ftchnls Tab
t)
tabHarmonics :: Tab -> Double -> Double -> Maybe Double -> Maybe Double -> Tab
tabHarmonics :: Tab -> Double -> Double -> Maybe Double -> Maybe Double -> Tab
tabHarmonics Tab
tab Double
minh Double
maxh Maybe Double
mrefSr Maybe Double
mInterp = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
idx <- Tab -> GE Int
renderTab Tab
tab
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idTabHarmonics (Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ [Double] -> Reader Int [Double]
forall a. a -> ReaderT Int Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Maybe Double] -> [Double]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Double] -> [Double]) -> [Maybe Double] -> [Double]
forall a b. (a -> b) -> a -> b
$ (Double -> Maybe Double) -> [Double] -> [Maybe Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Maybe Double
forall a. a -> Maybe a
Just [Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
idx, Double
minh, Double
maxh] [Maybe Double] -> [Maybe Double] -> [Maybe Double]
forall a. [a] -> [a] -> [a]
++ [Maybe Double
mrefSr, Maybe Double
mInterp]))
mixOnTab :: Tab -> [(PartialNumber, PartialStrength, PartialPhase)] -> Tab
mixOnTab :: Tab -> [(Double, Double, Double)] -> Tab
mixOnTab Tab
tab [(Double, Double, Double)]
xs = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
idx <- Tab -> GE Int
renderTab Tab
tab
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
plains Int
idMixOnTab ([Double] -> Tab) -> [Double] -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
idx Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: [Double
a | (Double
pn, Double
strength, Double
phs) <- [(Double, Double, Double)]
xs, Double
a <- [Double
pn, Double
strength, Double
phs]]
mixTabs :: [(Tab, PartialNumber, PartialStrength, PartialPhase)] -> Tab
mixTabs :: [(Tab, Double, Double, Double)] -> Tab
mixTabs [(Tab, Double, Double, Double)]
xs = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
[Double]
args <- [GE Double] -> GE [Double]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [GE Double
a | (Tab
tab, Double
pn, Double
strength, Double
phs) <- [(Tab, Double, Double, Double)]
xs, GE Double
a <- ((Int -> Double) -> GE Int -> GE Double
forall a b. (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (GE Int -> GE Double) -> GE Int -> GE Double
forall a b. (a -> b) -> a -> b
$ Tab -> GE Int
renderTab Tab
tab) GE Double -> [GE Double] -> [GE Double]
forall a. a -> [a] -> [a]
: (Double -> GE Double) -> [Double] -> [GE Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> GE Double
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return [Double
pn, Double
strength, Double
phs]]
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
plains Int
idMixTabs [Double]
args
normTab :: NormTabSpec -> Tab -> Tab
normTab :: NormTabSpec -> Tab -> Tab
normTab NormTabSpec
spec Tab
tab = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
idx <- Tab -> GE Int
renderTab Tab
tab
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
plains Int
idNormTab ([Double] -> Tab) -> [Double] -> Tab
forall a b. (a -> b) -> a -> b
$ (Int -> Double) -> [Int] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral [Int
idx, NormTabSpec -> Int
forall {a}. Num a => NormTabSpec -> a
fromNormTabSpec NormTabSpec
spec]
where
fromNormTabSpec :: NormTabSpec -> a
fromNormTabSpec NormTabSpec
x = case NormTabSpec
x of
NormTabSpec
ScanLeftToRight -> a
0
NormTabSpec
ScanFromMiddle -> a
1
data NormTabSpec = ScanLeftToRight | ScanFromMiddle
scaleTab :: (Double, Double) -> Tab -> Tab
scaleTab :: (Double, Double) -> Tab -> Tab
scaleTab (Double
minVal, Double
maxVal) Tab
tab = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
tabId <- Tab -> GE Int
renderTab Tab
tab
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
gen Int
idReadNumTab [Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
tabId, Double
minVal, Double
maxVal]
tabseg :: [(Tab, PartialStrength, Double)] -> Tab
tabseg :: [(Tab, Double, Double)] -> Tab
tabseg [(Tab, Double, Double)]
xs = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
[Int]
tabIds <- (Tab -> GE Int) -> [Tab] -> GE [Int]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Tab -> GE Int
renderTab [Tab]
tabs
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idLinTab (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ [Int] -> TabArgs
forall {a}. Integral a => [a] -> TabArgs
mkArgs [Int]
tabIds
where
([Tab]
tabs, [Double]
amps, [Double]
durs) = [(Tab, Double, Double)] -> ([Tab], [Double], [Double])
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 [(Tab, Double, Double)]
xs
segments :: a -> [(Double, Double)]
segments a
n = ((Double, Double) -> (Double, Double))
-> [(Double, Double)] -> [(Double, Double)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Double -> Double) -> (Double, Double) -> (Double, Double)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Double -> Double) -> (Double, Double) -> (Double, Double))
-> (Double -> Double) -> (Double, Double) -> (Double, Double)
forall a b. (a -> b) -> a -> b
$ \Double
x -> Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
1) ([(Double, Double)] -> [(Double, Double)])
-> [(Double, Double)] -> [(Double, Double)]
forall a b. (a -> b) -> a -> b
$ [(Double, Double)] -> [(Double, Double)]
forall a. HasCallStack => [a] -> [a]
tail ([(Double, Double)] -> [(Double, Double)])
-> [(Double, Double)] -> [(Double, Double)]
forall a b. (a -> b) -> a -> b
$ ((Double, Double) -> Double -> (Double, Double))
-> (Double, Double) -> [Double] -> [(Double, Double)]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl (\(Double
_, Double
b) Double
x -> (Double
b, Double
b Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x)) (Double
0, Double
0) ([Double] -> [(Double, Double)]) -> [Double] -> [(Double, Double)]
forall a b. (a -> b) -> a -> b
$ a -> [Double] -> [Double]
forall (t :: * -> *) b a.
(Functor t, Foldable t, RealFrac b, Integral a) =>
a -> t b -> t Double
mkRelative a
n [Double]
durs
mkArgs :: [a] -> TabArgs
mkArgs [a]
ids = Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ (Int -> [Double]) -> Reader Int [Double]
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
reader ((Int -> [Double]) -> Reader Int [Double])
-> (Int -> [Double]) -> Reader Int [Double]
forall a b. (a -> b) -> a -> b
$ \Int
size -> [[Double]] -> [Double]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Double]] -> [Double]) -> [[Double]] -> [Double]
forall a b. (a -> b) -> a -> b
$ (a -> Double -> (Double, Double) -> [Double])
-> [a] -> [Double] -> [(Double, Double)] -> [[Double]]
forall a b c d. (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 (\a
tabId Double
amp (Double
start, Double
finish) -> [a -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
tabId, Double
amp, Double
start, Double
finish]) [a]
ids [Double]
amps (Int -> [(Double, Double)]
forall {a}. Integral a => a -> [(Double, Double)]
segments Int
size)
etabseg :: [(Tab, PartialStrength)] -> Tab
etabseg :: [(Tab, Double)] -> Tab
etabseg = [(Tab, Double, Double)] -> Tab
tabseg ([(Tab, Double, Double)] -> Tab)
-> ([(Tab, Double)] -> [(Tab, Double, Double)])
-> [(Tab, Double)]
-> Tab
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Tab, Double) -> (Tab, Double, Double))
-> [(Tab, Double)] -> [(Tab, Double, Double)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Tab
tab, Double
amp) -> (Tab
tab, Double
amp, Double
1))
gen21 :: Int -> [Double] -> Tab
gen21 :: Int -> [Double] -> Tab
gen21 Int
typeId [Double]
aux = Int -> [Double] -> Tab
gen Int
idRandDists ([Double] -> Tab) -> [Double] -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
typeId Double -> [Double] -> [Double]
forall a. a -> [a] -> [a]
: [Double]
aux
dist :: Int -> Tab
dist :: Int -> Tab
dist Int
n = Int -> [Double] -> Tab
gen21 Int
n []
uniDist :: Tab
uniDist :: Tab
uniDist = Int -> Tab
dist Int
1
linDist :: Tab
linDist :: Tab
linDist = Int -> Tab
dist Int
2
triDist :: Tab
triDist :: Tab
triDist = Int -> Tab
dist Int
3
expDist :: Tab
expDist :: Tab
expDist = Int -> Tab
dist Int
4
biexpDist :: Tab
biexpDist :: Tab
biexpDist = Int -> Tab
dist Int
5
gaussDist :: Tab
gaussDist :: Tab
gaussDist = Int -> Tab
dist Int
6
cauchyDist :: Tab
cauchyDist :: Tab
cauchyDist = Int -> Tab
dist Int
7
pcauchyDist :: Tab
pcauchyDist :: Tab
pcauchyDist = Int -> Tab
dist Int
8
betaDist :: Double -> Double -> Tab
betaDist :: Double -> Double -> Tab
betaDist Double
arg1 Double
arg2 = Int -> [Double] -> Tab
gen21 Int
9 [Double
1, Double
arg1, Double
arg2]
weibullDist :: Double -> Tab
weibullDist :: Double -> Tab
weibullDist Double
arg1 = Int -> [Double] -> Tab
gen21 Int
10 [Double
1, Double
arg1]
poissonDist :: Tab
poissonDist :: Tab
poissonDist = Int -> Tab
dist Int
11
dist' :: Int -> Double -> Tab
dist' :: Int -> Double -> Tab
dist' Int
n Double
level = Int -> [Double] -> Tab
gen21 Int
n [Double
level]
uniDist' :: Double -> Tab
uniDist' :: Double -> Tab
uniDist' = Int -> Double -> Tab
dist' Int
1
linDist' :: Double -> Tab
linDist' :: Double -> Tab
linDist' = Int -> Double -> Tab
dist' Int
2
triDist' :: Double -> Tab
triDist' :: Double -> Tab
triDist' = Int -> Double -> Tab
dist' Int
3
expDist' :: Double -> Tab
expDist' :: Double -> Tab
expDist' = Int -> Double -> Tab
dist' Int
4
biexpDist' :: Double -> Tab
biexpDist' :: Double -> Tab
biexpDist' = Int -> Double -> Tab
dist' Int
5
gaussDist' :: Double -> Tab
gaussDist' :: Double -> Tab
gaussDist' = Int -> Double -> Tab
dist' Int
6
cauchyDist' :: Double -> Tab
cauchyDist' :: Double -> Tab
cauchyDist' = Int -> Double -> Tab
dist' Int
7
pcauchyDist' :: Double -> Tab
pcauchyDist' :: Double -> Tab
pcauchyDist' = Int -> Double -> Tab
dist' Int
8
betaDist' :: Double -> Double -> Double -> Tab
betaDist' :: Double -> Double -> Double -> Tab
betaDist' Double
level Double
arg1 Double
arg2 = Int -> [Double] -> Tab
gen21 Int
9 [Double
level, Double
arg1, Double
arg2]
weibullDist' :: Double -> Double -> Tab
weibullDist' :: Double -> Double -> Tab
weibullDist' Double
level Double
arg1 = Int -> [Double] -> Tab
gen21 Int
10 [Double
level, Double
arg1]
poissonDist' :: Double -> Tab
poissonDist' :: Double -> Tab
poissonDist' = Int -> Double -> Tab
dist' Int
11
tabDist :: Tab -> Tab
tabDist :: Tab -> Tab
tabDist Tab
src = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
tabId <- Tab -> GE Int
renderTab Tab
src
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
gen Int
idRandHist [Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
tabId]
randDist :: [Double] -> Tab
randDist :: [Double] -> Tab
randDist [Double]
xs = Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
gen Int
idRandPairs [Double]
xs
rangeDist :: [Double] -> Tab
rangeDist :: [Double] -> Tab
rangeDist [Double]
xs = Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
gen Int
idRandRanges [Double]
xs
readNumFile :: String -> Tab
readNumFile :: String -> Tab
readNumFile String
filename = Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idReadNumFile (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ String -> [Double] -> TabArgs
FileAccess String
filename []
readTrajectoryFile :: String -> Tab
readTrajectoryFile :: String -> Tab
readTrajectoryFile String
filename = Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idReadTrajectoryFile (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ String -> [Double] -> TabArgs
FileAccess String
filename []
readPvocex :: String -> Int -> Tab
readPvocex :: String -> Int -> Tab
readPvocex String
filename Int
channel = TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
idPvocex (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ String -> [Double] -> TabArgs
FileAccess String
filename [Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
channel]
readMultichannel :: Int -> [(Tab, Int, Int)] -> Tab
readMultichannel :: Int -> [(Tab, Int, Int)] -> Tab
readMultichannel Int
n [(Tab, Int, Int)]
args = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
[Int]
idSrcs <- (Tab -> GE Int) -> [Tab] -> GE [Int]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Tab -> GE Int
renderTab [Tab]
fsrcs
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Tab -> Tab
skipNorm (Tab -> Tab) -> Tab -> Tab
forall a b. (a -> b) -> a -> b
$ Int -> [Double] -> Tab
gen Int
idMultichannel ([Double] -> Tab) -> [Double] -> Tab
forall a b. (a -> b) -> a -> b
$ (Int -> Double) -> [Int] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Int] -> [Double]) -> [Int] -> [Double]
forall a b. (a -> b) -> a -> b
$ Int
n Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: ([[Int]] -> [Int]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Int]] -> [Int]) -> [[Int]] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int -> [Int]) -> [Int] -> [Int] -> [Int] -> [[Int]]
forall a b c d. (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 (\Int
a Int
b Int
c -> [Int
a, Int
b, Int
c]) [Int]
idSrcs [Int]
offsets [Int]
chnls)
where
([Tab]
fsrcs, [Int]
offsets, [Int]
chnls) = [(Tab, Int, Int)] -> ([Tab], [Int], [Int])
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 [(Tab, Int, Int)]
args
tabSines1 :: Tab -> Double -> Double -> Maybe Double -> Tab
tabSines1 :: Tab -> Double -> Double -> Maybe Double -> Tab
tabSines1 = Int -> Tab -> Double -> Double -> Maybe Double -> Tab
tabSinesBy Int
idMixSines2
tabSines2 :: Tab -> Double -> Double -> Maybe Double -> Tab
tabSines2 :: Tab -> Double -> Double -> Maybe Double -> Tab
tabSines2 = Int -> Tab -> Double -> Double -> Maybe Double -> Tab
tabSinesBy Int
idMixSines2
tabSinesBy :: Int -> Tab -> Double -> Double -> Maybe Double -> Tab
tabSinesBy :: Int -> Tab -> Double -> Double -> Maybe Double -> Tab
tabSinesBy Int
genId Tab
tab Double
nh Double
amp Maybe Double
fmode = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
tabId <- Tab -> GE Int
renderTab Tab
tab
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ TabSize -> Int -> TabArgs -> Tab
preTab TabSize
forall a. Default a => a
def Int
genId (TabArgs -> Tab) -> TabArgs -> Tab
forall a b. (a -> b) -> a -> b
$ Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ [Double] -> Reader Int [Double]
forall a. a -> ReaderT Int Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Double] -> Reader Int [Double])
-> [Double] -> Reader Int [Double]
forall a b. (a -> b) -> a -> b
$ [Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
tabId, Double
nh, Double
amp] [Double] -> [Double] -> [Double]
forall a. [a] -> [a] -> [a]
++ ([Double] -> (Double -> [Double]) -> Maybe Double -> [Double]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Double -> [Double]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Double
fmode)
waveletTab :: Tab -> Int -> Tab
waveletTab :: Tab -> Int -> Tab
waveletTab = Int -> Tab -> Int -> Tab
waveletTabBy Int
0
rescaleWaveletTab :: Tab -> Int -> Tab
rescaleWaveletTab :: Tab -> Int -> Tab
rescaleWaveletTab = Int -> Tab -> Int -> Tab
waveletTabBy Int
1
waveletTabBy :: Int -> Tab -> Int -> Tab
waveletTabBy :: Int -> Tab -> Int -> Tab
waveletTabBy Int
rescaleFlag Tab
srcTab Int
sq = GE Tab -> Tab
forall a. Val a => GE a -> a
hideGE (GE Tab -> Tab) -> GE Tab -> Tab
forall a b. (a -> b) -> a -> b
$ do
Int
tabId <- Tab -> GE Int
renderTab Tab
srcTab
Tab -> GE Tab
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tab -> GE Tab) -> Tab -> GE Tab
forall a b. (a -> b) -> a -> b
$ Text -> [Double] -> Tab
plainStringTab Text
idWave ([Double] -> Tab) -> [Double] -> Tab
forall a b. (a -> b) -> a -> b
$ (Int -> Double) -> [Int] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral [Int
tabId, Int
sq, Int
rescaleFlag]
triTab :: Tab
triTab :: Tab
triTab = [Double] -> Tab
elins [Double
0, Double
1, Double
0, -Double
1, Double
0]
sawTab :: Tab
sawTab :: Tab
sawTab = [Double] -> Tab
elins [Double
1, -Double
1]
sqrTab :: Tab
sqrTab :: Tab
sqrTab = [Double] -> Tab
lins [Double
1, Double
0.5, Double
1, Double
0.01, -Double
1, Double
0.5, -Double
1, Double
0.01, Double
1]
pwTab :: Double -> Tab
pwTab :: Double -> Tab
pwTab Double
duty = [Double] -> Tab
lins [Double
1, Double
duty, Double
1, Double
0.01, -Double
1, Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
duty, -Double
1, Double
0.01, Double
1]
tanhTab :: (Double, Double) -> Tab
tanhTab :: (Double, Double) -> Tab
tanhTab (Double
start, Double
end) = Text -> [Double] -> Tab
plainStringTab Text
idTanh [Double
start, Double
end, Double
0]
rescaleTanhTab :: (Double, Double) -> Tab
rescaleTanhTab :: (Double, Double) -> Tab
rescaleTanhTab (Double
start, Double
end) = Text -> [Double] -> Tab
plainStringTab Text
idTanh [Double
start, Double
end, Double
1]
expTab :: (Double, Double) -> Tab
expTab :: (Double, Double) -> Tab
expTab (Double
start, Double
end) = Text -> [Double] -> Tab
plainStringTab Text
idExp [Double
start, Double
end, Double
0]
rescaleExpTab :: (Double, Double) -> Tab
rescaleExpTab :: (Double, Double) -> Tab
rescaleExpTab (Double
start, Double
end) = Text -> [Double] -> Tab
plainStringTab Text
idExp [Double
start, Double
end, Double
1]
soneTab :: (Double, Double) -> Double -> Tab
soneTab :: (Double, Double) -> Double -> Tab
soneTab (Double
start, Double
end) Double
equalpoint = Text -> [Double] -> Tab
plainStringTab Text
idSone [Double
start, Double
end, Double
equalpoint, Double
0]
rescaleSoneTab :: (Double, Double) -> Double -> Tab
rescaleSoneTab :: (Double, Double) -> Double -> Tab
rescaleSoneTab (Double
start, Double
end) Double
equalpoint = Text -> [Double] -> Tab
plainStringTab Text
idSone [Double
start, Double
end, Double
equalpoint, Double
0]
fareyTab :: Int -> Int -> Tab
fareyTab :: Int -> Int -> Tab
fareyTab Int
mode Int
num = Text -> [Double] -> Tab
plainStringTab Text
idFarey ([Double] -> Tab) -> [Double] -> Tab
forall a b. (a -> b) -> a -> b
$ (Int -> Double) -> [Int] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral [Int
num, Int
mode]
tablew :: Sig -> Sig -> Tab -> SE ()
tablew :: Sig -> Sig -> Tab -> SE ()
tablew Sig
b1 Sig
b2 Tab
b3 = Dep () -> SE ()
forall a. Dep a -> SE a
SE (Dep () -> SE ()) -> Dep () -> SE ()
forall a b. (a -> b) -> a -> b
$ (E -> Dep ()
forall (m :: * -> *). Monad m => E -> DepT m ()
depT_ (E -> Dep ()) -> Dep E -> Dep ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep ()) -> Dep E -> Dep ()
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E -> E
f (E -> E -> E -> E) -> GE E -> GE (E -> E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE (E -> E -> E) -> GE E -> GE (E -> E)
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sig -> GE E
unSig Sig
b2 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b3
where f :: E -> E -> E -> E
f E
a1 E
a2 E
a3 = Text -> Spec1 -> [E] -> E
opcs Text
"tablew" [(Rate
Xr,[Rate
Xr,Rate
Xr,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2,E
a3]
readTab :: Sig -> Tab -> SE Sig
readTab :: Sig -> Tab -> SE Sig
readTab Sig
b1 Tab
b2 = (E -> Sig) -> SE E -> SE Sig
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ( GE E -> Sig
Sig (GE E -> Sig) -> (E -> GE E) -> E -> Sig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE Sig) -> SE E -> SE Sig
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2
where f :: E -> E -> E
f E
a1 E
a2 = Text -> Spec1 -> [E] -> E
opcs Text
"tab" [(Rate
Kr,[Rate
Kr,Rate
Ir,Rate
Ir]),(Rate
Ar,[Rate
Xr,Rate
Ir,Rate
Ir])] [E
a1,E
a2]
readTable :: SigOrD a => a -> Tab -> SE a
readTable :: forall a. SigOrD a => a -> Tab -> SE a
readTable a
b1 Tab
b2 = (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2
where f :: E -> E -> E
f E
a1 E
a2 = Text -> Spec1 -> [E] -> E
opcs Text
"table" [(Rate
Ar,[Rate
Ar,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Ir,[Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Kr,[Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2]
readTable3 :: SigOrD a => a -> Tab -> SE a
readTable3 :: forall a. SigOrD a => a -> Tab -> SE a
readTable3 a
b1 Tab
b2 = (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2
where f :: E -> E -> E
f E
a1 E
a2 = Text -> Spec1 -> [E] -> E
opcs Text
"table3" [(Rate
Ar,[Rate
Ar,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Ir,[Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Kr,[Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2]
readTablei :: SigOrD a => a -> Tab -> SE a
readTablei :: forall a. SigOrD a => a -> Tab -> SE a
readTablei a
b1 Tab
b2 = (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2
where f :: E -> E -> E
f E
a1 E
a2 = Text -> Spec1 -> [E] -> E
opcs Text
"tablei" [(Rate
Ar,[Rate
Ar,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Ir,[Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Kr,[Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2]
tableikt :: Sig -> Tab -> Sig
tableikt :: Sig -> Tab -> Sig
tableikt Sig
b1 Tab
b2 = GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2
where f :: E -> E -> E
f E
a1 E
a2 = Text -> Spec1 -> [E] -> E
opcs Text
"tableikt" [(Rate
Ar,[Rate
Xr,Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Xr,Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2]
tablekt :: Sig -> Tab -> Sig
tablekt :: Sig -> Tab -> Sig
tablekt Sig
b1 Tab
b2 = GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2
where f :: E -> E -> E
f E
a1 E
a2 = Text -> Spec1 -> [E] -> E
opcs Text
"tablekt" [(Rate
Ar,[Rate
Xr,Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Xr,Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2]
tablexkt :: Sig -> Tab -> Sig -> D -> Sig
tablexkt :: Sig -> Tab -> Sig -> D -> Sig
tablexkt Sig
b1 Tab
b2 Sig
b3 D
b4 = GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E -> E -> E -> E
f (E -> E -> E -> E -> E) -> GE E -> GE (E -> E -> E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE (E -> E -> E -> E) -> GE E -> GE (E -> E -> E)
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b2 GE (E -> E -> E) -> GE E -> GE (E -> E)
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sig -> GE E
unSig Sig
b3 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> D -> GE E
unD D
b4
where f :: E -> E -> E -> E -> E
f E
a1 E
a2 E
a3 E
a4 = Text -> Spec1 -> [E] -> E
opcs Text
"tablexkt" [(Rate
Ar,[Rate
Xr,Rate
Kr,Rate
Kr,Rate
Ir,Rate
Ir,Rate
Ir,Rate
Ir])] [E
a1,E
a2,E
a3,E
a4]
cuserrnd :: SigOrD a => a -> a -> Tab -> SE a
cuserrnd :: forall a. SigOrD a => a -> a -> Tab -> SE a
cuserrnd a
b1 a
b2 Tab
b3 = (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E -> E
f (E -> E -> E -> E) -> GE E -> GE (E -> E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1 GE (E -> E -> E) -> GE E -> GE (E -> E)
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> GE E
forall a. Val a => a -> GE E
toGE a
b2 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Tab -> GE E
unTab Tab
b3
where f :: E -> E -> E -> E
f E
a1 E
a2 E
a3 = Text -> Spec1 -> [E] -> E
opcs Text
"cuserrnd" [(Rate
Ar,[Rate
Kr,Rate
Kr,Rate
Kr])
,(Rate
Ir,[Rate
Ir,Rate
Ir,Rate
Ir])
,(Rate
Kr,[Rate
Kr,Rate
Kr,Rate
Kr])] [E
a1,E
a2,E
a3]
duserrnd :: SigOrD a => Tab -> SE a
duserrnd :: forall a. SigOrD a => Tab -> SE a
duserrnd Tab
b1 = (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ (E -> Dep E
forall (m :: * -> *). Monad m => E -> DepT m E
depT (E -> Dep E) -> Dep E -> Dep E
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> Dep E) -> Dep E -> Dep E
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ (E -> E) -> GE E -> GE E
forall a b. (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap E -> E
f (GE E -> GE E) -> GE E -> GE E
forall a b. (a -> b) -> a -> b
$ Tab -> GE E
unTab Tab
b1
where f :: E -> E
f E
a1 = Text -> Spec1 -> [E] -> E
opcs Text
"duserrnd" [(Rate
Ar,[Rate
Kr])
,(Rate
Ir,[Rate
Ir])
,(Rate
Kr,[Rate
Kr])] [E
a1]
bpRelativeArgs :: [Double] -> TabArgs
bpRelativeArgs :: [Double] -> TabArgs
bpRelativeArgs [Double]
ys = Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ (Int -> [Double]) -> Reader Int [Double]
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
reader ((Int -> [Double]) -> Reader Int [Double])
-> (Int -> [Double]) -> Reader Int [Double]
forall a b. (a -> b) -> a -> b
$ \Int
size -> Int -> [Double] -> [Double]
forall {a}. Integral a => a -> [Double] -> [Double]
fromRelative Int
size [Double]
ys
where
fromRelative :: a -> [Double] -> [Double]
fromRelative a
n [Double]
as = [Double] -> [Double] -> [Double]
forall a. [a] -> [a] -> [a]
substOdds (a -> [Double] -> [Double]
forall {f :: * -> *} {b} {a}.
(Functor f, RealFrac b, Integral a) =>
a -> f b -> f Double
makeRelative a
n ([Double] -> [Double]) -> [Double] -> [Double]
forall a b. (a -> b) -> a -> b
$ [Double] -> [Double]
forall {b}. [b] -> [b]
getOdds [Double]
as) [Double]
as
getOdds :: [b] -> [b]
getOdds [b]
xs = ((Bool, b) -> b) -> [(Bool, b)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool, b) -> b
forall a b. (a, b) -> b
snd ([(Bool, b)] -> [b]) -> [(Bool, b)] -> [b]
forall a b. (a -> b) -> a -> b
$ ((Bool, b) -> Bool) -> [(Bool, b)] -> [(Bool, b)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool, b) -> Bool
forall a b. (a, b) -> a
fst ([(Bool, b)] -> [(Bool, b)]) -> [(Bool, b)] -> [(Bool, b)]
forall a b. (a -> b) -> a -> b
$ [Bool] -> [b] -> [(Bool, b)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([Bool] -> [Bool]
forall a. HasCallStack => [a] -> [a]
cycle [Bool
True,Bool
False]) [b]
xs
substOdds :: [d] -> [d] -> [d]
substOdds [d]
odds [d]
xs = (Bool -> d -> d -> d) -> [Bool] -> [d] -> [d] -> [d]
forall a b c d. (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 Bool -> d -> d -> d
forall {p}. Bool -> p -> p -> p
go ([Bool] -> [Bool]
forall a. HasCallStack => [a] -> [a]
cycle [Bool
True,Bool
False]) ((\d
a -> [d
a,d
a]) (d -> [d]) -> [d] -> [d]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [d]
odds) [d]
xs
where go :: Bool -> p -> p -> p
go Bool
flag p
odd' p
x = if Bool
flag then p
odd' else p
x
makeRelative :: a -> f b -> f Double
makeRelative a
size f b
as = (b -> Double) -> f b -> f Double
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral :: (Int -> Double)) (Int -> Double) -> (b -> Int) -> b -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Int
forall b. Integral b => b -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (b -> Int) -> (b -> b) -> b -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
size b -> b -> b
forall a. Num a => a -> a -> a
* )) f b
as
relativeArgs :: [Double] -> TabArgs
relativeArgs :: [Double] -> TabArgs
relativeArgs [Double]
xs = Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ (Int -> [Double]) -> Reader Int [Double]
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
reader ((Int -> [Double]) -> Reader Int [Double])
-> (Int -> [Double]) -> Reader Int [Double]
forall a b. (a -> b) -> a -> b
$ \Int
size -> Int -> [Double] -> [Double]
forall {a}. Integral a => a -> [Double] -> [Double]
fromRelative Int
size [Double]
xs
where
fromRelative :: a -> [Double] -> [Double]
fromRelative a
n [Double]
as = [Double] -> [Double] -> [Double]
forall a. [a] -> [a] -> [a]
substEvens (a -> [Double] -> [Double]
forall (t :: * -> *) b a.
(Functor t, Foldable t, RealFrac b, Integral a) =>
a -> t b -> t Double
mkRelative a
n ([Double] -> [Double]) -> [Double] -> [Double]
forall a b. (a -> b) -> a -> b
$ [Double] -> [Double]
forall {b}. [b] -> [b]
getEvens [Double]
as) [Double]
as
getEvens :: [a] -> [a]
getEvens = \case
[] -> []
a
_:[] -> []
a
_:a
b:[a]
as -> a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
getEvens [a]
as
substEvens :: [a] -> [a] -> [a]
substEvens [a]
evens [a]
ys = case ([a]
evens, [a]
ys) of
([], [a]
as) -> [a]
as
([a]
_, []) -> []
(a
e:[a]
es, a
a:a
_:[a]
as) -> a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
e a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
substEvens [a]
es [a]
as
([a], [a])
_ -> String -> [a]
forall a. HasCallStack => String -> a
error String
"table argument list should contain even number of elements"
relativeArgsGen16 :: [Double] -> TabArgs
relativeArgsGen16 :: [Double] -> TabArgs
relativeArgsGen16 [Double]
xs = Reader Int [Double] -> TabArgs
ArgsPlain (Reader Int [Double] -> TabArgs) -> Reader Int [Double] -> TabArgs
forall a b. (a -> b) -> a -> b
$ (Int -> [Double]) -> Reader Int [Double]
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
reader ((Int -> [Double]) -> Reader Int [Double])
-> (Int -> [Double]) -> Reader Int [Double]
forall a b. (a -> b) -> a -> b
$ \Int
size -> Int -> [Double] -> [Double]
forall {a}. Integral a => a -> [Double] -> [Double]
formRelativeGen16 Int
size [Double]
xs
where
formRelativeGen16 :: a -> [Double] -> [Double]
formRelativeGen16 a
n [Double]
as = [Double] -> [Double] -> [Double]
forall a. [a] -> [a] -> [a]
substGen16 (a -> [Double] -> [Double]
forall (t :: * -> *) b a.
(Functor t, Foldable t, RealFrac b, Integral a) =>
a -> t b -> t Double
mkRelative a
n ([Double] -> [Double]) -> [Double] -> [Double]
forall a b. (a -> b) -> a -> b
$ [Double] -> [Double]
forall {b}. [b] -> [b]
getGen16 [Double]
as) [Double]
as
getGen16 :: [a] -> [a]
getGen16 = \case
a
_:a
durN:a
_:[a]
rest -> a
durN a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
getGen16 [a]
rest
[a]
_ -> []
substGen16 :: [a] -> [a] -> [a]
substGen16 [a]
durs [a]
ys = case ([a]
durs, [a]
ys) of
([], [a]
as) -> [a]
as
([a]
_, []) -> []
(a
d:[a]
ds, a
valN:a
_:a
typeN:[a]
rest) -> a
valN a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
d a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
typeN a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
substGen16 [a]
ds [a]
rest
([a]
_, [a]
_) -> [a]
ys
mkRelative :: (Functor t, Foldable t, RealFrac b, Integral a) => a -> t b -> t Double
mkRelative :: forall (t :: * -> *) b a.
(Functor t, Foldable t, RealFrac b, Integral a) =>
a -> t b -> t Double
mkRelative a
n t b
as = (b -> Double) -> t b -> t Double
forall a b. (a -> b) -> t a -> t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral :: (Int -> Double)) (Int -> Double) -> (b -> Int) -> b -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Int
forall b. Integral b => b -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (b -> Int) -> (b -> b) -> b -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b
s b -> b -> b
forall a. Num a => a -> a -> a
* )) t b
as
where s :: b
s = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
n b -> b -> b
forall a. Fractional a => a -> a -> a
/ t b -> b
forall a. Num a => t a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum t b
as