-- | These UGens only run at audio rate ('AR')
-- 
--   They also can cause CPU spikes when their parameters are changed!

{-# LANGUAGE DataKinds #-}

{-# LANGUAGE NoIncoherentInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE NoUndecidableInstances #-}

module Vivid.UGens.Filters.BEQSuite (
     bAllpass
   , bBandPass
   , bBandStop
   , bHiPass
---   , bHiPass4
   , bHiShelf
   , bLowPass
   , bLowPass4
   , bLowShelf
   , bPeakEQ
   ) where

import Vivid.SC.SynthDef.Types (CalculationRate(..))
import Vivid.SynthDef
import Vivid.SynthDef.FromUA
import Vivid.UGens.Args

import Vivid.UGens.Algebraic
import Vivid.UGens.Filters.Linear (sos)
import Vivid.UGens.Info (sampleRate, sampleDur)

-- import qualified Data.List as L
-- import Data.Maybe
import Data.Proxy

bAllpass :: (Args '["in"] '["freq", "rq"] a) => a -> SDBody a Signal
bAllpass :: a -> SDBody a Signal
bAllpass = String
-> CalculationRate
-> Vs '["in", "freq", "rq"]
-> (UA "freq" (SDBodyArgs a), UA "rq" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BAllPass" CalculationRate
AR
   (Vs '["in", "freq", "rq"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "rq"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "rq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "rq" as
rq_ (Float
1::Float))

-- | Band-pass filter
bBandPass :: (Args '["in"] '["freq", "bw"] a) => a -> SDBody a Signal
bBandPass :: a -> SDBody a Signal
bBandPass = String
-> CalculationRate
-> Vs '["in", "freq", "bw"]
-> (UA "freq" (SDBodyArgs a), UA "bw" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BBandPass" CalculationRate
AR
   (Vs '["in", "freq", "bw"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "bw"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "bw" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "bw" as
bw_ (Float
1::Float))

bBandStop :: (Args '["in"] '["freq", "bw"] a) => a -> SDBody a Signal
bBandStop :: a -> SDBody a Signal
bBandStop = String
-> CalculationRate
-> Vs '["in", "freq", "bw"]
-> (UA "freq" (SDBodyArgs a), UA "bw" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BBandStop" CalculationRate
AR
   (Vs '["in", "freq", "bw"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "bw"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "bw" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "bw" as
bw_ (Float
1::Float))

-- | This is only in AR
bHiPass :: (Args '["in"] '["freq", "rq"] a) => a -> SDBody a Signal
bHiPass :: a -> SDBody a Signal
bHiPass = String
-> CalculationRate
-> Vs '["in", "freq", "rq"]
-> (UA "freq" (SDBodyArgs a), UA "rq" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BHiPass" CalculationRate
AR
   (Vs '["in", "freq", "rq"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "rq"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "rq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "rq" as
rq_ (Float
1::Float))

-- bHiPass4 :: (Args '["in"] '["freq", "rq"] a) => a -> SDBody a Signal
--- bHiPass4 ::
--- bHiPass4 =

bHiShelf :: (Args '["in"] '["freq", "rs", "db"] a) => a -> SDBody a Signal
bHiShelf :: a -> SDBody a Signal
bHiShelf = String
-> CalculationRate
-> Vs '["in", "freq", "rs", "db"]
-> (UA "freq" (SDBodyArgs a), UA "rs" (SDBodyArgs a),
    UA "db" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BHiShelf" CalculationRate
AR
   (Vs '["in", "freq", "rs", "db"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "rs", "db"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "rs" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "rs" as
rs_ (Float
1::Float), Float -> UA "db" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "db" as
db_ (Float
0::Float))

bLowPass :: (Args '["in"] '["freq", "rq"] a) => a -> SDBody a Signal
bLowPass :: a -> SDBody a Signal
bLowPass = String
-> CalculationRate
-> Vs '["in", "freq", "rq"]
-> (UA "freq" (SDBodyArgs a), UA "rq" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BLowPass" CalculationRate
AR
   (Vs '["in", "freq", "rq"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "rq"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "rq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "rq" as
rq_ (Float
1::Float))

-- Checked this w/ 2 different inputs:
bLowPass4 :: (Args '["in"] '["freq","rq"] a) => a -> SDBody a Signal
bLowPass4 :: a -> SDBody a Signal
bLowPass4 a
as = do
   Signal
freq <- Float -> a -> Proxy "freq" -> SDBody a Signal
forall as (aToLookUp :: Symbol) defaultVal (proxy :: Symbol -> *).
(FromUA as, KnownSymbol aToLookUp,
 ToSig defaultVal (SDBodyArgs as)) =>
defaultVal -> as -> proxy aToLookUp -> SDBody as Signal
uaArgValWDefault (Float
1200::Float) a
as (Proxy "freq"
forall k (t :: k). Proxy t
Proxy::Proxy "freq")
   Signal
rq <- Float -> a -> Proxy "rq" -> SDBody a Signal
forall as (aToLookUp :: Symbol) defaultVal (proxy :: Symbol -> *).
(FromUA as, KnownSymbol aToLookUp,
 ToSig defaultVal (SDBodyArgs as)) =>
defaultVal -> as -> proxy aToLookUp -> SDBody as Signal
uaArgValWDefault (Float
1::Float) a
as (Proxy "rq"
forall k (t :: k). Proxy t
Proxy::Proxy "rq")
   Signal
in' <- a
as a -> Proxy "in" -> SDBody a Signal
forall as (aToLookUp :: Symbol) (proxy :: Symbol -> *).
(FromUA as, Elem aToLookUp (UAsArgs as), KnownSymbol aToLookUp) =>
as -> proxy aToLookUp -> SDBody as Signal
`uaArgVal` (Proxy "in"
forall k (t :: k). Proxy t
Proxy::Proxy "in")

   -- We don't actually use 'sRate' -- why?:
   Signal
_sRate <- SDBody a Signal
forall (a :: [Symbol]). SDBody' a Signal
sampleRate
   Signal
sDur <- SDBody a Signal
forall (a :: [Symbol]). SDBody' a Signal
sampleDur
   Signal
four <- (Float -> Signal
Constant (Float -> Signal) -> Float -> Signal
forall a b. (a -> b) -> a -> b
$ Float
2Float -> Float -> Float
forall a. Num a => a -> a -> a
*Float
forall a. Floating a => a
pi)Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~*Signal
sDurSDBody a Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~*Signal
freq
   Signal
five <- UnaryOp -> Signal -> SDBody a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
uOp UnaryOp
Cos Signal
four
   Signal
six <- {- 1 ~- five -} (Float -> Signal
Constant Float
1) Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~- Signal
five
   Signal
seven <- Signal
six Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* (Float -> Signal
Constant Float
0.5)
   Signal
eight <- Signal
five Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* (Float -> Signal
Constant Float
2)
   Signal
nine <- UnaryOp -> Signal -> SDBody a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
uOp UnaryOp
Sin Signal
four
   Signal
ten <- Signal
nine Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* (Float -> Signal
Constant Float
0.5)
   Signal
eleven <- Signal
ten Signal -> SDBody a Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* UnaryOp -> Signal -> SDBody a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
uOp UnaryOp
Sqrt Signal
rq
   Signal
twelve <- Float -> Signal
Constant Float
1 Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~+ Signal
eleven
   Signal
thirteen <- UnaryOp -> Signal -> SDBody a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
uOp UnaryOp
Recip Signal
twelve
   Signal
fourteen <- Signal
seven Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* Signal
thirteen
   Signal
fifteen <- Signal
six Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* Signal
thirteen
   Signal
sixteen <- Signal
eight Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* Signal
thirteen
   Signal
seventeen <- UnaryOp -> Signal -> SDBody a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
uOp UnaryOp
Neg Signal
thirteen
   Signal
eighteen <- Float -> Signal
Constant Float
1 Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~- Signal
eleven
   Signal
nineteen <- Signal
eighteen Signal -> Signal -> SDBody a Signal
forall i0 (a :: [Symbol]) i1.
(ToSig i0 a, ToSig i1 a) =>
i0 -> i1 -> SDBody' a Signal
~* Signal
seventeen
   Signal
twenty <- (UA "in" (SDBodyArgs a), UA "a0" (SDBodyArgs a),
 UA "a1" (SDBodyArgs a), UA "a2" (SDBodyArgs a),
 UA "b1" (SDBodyArgs a), UA "b2" (SDBodyArgs a))
-> SDBody
     (UA "in" (SDBodyArgs a), UA "a0" (SDBodyArgs a),
      UA "a1" (SDBodyArgs a), UA "a2" (SDBodyArgs a),
      UA "b1" (SDBodyArgs a), UA "b2" (SDBodyArgs a))
     Signal
forall a.
Args '["in"] '["a0", "a1", "a2", "b1", "b2"] a =>
a -> SDBody a Signal
sos (Signal -> UA "in" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "in" as
in_ Signal
in', Signal -> UA "a0" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "a0" as
a0_ Signal
fourteen, Signal -> UA "a1" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "a1" as
a1_ Signal
fifteen, Signal -> UA "a2" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "a2" as
a2_ Signal
fourteen, Signal -> UA "b1" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "b1" as
b1_ Signal
sixteen, Signal -> UA "b2" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "b2" as
b2_ Signal
nineteen)
   Signal
twentyOne <- (UA "in" (SDBodyArgs a), UA "a0" (SDBodyArgs a),
 UA "a1" (SDBodyArgs a), UA "a2" (SDBodyArgs a),
 UA "b1" (SDBodyArgs a), UA "b2" (SDBodyArgs a))
-> SDBody
     (UA "in" (SDBodyArgs a), UA "a0" (SDBodyArgs a),
      UA "a1" (SDBodyArgs a), UA "a2" (SDBodyArgs a),
      UA "b1" (SDBodyArgs a), UA "b2" (SDBodyArgs a))
     Signal
forall a.
Args '["in"] '["a0", "a1", "a2", "b1", "b2"] a =>
a -> SDBody a Signal
sos (Signal -> UA "in" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "in" as
in_ Signal
twenty, Signal -> UA "a0" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "a0" as
a0_ Signal
fourteen, Signal -> UA "a1" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "a1" as
a1_ Signal
fifteen, Signal -> UA "a2" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "a2" as
a2_ Signal
fourteen, Signal -> UA "b1" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "b1" as
b1_ Signal
sixteen, Signal -> UA "b2" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "b2" as
b2_ Signal
nineteen)
   Signal -> SDBody a Signal
forall (m :: * -> *) a. Monad m => a -> m a
return Signal
twentyOne

bLowShelf :: (Args '["in"] '["freq", "rs", "db"] a) => a -> SDBody a Signal
bLowShelf :: a -> SDBody a Signal
bLowShelf = String
-> CalculationRate
-> Vs '["in", "freq", "rs", "db"]
-> (UA "freq" (SDBodyArgs a), UA "rs" (SDBodyArgs a),
    UA "db" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BLowShelf" CalculationRate
AR
   (Vs '["in", "freq", "rs", "db"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "rs", "db"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "rs" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "rs" as
rs_ (Float
1::Float), Float -> UA "db" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "db" as
db_ (Float
0::Float))


bPeakEQ :: (Args '["in"] '["freq", "rq", "db"] a) => a -> SDBody a Signal
bPeakEQ :: a -> SDBody a Signal
bPeakEQ = String
-> CalculationRate
-> Vs '["in", "freq", "rq", "db"]
-> (UA "freq" (SDBodyArgs a), UA "rq" (SDBodyArgs a),
    UA "db" (SDBodyArgs a))
-> a
-> SDBody a Signal
forall (tags :: [Symbol]) optional userSupplied (args :: [Symbol]).
(GetSymbolVals (Vs tags), FromUA optional, FromUA userSupplied,
 SDBodyArgs optional ~ SDBodyArgs userSupplied,
 SDBodyArgs optional ~ args) =>
String
-> CalculationRate
-> Vs tags
-> optional
-> userSupplied
-> SDBody' args Signal
makeUGen
   String
"BPeakEQ" CalculationRate
AR
   (Vs '["in", "freq", "rq", "db"]
forall (a :: [Symbol]). Vs a
Vs::Vs '["in", "freq", "rq", "db"])
   (Float -> UA "freq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "freq" as
freq_ (Float
1200::Float), Float -> UA "rq" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "rq" as
rq_ (Float
1::Float), Float -> UA "db" (SDBodyArgs a)
forall s (as :: [Symbol]). ToSig s as => s -> UA "db" as
db_ (Float
0::Float))