{- |
Translate clocked signal processing components to stream functions without explicit clock types.

This module is not meant to be used externally,
and is thus not exported from 'FRP.Rhine'.
-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TupleSections #-}
module FRP.Rhine.Reactimation.ClockErasure where

-- base
import Control.Monad (join)

-- dunai
import Control.Monad.Trans.MSF.Reader
import Data.MonadicStreamFunction

-- rhine
import FRP.Rhine.Clock
import FRP.Rhine.Clock.Proxy
import FRP.Rhine.Clock.Util
import FRP.Rhine.ClSF hiding (runReaderS)
import FRP.Rhine.ResamplingBuffer
import FRP.Rhine.SN

-- | Run a clocked signal function as a monadic stream function,
--   accepting the timestamps and tags as explicit inputs.
eraseClockClSF
  :: (Monad m, Clock m cl)
  => ClockProxy cl -> Time cl
  -> ClSF m cl a b
  -> MSF m (Time cl, Tag cl, a) b
eraseClockClSF :: forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl) =>
ClockProxy cl
-> Time cl -> ClSF m cl a b -> MSF m (Time cl, Tag cl, a) b
eraseClockClSF ClockProxy cl
proxy Time cl
initialTime ClSF m cl a b
clsf = proc (Time cl
time, Tag cl
tag, a
a) -> do
  TimeInfo cl
timeInfo <- forall (m :: Type -> Type) cl.
(Monad m, Clock m cl) =>
ClockProxy cl -> Time cl -> MSF m (Time cl, Tag cl) (TimeInfo cl)
genTimeInfo ClockProxy cl
proxy Time cl
initialTime -< (Time cl
time, Tag cl
tag)
  forall (m :: Type -> Type) r a b.
Monad m =>
MSF (ReaderT r m) a b -> MSF m (r, a) b
runReaderS ClSF m cl a b
clsf                           -< (TimeInfo cl
timeInfo, a
a)

-- | Run a signal network as a monadic stream function.
--
--   Depending on the incoming clock,
--   input data may need to be provided,
--   and depending on the outgoing clock,
--   output data may be generated.
--   There are thus possible invalid inputs,
--   which 'eraseClockSN' does not gracefully handle.
eraseClockSN
  :: (Monad m, Clock m cl, GetClockProxy cl)
  => Time cl
  -> SN m cl a b
  -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)

-- A synchronous signal network is run by erasing the clock from the clocked signal function.
eraseClockSN :: forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime sn :: SN m cl a b
sn@(Synchronous ClSF m cl a b
clsf) = proc (Time cl
time, Tag cl
tag, Just a
a) -> do
  b
b <- forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl) =>
ClockProxy cl
-> Time cl -> ClSF m cl a b -> MSF m (Time cl, Tag cl, a) b
eraseClockClSF (forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m cl a b
sn) Time cl
initialTime ClSF m cl a b
clsf -< (Time cl
time, Tag cl
tag, a
a)
  forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA                                                -< forall a. a -> Maybe a
Just b
b

-- A sequentially composed signal network may either be triggered in its first component,
-- or its second component. In either case,
-- the resampling buffer (which connects the two components) may be triggered,
-- but only if the outgoing clock of the first component ticks,
-- or the incoming clock of the second component ticks.
eraseClockSN Time cl
initialTime (Sequential SN m clab a b
sn1 ResamplingBuffer m (Out clab) (In clcd) b c
resBuf SN m clcd c b
sn2) =
  let
    proxy1 :: ClockProxy (Cl (SN m clab a b))
proxy1 = forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m clab a b
sn1
    proxy2 :: ClockProxy (Cl (SN m clcd c b))
proxy2 = forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m clcd c b
sn2
  in proc (Time cl
time, Tag cl
tag, Maybe a
maybeA) -> do
  Maybe
  (Either
     (Time (In clcd), Tag (Out clab), b)
     (Time (In clcd), Tag (In clcd)))
resBufIn <- case Tag cl
tag of
    Left  Tag clab
tagL -> do
      Maybe b
maybeB <- forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m clab a b
sn1 -< (Time cl
time, Tag clab
tagL, Maybe a
maybeA)
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< forall a b. a -> Either a b
Left forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Time cl
time, , ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (Out cl))
outTag ClockProxy (Cl (SN m clab a b))
proxy1 Tag clab
tagL forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Maybe b
maybeB)
    Right Tag clcd
tagR -> do
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time cl
time, ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (In cl))
inTag ClockProxy (Cl (SN m clcd c b))
proxy2 Tag clcd
tagR
  Maybe (Maybe c)
maybeC <- forall (m :: Type -> Type) a b.
Monad m =>
MSF m a b -> MSF m (Maybe a) (Maybe b)
mapMaybeS forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) cl1 cl2 a b.
(Monad m, Clock m cl1, Clock m cl2, Time cl1 ~ Time cl2) =>
ClockProxy cl1
-> ClockProxy cl2
-> Time cl1
-> ResBuf m cl1 cl2 a b
-> MSF
     m (Either (Time cl1, Tag cl1, a) (Time cl2, Tag cl2)) (Maybe b)
eraseClockResBuf (forall cl. ClockProxy cl -> ClockProxy (Out cl)
outProxy ClockProxy (Cl (SN m clab a b))
proxy1) (forall cl. ClockProxy cl -> ClockProxy (In cl)
inProxy ClockProxy (Cl (SN m clcd c b))
proxy2) Time cl
initialTime ResamplingBuffer m (Out clab) (In clcd) b c
resBuf -< Maybe
  (Either
     (Time (In clcd), Tag (Out clab), b)
     (Time (In clcd), Tag (In clcd)))
resBufIn
  case Tag cl
tag of
    Left  Tag clab
_    -> do
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< forall a. Maybe a
Nothing
    Right Tag clcd
tagR -> do
      forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m clcd c b
sn2 -< (Time cl
time, Tag clcd
tagR, forall (m :: Type -> Type) a. Monad m => m (m a) -> m a
join Maybe (Maybe c)
maybeC)

eraseClockSN Time cl
initialTime (Parallel SN m cl1 a b
snL SN m cl2 a b
snR) = proc (Time cl
time, Tag cl
tag, Maybe a
maybeA) -> do
  case Tag cl
tag of
    Left  Tag cl1
tagL -> forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m cl1 a b
snL -< (Time cl
time, Tag cl1
tagL, Maybe a
maybeA)
    Right Tag cl2
tagR -> forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m cl2 a b
snR -< (Time cl
time, Tag cl2
tagR, Maybe a
maybeA)

eraseClockSN Time cl
initialTime (Postcompose SN m cl a b
sn ClSF m (Out cl) b b
clsf) =
  let
    proxy :: ClockProxy (Cl (SN m cl a b))
proxy = forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m cl a b
sn
  in proc input :: (Time cl, Tag cl, Maybe a)
input@(Time cl
time, Tag cl
tag, Maybe a
_) -> do
  Maybe b
bMaybe <- forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m cl a b
sn -< (Time cl, Tag cl, Maybe a)
input
  forall (m :: Type -> Type) a b.
Monad m =>
MSF m a b -> MSF m (Maybe a) (Maybe b)
mapMaybeS forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl) =>
ClockProxy cl
-> Time cl -> ClSF m cl a b -> MSF m (Time cl, Tag cl, a) b
eraseClockClSF (forall cl. ClockProxy cl -> ClockProxy (Out cl)
outProxy ClockProxy (Cl (SN m cl a b))
proxy) Time cl
initialTime ClSF m (Out cl) b b
clsf -< (Time cl
time, , ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (Out cl))
outTag ClockProxy (Cl (SN m cl a b))
proxy Tag cl
tag forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Maybe b
bMaybe

eraseClockSN Time cl
initialTime (Precompose ClSF m (In cl) a b
clsf SN m cl b b
sn) =
  let
    proxy :: ClockProxy (Cl (SN m cl b b))
proxy = forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m cl b b
sn
  in proc (Time cl
time, Tag cl
tag, Maybe a
aMaybe) -> do
  Maybe b
bMaybe <- forall (m :: Type -> Type) a b.
Monad m =>
MSF m a b -> MSF m (Maybe a) (Maybe b)
mapMaybeS forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl) =>
ClockProxy cl
-> Time cl -> ClSF m cl a b -> MSF m (Time cl, Tag cl, a) b
eraseClockClSF (forall cl. ClockProxy cl -> ClockProxy (In cl)
inProxy ClockProxy (Cl (SN m cl b b))
proxy) Time cl
initialTime ClSF m (In cl) a b
clsf -< (Time cl
time, , ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (In cl))
inTag ClockProxy (Cl (SN m cl b b))
proxy Tag cl
tag forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Maybe a
aMaybe
  forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m cl b b
sn -< (Time cl
time, Tag cl
tag, Maybe b
bMaybe)

eraseClockSN Time cl
initialTime (Feedback ResBuf m (Out cl) (In cl) d c
buf0 SN m cl (a, c) (b, d)
sn) =
  let
    proxy :: ClockProxy (Cl (SN m cl (a, c) (b, d)))
proxy = forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m cl (a, c) (b, d)
sn
  in forall (m :: Type -> Type) c a b.
Monad m =>
c -> MSF m (a, c) (b, c) -> MSF m a b
feedback ResBuf m (Out cl) (In cl) d c
buf0 forall a b. (a -> b) -> a -> b
$ proc ((Time cl
time, Tag cl
tag, Maybe a
aMaybe), ResBuf m (Out cl) (In cl) d c
buf) -> do
  (Maybe c
cMaybe, ResBuf m (Out cl) (In cl) d c
buf') <- case forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (In cl))
inTag ClockProxy (Cl (SN m cl (a, c) (b, d)))
proxy Tag cl
tag of
    Maybe (Tag (In cl))
Nothing -> do
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< (forall a. Maybe a
Nothing, ResBuf m (Out cl) (In cl) d c
buf)
    Just Tag (In cl)
tagIn -> do
      TimeInfo (In cl)
timeInfo <- forall (m :: Type -> Type) cl.
(Monad m, Clock m cl) =>
ClockProxy cl -> Time cl -> MSF m (Time cl, Tag cl) (TimeInfo cl)
genTimeInfo (forall cl. ClockProxy cl -> ClockProxy (In cl)
inProxy ClockProxy (Cl (SN m cl (a, c) (b, d)))
proxy) Time cl
initialTime -< (Time cl
time, Tag (In cl)
tagIn)
      (c
c, ResBuf m (Out cl) (In cl) d c
buf') <- forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> MSF m a b
arrM forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (m :: Type -> Type) cla clb a b.
ResamplingBuffer m cla clb a b
-> TimeInfo clb -> m (b, ResamplingBuffer m cla clb a b)
get -< (ResBuf m (Out cl) (In cl) d c
buf, TimeInfo (In cl)
timeInfo)
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< (forall a. a -> Maybe a
Just c
c, ResBuf m (Out cl) (In cl) d c
buf')
  Maybe (b, d)
bdMaybe <- forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m cl (a, c) (b, d)
sn -< (Time cl
time, Tag cl
tag, (, ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
aMaybe forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Maybe c
cMaybe)
  case (, ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (Out cl))
outTag ClockProxy (Cl (SN m cl (a, c) (b, d)))
proxy Tag cl
tag forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Maybe (b, d)
bdMaybe of
    Maybe (Tag (Out cl), (b, d))
Nothing -> do
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< (forall a. Maybe a
Nothing, ResBuf m (Out cl) (In cl) d c
buf')
    Just (Tag (Out cl)
tagOut, (b
b, d
d)) -> do
      TimeInfo (Out cl)
timeInfo <- forall (m :: Type -> Type) cl.
(Monad m, Clock m cl) =>
ClockProxy cl -> Time cl -> MSF m (Time cl, Tag cl) (TimeInfo cl)
genTimeInfo (forall cl. ClockProxy cl -> ClockProxy (Out cl)
outProxy ClockProxy (Cl (SN m cl (a, c) (b, d)))
proxy) Time cl
initialTime -< (Time cl
time, Tag (Out cl)
tagOut)
      ResBuf m (Out cl) (In cl) d c
buf'' <- forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> MSF m a b
arrM forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (m :: Type -> Type) cla clb a b.
ResamplingBuffer m cla clb a b
-> TimeInfo cla -> a -> m (ResamplingBuffer m cla clb a b)
put -< ((ResBuf m (Out cl) (In cl) d c
buf', TimeInfo (Out cl)
timeInfo), d
d)
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< (forall a. a -> Maybe a
Just b
b, ResBuf m (Out cl) (In cl) d c
buf'')

eraseClockSN Time cl
initialTime (FirstResampling SN m cl a b
sn ResamplingBuffer m (In cl) (Out cl) c d
buf) =
  let
    proxy :: ClockProxy (Cl (SN m cl a b))
proxy = forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m cl a b
sn
  in proc (Time cl
time, Tag cl
tag, Maybe a
acMaybe) -> do
    Maybe b
bMaybe <- forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initialTime SN m cl a b
sn -< (Time cl
time, Tag cl
tag, forall a b. (a, b) -> a
fst forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
acMaybe)
    let
      resBufInput :: Maybe
  (Either
     (Time (In cl), Tag (In cl), c) (Time (In cl), Tag (Out cl)))
resBufInput = case (forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (In cl))
inTag ClockProxy (Cl (SN m cl a b))
proxy Tag cl
tag, forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (Out cl))
outTag ClockProxy (Cl (SN m cl a b))
proxy Tag cl
tag, forall a b. (a, b) -> b
snd forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
acMaybe) of
        (Just Tag (In cl)
tagIn, Maybe (Tag (Out cl))
_, Just c
c) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left (Time cl
time, Tag (In cl)
tagIn, c
c)
        (Maybe (Tag (In cl))
_, Just Tag (Out cl)
tagOut, Maybe c
_) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. b -> Either a b
Right (Time cl
time, Tag (Out cl)
tagOut)
        (Maybe (Tag (In cl)), Maybe (Tag (Out cl)), Maybe c)
_ -> forall a. Maybe a
Nothing
    Maybe (Maybe d)
dMaybe <- forall (m :: Type -> Type) a b.
Monad m =>
MSF m a b -> MSF m (Maybe a) (Maybe b)
mapMaybeS forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) cl1 cl2 a b.
(Monad m, Clock m cl1, Clock m cl2, Time cl1 ~ Time cl2) =>
ClockProxy cl1
-> ClockProxy cl2
-> Time cl1
-> ResBuf m cl1 cl2 a b
-> MSF
     m (Either (Time cl1, Tag cl1, a) (Time cl2, Tag cl2)) (Maybe b)
eraseClockResBuf (forall cl. ClockProxy cl -> ClockProxy (In cl)
inProxy ClockProxy (Cl (SN m cl a b))
proxy) (forall cl. ClockProxy cl -> ClockProxy (Out cl)
outProxy ClockProxy (Cl (SN m cl a b))
proxy) Time cl
initialTime ResamplingBuffer m (In cl) (Out cl) c d
buf -< Maybe
  (Either
     (Time (In cl), Tag (In cl), c) (Time (In cl), Tag (Out cl)))
resBufInput
    forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA -< (,) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe b
bMaybe forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall (m :: Type -> Type) a. Monad m => m (m a) -> m a
join Maybe (Maybe d)
dMaybe

-- | Translate a resampling buffer into a monadic stream function.
--
--   The input decides whether the buffer is to accept input or has to produce output.
--   (In the latter case, only time information is provided.)
eraseClockResBuf
  :: ( Monad m
     , Clock m cl1, Clock m cl2
     , Time cl1 ~ Time cl2
     )
  => ClockProxy cl1 -> ClockProxy cl2 -> Time cl1
  -> ResBuf m cl1 cl2 a b
  -> MSF m (Either (Time cl1, Tag cl1, a) (Time cl2, Tag cl2)) (Maybe b)
eraseClockResBuf :: forall (m :: Type -> Type) cl1 cl2 a b.
(Monad m, Clock m cl1, Clock m cl2, Time cl1 ~ Time cl2) =>
ClockProxy cl1
-> ClockProxy cl2
-> Time cl1
-> ResBuf m cl1 cl2 a b
-> MSF
     m (Either (Time cl1, Tag cl1, a) (Time cl2, Tag cl2)) (Maybe b)
eraseClockResBuf ClockProxy cl1
proxy1 ClockProxy cl2
proxy2 Time cl1
initialTime ResBuf m cl1 cl2 a b
resBuf0 = forall (m :: Type -> Type) c a b.
Monad m =>
c -> MSF m (a, c) (b, c) -> MSF m a b
feedback ResBuf m cl1 cl2 a b
resBuf0 forall a b. (a -> b) -> a -> b
$ proc (Either (Time cl1, Tag cl1, a) (Time cl2, Tag cl2)
input, ResBuf m cl1 cl2 a b
resBuf) -> do
  case Either (Time cl1, Tag cl1, a) (Time cl2, Tag cl2)
input of
    Left (Time cl1
time1, Tag cl1
tag1, a
a) -> do
      TimeInfo cl1
timeInfo1 <- forall (m :: Type -> Type) cl.
(Monad m, Clock m cl) =>
ClockProxy cl -> Time cl -> MSF m (Time cl, Tag cl) (TimeInfo cl)
genTimeInfo ClockProxy cl1
proxy1 Time cl1
initialTime   -< (Time cl1
time1, Tag cl1
tag1)
      ResBuf m cl1 cl2 a b
resBuf'   <- forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> MSF m a b
arrM (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (m :: Type -> Type) cla clb a b.
ResamplingBuffer m cla clb a b
-> TimeInfo cla -> a -> m (ResamplingBuffer m cla clb a b)
put)     -< ((ResBuf m cl1 cl2 a b
resBuf, TimeInfo cl1
timeInfo1), a
a)
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA                                       -< (forall a. Maybe a
Nothing, ResBuf m cl1 cl2 a b
resBuf')
    Right (Time cl2
time2, Tag cl2
tag2) -> do
      TimeInfo cl2
timeInfo2    <- forall (m :: Type -> Type) cl.
(Monad m, Clock m cl) =>
ClockProxy cl -> Time cl -> MSF m (Time cl, Tag cl) (TimeInfo cl)
genTimeInfo ClockProxy cl2
proxy2 Time cl1
initialTime -< (Time cl2
time2, Tag cl2
tag2)
      (b
b, ResBuf m cl1 cl2 a b
resBuf') <- forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> MSF m a b
arrM (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (m :: Type -> Type) cla clb a b.
ResamplingBuffer m cla clb a b
-> TimeInfo clb -> m (b, ResamplingBuffer m cla clb a b)
get)             -< (ResBuf m cl1 cl2 a b
resBuf, TimeInfo cl2
timeInfo2)
      forall (a :: Type -> Type -> Type) b. Arrow a => a b b
returnA                                        -< (forall a. a -> Maybe a
Just b
b, ResBuf m cl1 cl2 a b
resBuf')