module Csound.Typed.Plugins.Adsr140(
  adsr140
) where

import Csound.Dynamic

import Csound.Typed.Types.Prim
import Csound.Typed.GlobalState
import qualified Csound.Typed.GlobalState.Elements as E(adsr140Plugin)


-------------------------------------------------------------------------------

-- | Gated, Re-triggerable ADSR modeled after the Doepfer A-140
-- opcode adsr140, a, aakkkk
--
-- inputs: agate, aretrig, kattack, kdecay, ksustain, krelease
adsr140 :: Sig -> Sig -> Sig -> Sig -> Sig -> Sig -> Sig
adsr140 :: Sig -> Sig -> Sig -> Sig -> Sig -> Sig -> Sig
adsr140 Sig
agate Sig
aretrig Sig
kattack Sig
kdecay Sig
ksustain Sig
krelease = GE E -> Sig
forall a. Val a => GE E -> a
fromGE (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ do
    UdoPlugin -> GE ()
addUdoPlugin UdoPlugin
E.adsr140Plugin
    E -> E -> E -> E -> E -> E -> E
f (E -> E -> E -> E -> E -> E -> E)
-> GE E -> GE (E -> E -> E -> E -> E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
agate GE (E -> E -> E -> E -> E -> E)
-> GE E -> GE (E -> E -> 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
<*> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
aretrig GE (E -> E -> E -> E -> E) -> GE E -> GE (E -> 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
<*> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
kattack 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
<*> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
kdecay 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
forall a. Val a => a -> GE E
toGE Sig
ksustain 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
forall a. Val a => a -> GE E
toGE Sig
krelease
    where f :: E -> E -> E -> E -> E -> E -> E
f E
agate' E
aretrig' E
kattack' E
kdecay' E
ksustain' E
krelease' = Name -> Spec1 -> [E] -> E
opcs Name
"adsr140" [(Rate
Ar, [Rate
Ar, Rate
Ar, Rate
Kr, Rate
Kr, Rate
Kr, Rate
Kr])] [E
agate', E
aretrig', E
kattack', E
kdecay', E
ksustain', E
krelease']