{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoIncoherentInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE NoUndecidableInstances #-}
module Vivid.UGens.Maths (
clip
, inRange
, leastChange
, linExp
, mostChange
, mulAdd
) where
import Vivid.SC.SynthDef.Types (CalculationRate(..))
import Vivid.SynthDef
import Vivid.SynthDef.FromUA
import Vivid.UGens.Args
import qualified Data.ByteString.UTF8 as UTF8 (fromString)
import Data.Proxy
clip :: (Args '["in"] '["lo", "hi"] a) => a -> SDBody a Signal
clip = makeUGen
"Clip" AR
(Vs::Vs '["in","lo","hi"])
(lo_ (0::Float), hi_ (1::Float))
inRange :: (Args '["in"] '["lo", "hi"] a) => a -> SDBody a Signal
inRange = makeUGen
"InRange" AR
(Vs::Vs '["in", "lo", "hi"])
(lo_ (0::Float), hi_ (1::Float))
leastChange :: (ToSig s0 as, ToSig s1 as) => s0 -> s1 -> SDBody' as Signal
leastChange = leastOrMostChange "LeastChange"
leastOrMostChange :: (ToSig s0 as, ToSig s1 as) => String -> s0 -> s1 -> SDBody' as Signal
leastOrMostChange sdName s0 s1 = do
s0' <- toSig s0
s1' <- toSig s1
calcRate <- (maximum::Ord a=>[a]->a) <$> sequence (map getCalcRate [s0', s1'])
addUGen $ UGen (UGName_S . UTF8.fromString $ sdName) calcRate [s0',s1'] 1
linExp :: Args '["in"] '["srclo", "srchi", "dstlo", "dsthi"] a => a -> SDBody a Signal
linExp as = do
in' <- as `uaArgVal` (Proxy::Proxy "in")
getCalcRate in' >>= \case
AR -> successGraph AR
KR -> successGraph KR
_ -> error "linExp: 'in' value must be at AR/KR"
where
successGraph calcRate = ($ as) $ makeUGen
"LinExp" calcRate
(Vs::Vs '["in", "srclo", "srchi", "dstlo", "dsthi"])
(srclo_ (0::Float), srchi_ (1::Float), dstlo_ (1::Float), dsthi_ (2::Float))
mostChange :: (ToSig s0 as, ToSig s1 as) => s0 -> s1 -> SDBody' as Signal
mostChange = leastOrMostChange "MostChange"
mulAdd :: (Args '["in"] '["mul", "add"] a) => a -> SDBody a Signal
mulAdd = makeUGen
"MulAdd" AR
(Vs::Vs '["in", "mul", "add"])
(mul_ (1::Float), add_ (0::Float))