{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies, NoMonoLocalBinds #-}
{-# LANGUAGE NoIncoherentInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE NoUndecidableInstances #-}
module Vivid.UGens.Algebraic (
(~+)
, (~-)
, (~*)
, (~**)
, (~/)
, binaryOp
, biOp
, unaryOp
, uOp
, midiCPS
, cpsMIDI
, abs'
, neg
, tanh'
, clip2
, xor
) where
import Vivid.SynthDef
import Prelude
infixl 7 ~*
(~*) :: (ToSig i0 a, ToSig i1 a) => i0 -> i1 -> SDBody' a Signal
~* :: i0 -> i1 -> SDBody' a Signal
(~*) = BinaryOp -> i0 -> i1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp BinaryOp
Mul
infixr 8 ~**
(~**) :: (ToSig i0 a, ToSig i1 a) => i0 -> i1 -> SDBody' a Signal
~** :: i0 -> i1 -> SDBody' a Signal
(~**) = BinaryOp -> i0 -> i1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp BinaryOp
Pow
infixl 6 ~+
(~+) :: (ToSig i0 a, ToSig i1 a) => i0 -> i1 -> SDBody' a Signal
~+ :: i0 -> i1 -> SDBody' a Signal
(~+) = BinaryOp -> i0 -> i1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp BinaryOp
Add
infixl 7 ~/
(~/) :: (ToSig i0 a, ToSig i1 a) => i0 -> i1 -> SDBody' a Signal
~/ :: i0 -> i1 -> SDBody' a Signal
(~/) = BinaryOp -> i0 -> i1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp BinaryOp
FDiv
infixl 6 ~-
(~-) :: (ToSig i0 a, ToSig i1 a) => i0 -> i1 -> SDBody' a Signal
~- :: i0 -> i1 -> SDBody' a Signal
(~-) = BinaryOp -> i0 -> i1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp BinaryOp
Sub
binaryOp :: (ToSig s0 a, ToSig s1 a) => BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp :: BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp BinaryOp
theBiOp s0
s0 s1
s1 = do
Signal
s0' <- s0 -> SDBody' a Signal
forall s (args :: [Symbol]).
ToSig s args =>
s -> SDBody' args Signal
toSig s0
s0
Signal
s1' <- s1 -> SDBody' a Signal
forall s (args :: [Symbol]).
ToSig s args =>
s -> SDBody' args Signal
toSig s1
s1
CalculationRate
calcRate <- CalculationRate -> CalculationRate -> CalculationRate
forall a. Ord a => a -> a -> a
max (CalculationRate -> CalculationRate -> CalculationRate)
-> StateT ([Int], SynthDef a, VarSet a) Identity CalculationRate
-> StateT
([Int], SynthDef a, VarSet a)
Identity
(CalculationRate -> CalculationRate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal
-> StateT ([Int], SynthDef a, VarSet a) Identity CalculationRate
forall (args :: [Symbol]). Signal -> SDBody' args CalculationRate
getCalcRate Signal
s0' StateT
([Int], SynthDef a, VarSet a)
Identity
(CalculationRate -> CalculationRate)
-> StateT ([Int], SynthDef a, VarSet a) Identity CalculationRate
-> StateT ([Int], SynthDef a, VarSet a) Identity CalculationRate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Signal
-> StateT ([Int], SynthDef a, VarSet a) Identity CalculationRate
forall (args :: [Symbol]). Signal -> SDBody' args CalculationRate
getCalcRate Signal
s1'
let sigs :: [Signal]
sigs = [Signal
s0', Signal
s1']
UGen -> SDBody' a Signal
forall (args :: [Symbol]). UGen -> SDBody' args Signal
addUGen (UGen -> SDBody' a Signal) -> UGen -> SDBody' a Signal
forall a b. (a -> b) -> a -> b
$ UGenName -> CalculationRate -> [Signal] -> Int -> UGen
UGen (BinaryOp -> UGenName
UGName_B BinaryOp
theBiOp) CalculationRate
calcRate [Signal]
sigs Int
1
biOp :: (ToSig s0 a, ToSig s1 a) => BinaryOp -> s0 -> s1 -> SDBody' a Signal
biOp :: BinaryOp -> s0 -> s1 -> SDBody' a Signal
biOp = BinaryOp -> s0 -> s1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
binaryOp
unaryOp :: (ToSig sig a) => UnaryOp -> sig -> SDBody' a Signal
unaryOp :: UnaryOp -> sig -> SDBody' a Signal
unaryOp UnaryOp
theUOp sig
sig = do
Signal
sig' <- sig -> SDBody' a Signal
forall s (args :: [Symbol]).
ToSig s args =>
s -> SDBody' args Signal
toSig sig
sig
CalculationRate
calcRate <- Signal -> SDBody' a CalculationRate
forall (args :: [Symbol]). Signal -> SDBody' args CalculationRate
getCalcRate Signal
sig'
UGen -> SDBody' a Signal
forall (args :: [Symbol]). UGen -> SDBody' args Signal
addUGen (UGen -> SDBody' a Signal) -> UGen -> SDBody' a Signal
forall a b. (a -> b) -> a -> b
$ UGenName -> CalculationRate -> [Signal] -> Int -> UGen
UGen (UnaryOp -> UGenName
UGName_U UnaryOp
theUOp) CalculationRate
calcRate [Signal
sig'] Int
1
uOp :: (ToSig sig a) => UnaryOp -> sig -> SDBody' a Signal
uOp :: UnaryOp -> sig -> SDBody' a Signal
uOp = UnaryOp -> sig -> SDBody' a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
unaryOp
midiCPS :: (ToSig i a) => i -> SDBody' a Signal
midiCPS :: i -> SDBody' a Signal
midiCPS = UnaryOp -> i -> SDBody' a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
unaryOp UnaryOp
MIDICPS
cpsMIDI :: (ToSig i a) => i -> SDBody' a Signal
cpsMIDI :: i -> SDBody' a Signal
cpsMIDI = UnaryOp -> i -> SDBody' a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
unaryOp UnaryOp
CPSMIDI
abs' :: (ToSig i a) => i -> SDBody' a Signal
abs' :: i -> SDBody' a Signal
abs' = UnaryOp -> i -> SDBody' a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
unaryOp UnaryOp
Abs
neg :: (ToSig i a) => i -> SDBody' a Signal
neg :: i -> SDBody' a Signal
neg = UnaryOp -> i -> SDBody' a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
unaryOp UnaryOp
Neg
tanh' :: ToSig i a => i -> SDBody' a Signal
tanh' :: i -> SDBody' a Signal
tanh' i
i = UnaryOp -> i -> SDBody' a Signal
forall sig (a :: [Symbol]).
ToSig sig a =>
UnaryOp -> sig -> SDBody' a Signal
uOp UnaryOp
TanH i
i
clip2 :: (ToSig s0 a, ToSig s1 a) => s0 -> s1 -> SDBody' a Signal
clip2 :: s0 -> s1 -> SDBody' a Signal
clip2 = BinaryOp -> s0 -> s1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
biOp BinaryOp
Clip2
xor :: (ToSig s0 a, ToSig s1 a) => s0 -> s1 -> SDBody' a Signal
xor :: s0 -> s1 -> SDBody' a Signal
xor = BinaryOp -> s0 -> s1 -> SDBody' a Signal
forall s0 (a :: [Symbol]) s1.
(ToSig s0 a, ToSig s1 a) =>
BinaryOp -> s0 -> s1 -> SDBody' a Signal
biOp BinaryOp
BitXor