module Synthesizer.Plain.Modifier where
import Control.Monad.State (State(..), zipWithM, evalState)
import qualified Data.List as List
import Prelude hiding (init)
type T a = [a]
data Simple s ctrl a b =
Simple {
init :: s,
step :: ctrl -> a -> State s b
}
static ::
Simple s ctrl a b -> ctrl -> T a -> T b
static modif control x =
evalState (mapM (step modif control) x) (init modif)
modulated ::
Simple s ctrl a b -> T ctrl -> T a -> T b
modulated modif control x =
evalState (zipWithM (step modif) control x) (init modif)
data Initialized s init ctrl a b =
Initialized {
initInit :: init -> s,
initStep :: ctrl -> a -> State s b
}
initialize ::
Initialized s init ctrl a b -> init -> Simple s ctrl a b
initialize modif stateInit =
Simple (initInit modif stateInit) (initStep modif)
staticInit ::
Initialized s init ctrl a b -> init -> ctrl -> T a -> T b
staticInit modif state =
static (initialize modif state)
modulatedInit ::
Initialized s init ctrl a b -> init -> T ctrl -> T a -> T b
modulatedInit modif state =
modulated (initialize modif state)
stackStatesR :: (a -> State s a) -> (a -> State [s] a)
stackStatesR m =
State . List.mapAccumR (runState . m)
stackStatesL :: (a -> State s a) -> (a -> State [s] a)
stackStatesL m =
State . List.mapAccumL (runState . m)