{-# OPTIONS -fno-implicit-prelude #-}
{- |
Copyright   :  (c) Henning Thielemann 2008
License     :  GPL

Maintainer  :  synthesizer@henning-thielemann.de
Stability   :  provisional
Portability :  requires multi-parameter type classes
-}
module Synthesizer.Dimensional.Rate.Cut (
     take, drop,
   ) where

import qualified Synthesizer.Dimensional.Abstraction.Homogeneous as Hom

import qualified Synthesizer.Dimensional.RatePhantom as RP

import qualified Synthesizer.Dimensional.Process as Proc
-- import qualified Synthesizer.Dimensional.Rate as Rate

-- import Synthesizer.Dimensional.Process ((.:), (.^), )

import qualified Synthesizer.Dimensional.RateAmplitude.Signal as SigA
import qualified Synthesizer.State.Signal as Sig

import Synthesizer.Dimensional.RateAmplitude.Signal
   (toTimeScalar, )

import qualified Number.DimensionTerm        as DN
import qualified Algebra.DimensionTerm       as Dim

-- import qualified Number.NonNegative     as NonNeg

import qualified Algebra.RealField      as RealField
-- import qualified Algebra.Field          as Field


import NumericPrelude hiding (negate)
-- import PreludeBase as P
import Prelude hiding (take, drop, )


{-# INLINE take #-}
take :: (Hom.C sig, RealField.C t, Dim.C u) =>
   DN.T u t -> Proc.T s u t (RP.T s sig y -> RP.T s sig y)
take t' =
   do t <- toTimeScalar t'
      return $ Hom.processSamples (Sig.take (RealField.round t))

{-# INLINE drop #-}
drop :: (Hom.C sig, RealField.C t, Dim.C u) =>
   DN.T u t -> Proc.T s u t (RP.T s sig y -> RP.T s sig y)
drop t' =
   do t <- toTimeScalar t'
      return $ Hom.processSamples (Sig.drop (RealField.round t))