{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module FRP.Rhine.ClSF.Upsample where
import Data.Semigroup
import Control.Monad.Trans.MSF.Reader
import FRP.Rhine.ClSF.Core
import FRP.Rhine.Schedule
upsampleMSF :: Monad m => b -> MSF m a b -> MSF m (Either arbitrary a) b
upsampleMSF b msf = right msf >>> accumulateWith (<>) (Right b) >>> arr fromRight
where
fromRight (Right b') = b'
fromRight (Left _ ) = error "fromRight: This case never occurs in upsampleMSF."
upsampleR
:: (Monad m, Time clL ~ Time clR)
=> b -> ClSF m clR a b -> ClSF m (ParallelClock m clL clR) a b
upsampleR b clsf = readerS $ arr remap >>> upsampleMSF b (runReaderS clsf)
where
remap (TimeInfo { tag = Left tag }, _) = Left tag
remap (TimeInfo { tag = Right tag, .. }, a) = Right (TimeInfo { .. }, a)
upsampleL
:: (Monad m, Time clL ~ Time clR)
=> b -> ClSF m clL a b -> ClSF m (ParallelClock m clL clR) a b
upsampleL b clsf = readerS $ arr remap >>> upsampleMSF b (runReaderS clsf)
where
remap (TimeInfo { tag = Right tag }, _) = Left tag
remap (TimeInfo { tag = Left tag, .. }, a) = Right (TimeInfo { .. }, a)