module Sound.SC3.UGen.MCE where
data MCE n = MCE_Unit n | MCE_Vector [n]
deriving (MCE n -> MCE n -> Bool
(MCE n -> MCE n -> Bool) -> (MCE n -> MCE n -> Bool) -> Eq (MCE n)
forall n. Eq n => MCE n -> MCE n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MCE n -> MCE n -> Bool
$c/= :: forall n. Eq n => MCE n -> MCE n -> Bool
== :: MCE n -> MCE n -> Bool
$c== :: forall n. Eq n => MCE n -> MCE n -> Bool
Eq,ReadPrec [MCE n]
ReadPrec (MCE n)
Int -> ReadS (MCE n)
ReadS [MCE n]
(Int -> ReadS (MCE n))
-> ReadS [MCE n]
-> ReadPrec (MCE n)
-> ReadPrec [MCE n]
-> Read (MCE n)
forall n. Read n => ReadPrec [MCE n]
forall n. Read n => ReadPrec (MCE n)
forall n. Read n => Int -> ReadS (MCE n)
forall n. Read n => ReadS [MCE n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MCE n]
$creadListPrec :: forall n. Read n => ReadPrec [MCE n]
readPrec :: ReadPrec (MCE n)
$creadPrec :: forall n. Read n => ReadPrec (MCE n)
readList :: ReadS [MCE n]
$creadList :: forall n. Read n => ReadS [MCE n]
readsPrec :: Int -> ReadS (MCE n)
$creadsPrec :: forall n. Read n => Int -> ReadS (MCE n)
Read,Int -> MCE n -> ShowS
[MCE n] -> ShowS
MCE n -> String
(Int -> MCE n -> ShowS)
-> (MCE n -> String) -> ([MCE n] -> ShowS) -> Show (MCE n)
forall n. Show n => Int -> MCE n -> ShowS
forall n. Show n => [MCE n] -> ShowS
forall n. Show n => MCE n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MCE n] -> ShowS
$cshowList :: forall n. Show n => [MCE n] -> ShowS
show :: MCE n -> String
$cshow :: forall n. Show n => MCE n -> String
showsPrec :: Int -> MCE n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> MCE n -> ShowS
Show)
mce_elem :: MCE t -> [t]
mce_elem :: MCE t -> [t]
mce_elem MCE t
m =
case MCE t
m of
MCE_Unit t
e -> [t
e]
MCE_Vector [t]
e -> [t]
e
mce_extend :: Int -> MCE n -> MCE n
mce_extend :: Int -> MCE n -> MCE n
mce_extend Int
n MCE n
m =
case MCE n
m of
MCE_Unit n
e -> [n] -> MCE n
forall n. [n] -> MCE n
MCE_Vector (Int -> n -> [n]
forall a. Int -> a -> [a]
replicate Int
n n
e)
MCE_Vector [n]
e -> [n] -> MCE n
forall n. [n] -> MCE n
MCE_Vector (Int -> [n] -> [n]
forall a. Int -> [a] -> [a]
take Int
n ([n] -> [n]
forall a. [a] -> [a]
cycle [n]
e))
mce_map :: (a -> b) -> MCE a -> MCE b
mce_map :: (a -> b) -> MCE a -> MCE b
mce_map a -> b
f MCE a
m =
case MCE a
m of
MCE_Unit a
e -> b -> MCE b
forall n. n -> MCE n
MCE_Unit (a -> b
f a
e)
MCE_Vector [a]
e -> [b] -> MCE b
forall n. [n] -> MCE n
MCE_Vector ((a -> b) -> [a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map a -> b
f [a]
e)
mce_binop :: (a -> b -> c) -> MCE a -> MCE b -> MCE c
mce_binop :: (a -> b -> c) -> MCE a -> MCE b -> MCE c
mce_binop a -> b -> c
f MCE a
m1 MCE b
m2 =
case (MCE a
m1,MCE b
m2) of
(MCE_Unit a
e1,MCE_Unit b
e2) -> c -> MCE c
forall n. n -> MCE n
MCE_Unit (a -> b -> c
f a
e1 b
e2)
(MCE_Unit a
e1,MCE_Vector [b]
e2) -> [c] -> MCE c
forall n. [n] -> MCE n
MCE_Vector ((b -> c) -> [b] -> [c]
forall a b. (a -> b) -> [a] -> [b]
map (a -> b -> c
f a
e1) [b]
e2)
(MCE_Vector [a]
e1,MCE_Unit b
e2) -> [c] -> MCE c
forall n. [n] -> MCE n
MCE_Vector ((a -> c) -> [a] -> [c]
forall a b. (a -> b) -> [a] -> [b]
map (a -> b -> c
`f` b
e2) [a]
e1)
(MCE_Vector [a]
e1,MCE_Vector [b]
e2) ->
let n :: Int
n = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
e1) ([b] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [b]
e2)
ext :: [a] -> [a]
ext = Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
n ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
cycle
in [c] -> MCE c
forall n. [n] -> MCE n
MCE_Vector ((a -> b -> c) -> [a] -> [b] -> [c]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> b -> c
f ([a] -> [a]
forall a. [a] -> [a]
ext [a]
e1) ([b] -> [b]
forall a. [a] -> [a]
ext [b]
e2))
instance Num n => Num (MCE n) where
+ :: MCE n -> MCE n -> MCE n
(+) = (n -> n -> n) -> MCE n -> MCE n -> MCE n
forall a b c. (a -> b -> c) -> MCE a -> MCE b -> MCE c
mce_binop n -> n -> n
forall a. Num a => a -> a -> a
(+)
(-) = (n -> n -> n) -> MCE n -> MCE n -> MCE n
forall a b c. (a -> b -> c) -> MCE a -> MCE b -> MCE c
mce_binop (-)
* :: MCE n -> MCE n -> MCE n
(*) = (n -> n -> n) -> MCE n -> MCE n -> MCE n
forall a b c. (a -> b -> c) -> MCE a -> MCE b -> MCE c
mce_binop n -> n -> n
forall a. Num a => a -> a -> a
(*)
abs :: MCE n -> MCE n
abs = (n -> n) -> MCE n -> MCE n
forall a b. (a -> b) -> MCE a -> MCE b
mce_map n -> n
forall a. Num a => a -> a
abs
negate :: MCE n -> MCE n
negate = (n -> n) -> MCE n -> MCE n
forall a b. (a -> b) -> MCE a -> MCE b
mce_map n -> n
forall a. Num a => a -> a
negate
signum :: MCE n -> MCE n
signum = (n -> n) -> MCE n -> MCE n
forall a b. (a -> b) -> MCE a -> MCE b
mce_map n -> n
forall a. Num a => a -> a
signum
fromInteger :: Integer -> MCE n
fromInteger = n -> MCE n
forall n. n -> MCE n
MCE_Unit (n -> MCE n) -> (Integer -> n) -> Integer -> MCE n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> n
forall a. Num a => Integer -> a
fromInteger
instance Fractional n => Fractional (MCE n) where
/ :: MCE n -> MCE n -> MCE n
(/) = (n -> n -> n) -> MCE n -> MCE n -> MCE n
forall a b c. (a -> b -> c) -> MCE a -> MCE b -> MCE c
mce_binop n -> n -> n
forall a. Fractional a => a -> a -> a
(/)
fromRational :: Rational -> MCE n
fromRational = n -> MCE n
forall n. n -> MCE n
MCE_Unit (n -> MCE n) -> (Rational -> n) -> Rational -> MCE n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> n
forall a. Fractional a => Rational -> a
fromRational