module Csound.Dynamic.Build (

    -- * Expression tree
    -- | Working with expression tree
    toExp, onExp,

    -- * Rates
    -- * Queries
    getRates, isMultiOutSignature, getPrimUnsafe,

    -- * Constructors
    -- | Basic constructors
    prim, opcPrefix, oprPrefix, oprInfix,
    numExp1,
    tfm, tfmNoInlineArgs, pn, withInits,
    double, int, str, verbatim, instrIdE,
    inlineVar, gInit, gInitDouble,

    -- ** Opcodes constructors
    Spec1, spec1, opcs, opcsNoInlineArgs, opr1, opr1k, infOpr, oprBy,
    Specs, specs, MultiOut, mopcs, mo,

    -- * Global init statements
    setSr, setKsmps, setNchnls, setNchnls_i, setKr, setZeroDbfs,

    -- * Arrays
    opcsArr, infOprArr
) where

import qualified Data.Map as M(fromList, toList)

import Data.List(transpose)
import Data.Fix(Fix(..))

import Csound.Dynamic.Types.Exp
import Csound.Dynamic.Types.Dep

------------------------------------------------
-- basic constructors

prim :: Prim -> E
prim :: Prim -> E
prim = Exp E -> E
noRate (Exp E -> E) -> (Prim -> Exp E) -> Prim -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Prim -> Exp E
forall a. Prim -> MainExp a
ExpPrim

opcPrefix :: Name -> Signature -> Info
opcPrefix :: Name -> Signature -> Info
opcPrefix Name
name Signature
signature = Name -> Signature -> OpcFixity -> Info
Info Name
name Signature
signature OpcFixity
Opcode

oprPrefix :: Name -> Signature -> Info
oprPrefix :: Name -> Signature -> Info
oprPrefix Name
name Signature
signature = Name -> Signature -> OpcFixity -> Info
Info Name
name Signature
signature OpcFixity
Prefix

oprInfix :: Name -> Signature -> Info
oprInfix :: Name -> Signature -> Info
oprInfix Name
name Signature
signature = Name -> Signature -> OpcFixity -> Info
Info Name
name Signature
signature OpcFixity
Infix

tfm :: Info -> [E] -> E
tfm :: Info -> [E] -> E
tfm Info
info [E]
args = Exp E -> E
noRate (Exp E -> E) -> Exp E -> E
forall a b. (a -> b) -> a -> b
$ Info -> [PrimOr E] -> Exp E
forall a. Info -> [a] -> MainExp a
Tfm Info
info ([PrimOr E] -> Exp E) -> [PrimOr E] -> Exp E
forall a b. (a -> b) -> a -> b
$ (Rate -> E -> PrimOr E) -> [Rate] -> [E] -> [PrimOr E]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Rate -> E -> PrimOr E
toPrimOrTfm (Info -> [Rate]
getInfoRates Info
info) [E]
args

tfmArr :: Monad m => IsArrInit -> Var -> Info -> [E] -> DepT m ()
tfmArr :: IsArrInit -> Var -> Info -> [E] -> DepT m ()
tfmArr IsArrInit
isArrInit Var
var Info
info [E]
args = E -> DepT m ()
forall (m :: * -> *). Monad m => E -> DepT m ()
depT_ (E -> DepT m ()) -> E -> DepT m ()
forall a b. (a -> b) -> a -> b
$ Exp E -> E
noRate (Exp E -> E) -> Exp E -> E
forall a b. (a -> b) -> a -> b
$ IsArrInit -> Var -> Info -> [PrimOr E] -> Exp E
forall a. IsArrInit -> Var -> Info -> [a] -> MainExp a
TfmArr IsArrInit
isArrInit Var
var Info
info ([PrimOr E] -> Exp E) -> [PrimOr E] -> Exp E
forall a b. (a -> b) -> a -> b
$ (Rate -> E -> PrimOr E) -> [Rate] -> [E] -> [PrimOr E]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Rate -> E -> PrimOr E
toPrimOrTfm (Info -> [Rate]
getInfoRates Info
info) [E]
args

getInfoRates :: Info -> [Rate]
getInfoRates :: Info -> [Rate]
getInfoRates Info
a = Signature -> [Rate]
getInRates (Signature -> [Rate]) -> Signature -> [Rate]
forall a b. (a -> b) -> a -> b
$ Info -> Signature
infoSignature Info
a
    where
        getInRates :: Signature -> [Rate]
getInRates Signature
x = case Signature
x of
            SingleRate Map Rate [Rate]
m    -> ([Rate] -> Rate) -> [[Rate]] -> [Rate]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Rate] -> Rate
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum ([[Rate]] -> [Rate]) -> [[Rate]] -> [Rate]
forall a b. (a -> b) -> a -> b
$ [[Rate]] -> [[Rate]]
forall a. [[a]] -> [[a]]
transpose ([[Rate]] -> [[Rate]]) -> [[Rate]] -> [[Rate]]
forall a b. (a -> b) -> a -> b
$ ((Rate, [Rate]) -> [Rate]) -> [(Rate, [Rate])] -> [[Rate]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Rate, [Rate]) -> [Rate]
forall a b. (a, b) -> b
snd ([(Rate, [Rate])] -> [[Rate]]) -> [(Rate, [Rate])] -> [[Rate]]
forall a b. (a -> b) -> a -> b
$ Map Rate [Rate] -> [(Rate, [Rate])]
forall k a. Map k a -> [(k, a)]
M.toList Map Rate [Rate]
m
            MultiRate [Rate]
_ [Rate]
ins -> [Rate]
ins

tfmNoInlineArgs :: Info -> [E] -> E
tfmNoInlineArgs :: Info -> [E] -> E
tfmNoInlineArgs Info
info [E]
args = Exp E -> E
noRate (Exp E -> E) -> Exp E -> E
forall a b. (a -> b) -> a -> b
$ Info -> [PrimOr E] -> Exp E
forall a. Info -> [a] -> MainExp a
Tfm Info
info ([PrimOr E] -> Exp E) -> [PrimOr E] -> Exp E
forall a b. (a -> b) -> a -> b
$ (E -> PrimOr E) -> [E] -> [PrimOr E]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Either Prim E -> PrimOr E
forall a. Either Prim a -> PrimOr a
PrimOr (Either Prim E -> PrimOr E)
-> (E -> Either Prim E) -> E -> PrimOr E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> Either Prim E
forall a b. b -> Either a b
Right) [E]
args

inlineVar :: Var -> E
inlineVar :: Var -> E
inlineVar = RatedExp E -> E
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (RatedExp E -> E) -> (Var -> RatedExp E) -> Var -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Rate -> Maybe LineNum -> Exp E -> RatedExp E
forall a. Maybe Rate -> Maybe LineNum -> Exp a -> RatedExp a
RatedExp Maybe Rate
forall a. Maybe a
Nothing Maybe LineNum
forall a. Maybe a
Nothing (Exp E -> RatedExp E) -> (Var -> Exp E) -> Var -> RatedExp E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Exp E
forall a. Var -> MainExp a
ReadVar

pn :: Int -> E
pn :: LineNum -> E
pn = Prim -> E
prim (Prim -> E) -> (LineNum -> Prim) -> LineNum -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LineNum -> Prim
P

withInits :: E -> [E] -> E
withInits :: E -> [E] -> E
withInits E
a [E]
es = (Exp E -> Exp E) -> E -> E
onExp Exp E -> Exp E
phi E
a
    where phi :: Exp E -> Exp E
phi Exp E
x = case Exp E
x of
            -- for opcodes with single output
            Tfm Info
t [PrimOr E]
xs -> Info -> [PrimOr E] -> Exp E
forall a. Info -> [a] -> MainExp a
Tfm Info
t ([PrimOr E]
xs [PrimOr E] -> [PrimOr E] -> [PrimOr E]
forall a. [a] -> [a] -> [a]
++ ((E -> PrimOr E) -> [E] -> [PrimOr E]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap E -> PrimOr E
toPrimOr [E]
es))
            -- for opcodes with multiple outputs
            Select Rate
r LineNum
n PrimOr E
expr -> Rate -> LineNum -> PrimOr E -> Exp E
forall a. Rate -> LineNum -> a -> MainExp a
Select Rate
r LineNum
n (PrimOr E -> Exp E) -> PrimOr E -> Exp E
forall a b. (a -> b) -> a -> b
$ (E -> E) -> PrimOr E -> PrimOr E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\E
t -> E -> [E] -> E
withInits E
t [E]
es) PrimOr E
expr
            Exp E
_        -> Exp E
x

-- | Converts Haskell's doubles to Csound's doubles
double :: Double -> E
double :: Double -> E
double = Prim -> E
prim (Prim -> E) -> (Double -> Prim) -> Double -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Prim
PrimDouble

-- | Converts Haskell's strings to Csound's strings
str :: String -> E
str :: Name -> E
str = Prim -> E
prim (Prim -> E) -> (Name -> Prim) -> Name -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Prim
PrimString

-- | Converts Haskell's integers to Csound's doubles
int :: Int -> E
int :: LineNum -> E
int = Prim -> E
prim (Prim -> E) -> (LineNum -> Prim) -> LineNum -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LineNum -> Prim
PrimInt

verbatim :: Monad m => String -> DepT m ()
verbatim :: Name -> DepT m ()
verbatim = Exp E -> DepT m ()
forall (m :: * -> *). Monad m => Exp E -> DepT m ()
stmtOnlyT (Exp E -> DepT m ()) -> (Name -> Exp E) -> Name -> DepT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Exp E
forall a. Name -> MainExp a
Verbatim

instrIdE :: InstrId -> E
instrIdE :: InstrId -> E
instrIdE InstrId
x = case InstrId
x of
    InstrId Maybe LineNum
Nothing  LineNum
m -> LineNum -> E
int LineNum
m
    InstrId (Just LineNum
_) LineNum
_ -> Name -> E
forall a. HasCallStack => Name -> a
error Name
"instrId undefined for fractional InstrIds"
    InstrLabel Name
s -> Name -> E
str Name
s
----------------------------------------------------------------------
-- constructing opcodes

-- single output

-- User friendly type for single output type signatures
type Spec1 = [(Rate, [Rate])]

spec1 :: Spec1 -> Signature
spec1 :: [(Rate, [Rate])] -> Signature
spec1 = Map Rate [Rate] -> Signature
SingleRate (Map Rate [Rate] -> Signature)
-> ([(Rate, [Rate])] -> Map Rate [Rate])
-> [(Rate, [Rate])]
-> Signature
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Rate, [Rate])] -> Map Rate [Rate]
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList

opcs :: Name -> Spec1 -> [E] -> E
opcs :: Name -> [(Rate, [Rate])] -> [E] -> E
opcs Name
name [(Rate, [Rate])]
signature = Info -> [E] -> E
tfm (Name -> Signature -> Info
opcPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate, [Rate])]
signature)

opcsNoInlineArgs :: Name -> Spec1 -> [E] -> E
opcsNoInlineArgs :: Name -> [(Rate, [Rate])] -> [E] -> E
opcsNoInlineArgs Name
name [(Rate, [Rate])]
signature = Info -> [E] -> E
tfmNoInlineArgs (Name -> Signature -> Info
opcPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate, [Rate])]
signature)

opr1 :: Name -> E -> E
opr1 :: Name -> E -> E
opr1 Name
name E
a = Info -> [E] -> E
tfm (Name -> Signature -> Info
oprPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate
Ar, [Rate
Ar]), (Rate
Kr, [Rate
Kr]), (Rate
Ir, [Rate
Ir])]) [E
a]

oprBy :: Name -> Spec1 -> [E] -> E
oprBy :: Name -> [(Rate, [Rate])] -> [E] -> E
oprBy Name
name [(Rate, [Rate])]
signature = Info -> [E] -> E
tfm (Name -> Signature -> Info
oprPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate, [Rate])]
signature)

opr1k :: Name -> E -> E
opr1k :: Name -> E -> E
opr1k Name
name E
a = Info -> [E] -> E
tfm (Name -> Signature -> Info
oprPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate
Kr, [Rate
Kr]), (Rate
Ir, [Rate
Ir])]) [E
a]

infOpr :: Name -> E -> E -> E
infOpr :: Name -> E -> E -> E
infOpr Name
name E
a E
b = Info -> [E] -> E
tfm (Name -> Signature -> Info
oprInfix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate
Ar, [Rate
Ar, Rate
Ar]), (Rate
Kr, [Rate
Kr, Rate
Kr]), (Rate
Ir, [Rate
Ir, Rate
Ir])]) [E
a, E
b]

numExp1 :: NumOp -> E -> E
numExp1 :: NumOp -> E -> E
numExp1 NumOp
op E
x = Exp E -> E
noRate (Exp E -> E) -> Exp E -> E
forall a b. (a -> b) -> a -> b
$ NumExp (PrimOr E) -> Exp E
forall a. NumExp a -> MainExp a
ExpNum (NumExp (PrimOr E) -> Exp E) -> NumExp (PrimOr E) -> Exp E
forall a b. (a -> b) -> a -> b
$ (E -> PrimOr E) -> PreInline NumOp E -> NumExp (PrimOr E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap E -> PrimOr E
toPrimOr (PreInline NumOp E -> NumExp (PrimOr E))
-> PreInline NumOp E -> NumExp (PrimOr E)
forall a b. (a -> b) -> a -> b
$ NumOp -> [E] -> PreInline NumOp E
forall a b. a -> [b] -> PreInline a b
PreInline NumOp
op [E
x]

opcsArr :: Monad m => IsArrInit -> Var -> Name -> Spec1 -> [E] -> DepT m ()
opcsArr :: IsArrInit -> Var -> Name -> [(Rate, [Rate])] -> [E] -> DepT m ()
opcsArr IsArrInit
isArrInit Var
out Name
name [(Rate, [Rate])]
signature = IsArrInit -> Var -> Info -> [E] -> DepT m ()
forall (m :: * -> *).
Monad m =>
IsArrInit -> Var -> Info -> [E] -> DepT m ()
tfmArr IsArrInit
isArrInit Var
out (Name -> Signature -> Info
opcPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate, [Rate])]
signature)

infOprArr :: Monad m => IsArrInit -> Var -> Name -> E -> E -> DepT m ()
infOprArr :: IsArrInit -> Var -> Name -> E -> E -> DepT m ()
infOprArr IsArrInit
isArrInit Var
out Name
name E
a E
b = IsArrInit -> Var -> Info -> [E] -> DepT m ()
forall (m :: * -> *).
Monad m =>
IsArrInit -> Var -> Info -> [E] -> DepT m ()
tfmArr IsArrInit
isArrInit Var
out (Name -> Signature -> Info
oprInfix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ [(Rate, [Rate])] -> Signature
spec1 [(Rate
Ar, [Rate
Ar, Rate
Ar]), (Rate
Kr, [Rate
Kr, Rate
Kr]), (Rate
Ir, [Rate
Ir, Rate
Ir])]) [E
a, E
b]

-- multiple output

-- User friendly type for multiple outputs type signatures
type Specs = ([Rate], [Rate])

specs :: Specs -> Signature
specs :: Specs -> Signature
specs = ([Rate] -> [Rate] -> Signature) -> Specs -> Signature
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [Rate] -> [Rate] -> Signature
MultiRate

mopcs :: Name -> Specs -> [E] -> MultiOut [E]
mopcs :: Name -> Specs -> [E] -> MultiOut [E]
mopcs Name
name Specs
signature [E]
as = \LineNum
numOfOuts -> LineNum -> E -> [E]
mo LineNum
numOfOuts (E -> [E]) -> E -> [E]
forall a b. (a -> b) -> a -> b
$ Info -> [E] -> E
tfm (Name -> Signature -> Info
opcPrefix Name
name (Signature -> Info) -> Signature -> Info
forall a b. (a -> b) -> a -> b
$ Specs -> Signature
specs Specs
signature) [E]
as

mo :: Int -> E -> [E]
mo :: LineNum -> E -> [E]
mo LineNum
n E
e = (LineNum -> Rate -> E) -> [LineNum] -> [Rate] -> [E]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\LineNum
cellId Rate
r -> LineNum -> Rate -> E -> E
select LineNum
cellId Rate
r E
e') [LineNum
0 ..] [Rate]
outRates
    where outRates :: [Rate]
outRates = LineNum -> [Rate] -> [Rate]
forall a. LineNum -> [a] -> [a]
take LineNum
n ([Rate] -> [Rate]) -> [Rate] -> [Rate]
forall a b. (a -> b) -> a -> b
$ Exp E -> [Rate]
forall a. MainExp a -> [Rate]
getRates (Exp E -> [Rate]) -> Exp E -> [Rate]
forall a b. (a -> b) -> a -> b
$ E -> Exp E
toExp E
e
          e' :: E
e' = (Exp E -> Exp E) -> E -> E
onExp ([Rate] -> Exp E -> Exp E
forall a. [Rate] -> MainExp a -> MainExp a
setMultiRate [Rate]
outRates) E
e

          setMultiRate :: [Rate] -> MainExp a -> MainExp a
setMultiRate [Rate]
rates (Tfm Info
info [a]
xs) = Info -> [a] -> MainExp a
forall a. Info -> [a] -> MainExp a
Tfm (Info
info{ infoSignature :: Signature
infoSignature = [Rate] -> [Rate] -> Signature
MultiRate [Rate]
rates [Rate]
ins }) [a]
xs
              where ins :: [Rate]
ins = case Info -> Signature
infoSignature Info
info of
                        MultiRate [Rate]
_ [Rate]
a -> [Rate]
a
                        Signature
_ -> Name -> [Rate]
forall a. HasCallStack => Name -> a
error Name
"Tuple.hs: multiOutsSection -- should be multiOut expression"
          setMultiRate [Rate]
_ MainExp a
_ = Name -> MainExp a
forall a. HasCallStack => Name -> a
error Name
"Tuple.hs: multiOutsSection -- argument should be Tfm-expression"

          select :: LineNum -> Rate -> E -> E
select LineNum
cellId Rate
rate E
expr = Rate -> Exp E -> E
withRate Rate
rate (Exp E -> E) -> Exp E -> E
forall a b. (a -> b) -> a -> b
$ Rate -> LineNum -> PrimOr E -> Exp E
forall a. Rate -> LineNum -> a -> MainExp a
Select Rate
rate LineNum
cellId (Either Prim E -> PrimOr E
forall a. Either Prim a -> PrimOr a
PrimOr (Either Prim E -> PrimOr E) -> Either Prim E -> PrimOr E
forall a b. (a -> b) -> a -> b
$ E -> Either Prim E
forall a b. b -> Either a b
Right E
expr)


getRates :: MainExp a -> [Rate]
getRates :: MainExp a -> [Rate]
getRates (Tfm Info
info [a]
_) = case Info -> Signature
infoSignature Info
info of
    MultiRate [Rate]
outs [Rate]
_ -> [Rate]
outs
    Signature
_ -> Name -> [Rate]
forall a. HasCallStack => Name -> a
error Name
"Build.hs:getRates - argument should be multiOut"
getRates MainExp a
_ = Name -> [Rate]
forall a. HasCallStack => Name -> a
error Name
"Build.hs:getRates - argument should be Tfm-expression"


isMultiOutSignature :: Signature -> Bool
isMultiOutSignature :: Signature -> IsArrInit
isMultiOutSignature Signature
x = case Signature
x of
    MultiRate [Rate]
_ [Rate]
_ -> IsArrInit
True
    Signature
_ -> IsArrInit
False

getPrimUnsafe :: E -> Prim
getPrimUnsafe :: E -> Prim
getPrimUnsafe E
x = case E -> Exp E
toExp E
x of
    ExpPrim Prim
a   -> Prim
a
    Exp E
_           -> Name -> Prim
forall a. HasCallStack => Name -> a
error Name
"Csound.Dynamic.Build.getPrimUnsafe:Expression is not a primitive"

-- expression tree

toExp :: E -> Exp E
toExp :: E -> Exp E
toExp = RatedExp E -> Exp E
forall a. RatedExp a -> Exp a
ratedExpExp (RatedExp E -> Exp E) -> (E -> RatedExp E) -> E -> Exp E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix

-- Lifts transformation of main expression
onExp :: (Exp E -> Exp E) -> E -> E
onExp :: (Exp E -> Exp E) -> E -> E
onExp Exp E -> Exp E
f E
x = case E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
x of
    RatedExp E
a -> RatedExp E -> E
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (RatedExp E -> E) -> RatedExp E -> E
forall a b. (a -> b) -> a -> b
$ RatedExp E
a{ ratedExpExp :: Exp E
ratedExpExp = Exp E -> Exp E
f (RatedExp E -> Exp E
forall a. RatedExp a -> Exp a
ratedExpExp RatedExp E
a) }

----------------------------------------------------------------
-- global inits

setSr, setKsmps, setNchnls, setNchnls_i, setKr :: Monad m => Int -> DepT m ()

setZeroDbfs :: Monad m => Double -> DepT m  ()

setGlobal :: (Monad m, Show a) => String -> a -> DepT m  ()
setGlobal :: Name -> a -> DepT m ()
setGlobal Name
name a
val = Name -> DepT m ()
forall (m :: * -> *). Monad m => Name -> DepT m ()
verbatim (Name -> DepT m ()) -> Name -> DepT m ()
forall a b. (a -> b) -> a -> b
$ Name
name Name -> Name -> Name
forall a. [a] -> [a] -> [a]
++ Name
" = " Name -> Name -> Name
forall a. [a] -> [a] -> [a]
++ a -> Name
forall a. Show a => a -> Name
show a
val

setSr :: LineNum -> DepT m ()
setSr       = Name -> LineNum -> DepT m ()
forall (m :: * -> *) a. (Monad m, Show a) => Name -> a -> DepT m ()
setGlobal Name
"sr"
setKr :: LineNum -> DepT m ()
setKr       = Name -> LineNum -> DepT m ()
forall (m :: * -> *) a. (Monad m, Show a) => Name -> a -> DepT m ()
setGlobal Name
"kr"
setNchnls :: LineNum -> DepT m ()
setNchnls   = Name -> LineNum -> DepT m ()
forall (m :: * -> *) a. (Monad m, Show a) => Name -> a -> DepT m ()
setGlobal Name
"nchnls"
setNchnls_i :: LineNum -> DepT m ()
setNchnls_i = Name -> LineNum -> DepT m ()
forall (m :: * -> *) a. (Monad m, Show a) => Name -> a -> DepT m ()
setGlobal Name
"nchnls_i"
setKsmps :: LineNum -> DepT m ()
setKsmps    = Name -> LineNum -> DepT m ()
forall (m :: * -> *) a. (Monad m, Show a) => Name -> a -> DepT m ()
setGlobal Name
"ksmps"
setZeroDbfs :: Double -> DepT m ()
setZeroDbfs = Name -> Double -> DepT m ()
forall (m :: * -> *) a. (Monad m, Show a) => Name -> a -> DepT m ()
setGlobal Name
"0dbfs"

gInit :: Monad m => String -> Int -> DepT m ()
gInit :: Name -> LineNum -> DepT m ()
gInit Name
name LineNum
val = Var -> E -> DepT m ()
forall (m :: * -> *). Monad m => Var -> E -> DepT m ()
writeVar (Rate -> Name -> Var
VarVerbatim Rate
Ir Name
name) (LineNum -> E
int LineNum
val)

gInitDouble :: Monad m => String -> Double -> DepT m ()
gInitDouble :: Name -> Double -> DepT m ()
gInitDouble Name
name Double
val = Var -> E -> DepT m ()
forall (m :: * -> *). Monad m => Var -> E -> DepT m ()
writeVar (Rate -> Name -> Var
VarVerbatim Rate
Ir Name
name) (Double -> E
double Double
val)