synthesizer-core-0.9: src/Synthesizer/State/Storable.hs
{- |
Variants of functions from "Synthesizer.State.Signal"
that use a 'StorableVector' for interim storage.
-}
module Synthesizer.State.Storable where
import Synthesizer.State.Signal (T, fromStorableSignal, toStorableSignal)
import qualified Synthesizer.Storable.Signal as SigSt
import Foreign.Storable (Storable)
import Data.Tuple.HT (mapFst, mapPair)
{-# INLINE viewR #-}
viewR :: Storable a => T a -> Maybe (T a, a)
viewR = viewRSize SigSt.defaultChunkSize
{-# INLINE viewRSize #-}
viewRSize :: Storable a => SigSt.ChunkSize -> T a -> Maybe (T a, a)
viewRSize size =
fmap (mapFst fromStorableSignal) . SigSt.viewR . toStorableSignal size
{-# INLINE switchR #-}
switchR :: Storable a => b -> (T a -> a -> b) -> T a -> b
switchR n j =
maybe n (uncurry j) . viewR
{-# INLINE splitAt #-}
splitAt :: Storable a => Int -> T a -> (T a, T a)
splitAt = splitAtSize SigSt.defaultChunkSize
{-# INLINE splitAtSize #-}
splitAtSize :: Storable a => SigSt.ChunkSize -> Int -> T a -> (T a, T a)
splitAtSize size n =
mapPair (fromStorableSignal, fromStorableSignal) .
SigSt.splitAt n .
toStorableSignal size
{-# INLINE span #-}
span :: Storable a => (a -> Bool) -> T a -> (T a, T a)
span = spanSize SigSt.defaultChunkSize
{-# INLINE spanSize #-}
spanSize :: Storable a => SigSt.ChunkSize -> (a -> Bool) -> T a -> (T a, T a)
spanSize size p =
mapPair (fromStorableSignal, fromStorableSignal) .
SigSt.span p .
toStorableSignal size
infixr 5 `append`
{-# INLINE append #-}
append :: Storable a =>
T a -> T a -> T a
append = appendSize SigSt.defaultChunkSize
{-# INLINE appendSize #-}
appendSize :: Storable a => SigSt.ChunkSize -> T a -> T a -> T a
appendSize size xs ys =
fromStorableSignal $
SigSt.append
(toStorableSignal size xs)
(toStorableSignal size ys)
{-# INLINE concat #-}
concat :: Storable a => [T a] -> T a
concat = concatSize SigSt.defaultChunkSize
{-# INLINE concatSize #-}
concatSize :: Storable a => SigSt.ChunkSize -> [T a] -> T a
concatSize size =
fromStorableSignal . SigSt.concat . map (toStorableSignal size)
{-# INLINE reverse #-}
reverse :: Storable a =>
T a -> T a
reverse = reverseSize SigSt.defaultChunkSize
{-# INLINE reverseSize #-}
reverseSize :: Storable a => SigSt.ChunkSize -> T a -> T a
reverseSize size =
fromStorableSignal . SigSt.reverse . toStorableSignal size