module Csound.Typed.Plugins.AmbiRow(
  ambiRow, ambiRowMp3
) where

import Csound.Dynamic

import Csound.Typed.Types
import Csound.Typed.GlobalState
import qualified Csound.Typed.GlobalState.Elements as E(ambiRowPlugin, ambiRowMp3Plugin)

ambiRow :: Arr1 Str -> Sig -> Sig -> D -> Sig2
ambiRow :: Arr1 Str -> Sig -> Sig -> D -> Sig2
ambiRow (Arr [Var]
sFiles) Sig
kSpeed Sig
kIndex D
iFadeTime = GE [E] -> Sig2
forall a. Tuple a => GE [E] -> a
toTuple (GE [E] -> Sig2) -> GE [E] -> Sig2
forall a b. (a -> b) -> a -> b
$ ((Int -> [E]) -> [E]) -> GE (Int -> [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 ((Int -> [E]) -> Int -> [E]
forall a b. (a -> b) -> a -> b
$ Int
2) (GE (Int -> [E]) -> GE [E]) -> GE (Int -> [E]) -> GE [E]
forall a b. (a -> b) -> a -> b
$ do
  UdoPlugin -> GE ()
addUdoPlugin UdoPlugin
E.ambiRowPlugin
  [Var] -> E -> E -> E -> Int -> [E]
f [Var]
sFiles (E -> E -> E -> Int -> [E]) -> GE E -> GE (E -> E -> Int -> [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
kSpeed GE (E -> E -> Int -> [E]) -> GE E -> GE (E -> Int -> [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
kIndex GE (E -> Int -> [E]) -> GE E -> GE (Int -> [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
forall a. Val a => a -> GE E
toGE D
iFadeTime
  where f :: [Var] -> E -> E -> E -> Int -> [E]
f [Var]
sFiles' E
kSpeed' E
kIndex' E
iFadeTime' = Name -> Specs -> [E] -> Int -> [E]
mopcs Name
"AmbiRow" ([Rate
Ar, Rate
Ar], [Rate
Sr, Rate
Kr, Rate
Kr, Rate
Ir]) [Var -> E
inlineVar (Var -> E) -> Var -> E
forall a b. (a -> b) -> a -> b
$ [Var] -> Var
forall a. HasCallStack => [a] -> a
head [Var]
sFiles', E
kSpeed', E
kIndex', E
iFadeTime']

ambiRowMp3 :: Arr1 Str -> Sig -> Sig -> D -> Sig2
ambiRowMp3 :: Arr1 Str -> Sig -> Sig -> D -> Sig2
ambiRowMp3 (Arr [Var]
sFiles) Sig
kSpeed Sig
kIndex D
iFadeTime = GE [E] -> Sig2
forall a. Tuple a => GE [E] -> a
toTuple (GE [E] -> Sig2) -> GE [E] -> Sig2
forall a b. (a -> b) -> a -> b
$ ((Int -> [E]) -> [E]) -> GE (Int -> [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 ((Int -> [E]) -> Int -> [E]
forall a b. (a -> b) -> a -> b
$ Int
2) (GE (Int -> [E]) -> GE [E]) -> GE (Int -> [E]) -> GE [E]
forall a b. (a -> b) -> a -> b
$ do
  UdoPlugin -> GE ()
addUdoPlugin UdoPlugin
E.ambiRowMp3Plugin
  [Var] -> E -> E -> E -> Int -> [E]
f [Var]
sFiles (E -> E -> E -> Int -> [E]) -> GE E -> GE (E -> E -> Int -> [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
kSpeed GE (E -> E -> Int -> [E]) -> GE E -> GE (E -> Int -> [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
kIndex GE (E -> Int -> [E]) -> GE E -> GE (Int -> [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
forall a. Val a => a -> GE E
toGE D
iFadeTime
  where f :: [Var] -> E -> E -> E -> Int -> [E]
f [Var]
sFiles' E
kSpeed' E
kIndex' E
iFadeTime' = Name -> Specs -> [E] -> Int -> [E]
mopcs Name
"AmbiRowMp3" ([Rate
Ar, Rate
Ar], [Rate
Sr, Rate
Kr, Rate
Kr, Rate
Ir]) [Var -> E
inlineVar (Var -> E) -> Var -> E
forall a b. (a -> b) -> a -> b
$ [Var] -> Var
forall a. HasCallStack => [a] -> a
head [Var]
sFiles', E
kSpeed', E
kIndex', E
iFadeTime']