-- | Control
module Sound.Sc3.Ugen.Control where

import Text.Printf {- base -}

import Sound.Sc3.Common.Rate {- hsc3 -}
import Sound.Sc3.Ugen.Brackets {- hsc3 -}

-- * Control Group

{- | Controls may form part of a control group.
There are presently three types of groups.
Ranges controls have two values (minima, maxima) and are ordinarily drawn as a range slider.
Array controls have n values [e1 .. eN] and are ordinarily drawn as a multislider.
Xy controls have two values (x, y) and are ordinarily drawn as a two dimensional slider.
-}
data Control_Group
  = Control_Range
  | Control_Array Int
  | Control_Xy
  deriving (Eq Control_Group
Control_Group -> Control_Group -> Bool
Control_Group -> Control_Group -> Ordering
Control_Group -> Control_Group -> Control_Group
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Control_Group -> Control_Group -> Control_Group
$cmin :: Control_Group -> Control_Group -> Control_Group
max :: Control_Group -> Control_Group -> Control_Group
$cmax :: Control_Group -> Control_Group -> Control_Group
>= :: Control_Group -> Control_Group -> Bool
$c>= :: Control_Group -> Control_Group -> Bool
> :: Control_Group -> Control_Group -> Bool
$c> :: Control_Group -> Control_Group -> Bool
<= :: Control_Group -> Control_Group -> Bool
$c<= :: Control_Group -> Control_Group -> Bool
< :: Control_Group -> Control_Group -> Bool
$c< :: Control_Group -> Control_Group -> Bool
compare :: Control_Group -> Control_Group -> Ordering
$ccompare :: Control_Group -> Control_Group -> Ordering
Ord, Control_Group -> Control_Group -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Control_Group -> Control_Group -> Bool
$c/= :: Control_Group -> Control_Group -> Bool
== :: Control_Group -> Control_Group -> Bool
$c== :: Control_Group -> Control_Group -> Bool
Eq, ReadPrec [Control_Group]
ReadPrec Control_Group
Int -> ReadS Control_Group
ReadS [Control_Group]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Control_Group]
$creadListPrec :: ReadPrec [Control_Group]
readPrec :: ReadPrec Control_Group
$creadPrec :: ReadPrec Control_Group
readList :: ReadS [Control_Group]
$creadList :: ReadS [Control_Group]
readsPrec :: Int -> ReadS Control_Group
$creadsPrec :: Int -> ReadS Control_Group
Read, Int -> Control_Group -> ShowS
[Control_Group] -> ShowS
Control_Group -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Control_Group] -> ShowS
$cshowList :: [Control_Group] -> ShowS
show :: Control_Group -> String
$cshow :: Control_Group -> String
showsPrec :: Int -> Control_Group -> ShowS
$cshowsPrec :: Int -> Control_Group -> ShowS
Show)

-- | The number of elements in a control group.
control_group_degree :: Control_Group -> Int
control_group_degree :: Control_Group -> Int
control_group_degree Control_Group
grp =
  case Control_Group
grp of
    Control_Group
Control_Range -> Int
2
    Control_Array Int
n -> Int
n
    Control_Group
Control_Xy -> Int
2

{- | Grouped controls have names that have equal prefixes and identifying suffixes.
     Range controls have two elements, minima and maxima, suffixes are [ and ].
     Array controls have n elements and have zero-indexed numerical suffixes.
     Xy controls have two elements, X and Y coordinates, suffixes are X and Y.
-}
control_group_suffixes :: Control_Group -> [String]
control_group_suffixes :: Control_Group -> [String]
control_group_suffixes Control_Group
grp =
  case Control_Group
grp of
    Control_Group
Control_Range -> [String
"[",String
"]"]
    Control_Array Int
n -> forall a b. (a -> b) -> [a] -> [b]
map (forall r. PrintfType r => String -> r
printf String
"%02d") [Int
0 .. Int
n forall a. Num a => a -> a -> a
- Int
1]
    Control_Group
Control_Xy -> [String
"X",String
"Y"]

-- * Control Meta

-- | Control meta-data.
data Control_Meta n =
    Control_Meta
    {forall n. Control_Meta n -> n
ctl_min :: n -- ^ Minimum
    ,forall n. Control_Meta n -> n
ctl_max :: n -- ^ Maximum
    ,forall n. Control_Meta n -> String
ctl_warp :: String -- ^ @(0,1)@ @(min,max)@ transfer function.
    ,forall n. Control_Meta n -> n
ctl_step :: n -- ^ The step to increment & decrement by.
    ,forall n. Control_Meta n -> String
ctl_units :: String -- ^ Unit of measure (ie hz, ms etc.).
    ,forall n. Control_Meta n -> Maybe Control_Group
controlGroup :: Maybe Control_Group} -- ^ Control group.
  deriving (Control_Meta n -> Control_Meta n -> Bool
Control_Meta n -> Control_Meta n -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {n}. Ord n => Eq (Control_Meta n)
forall n. Ord n => Control_Meta n -> Control_Meta n -> Bool
forall n. Ord n => Control_Meta n -> Control_Meta n -> Ordering
forall n.
Ord n =>
Control_Meta n -> Control_Meta n -> Control_Meta n
min :: Control_Meta n -> Control_Meta n -> Control_Meta n
$cmin :: forall n.
Ord n =>
Control_Meta n -> Control_Meta n -> Control_Meta n
max :: Control_Meta n -> Control_Meta n -> Control_Meta n
$cmax :: forall n.
Ord n =>
Control_Meta n -> Control_Meta n -> Control_Meta n
>= :: Control_Meta n -> Control_Meta n -> Bool
$c>= :: forall n. Ord n => Control_Meta n -> Control_Meta n -> Bool
> :: Control_Meta n -> Control_Meta n -> Bool
$c> :: forall n. Ord n => Control_Meta n -> Control_Meta n -> Bool
<= :: Control_Meta n -> Control_Meta n -> Bool
$c<= :: forall n. Ord n => Control_Meta n -> Control_Meta n -> Bool
< :: Control_Meta n -> Control_Meta n -> Bool
$c< :: forall n. Ord n => Control_Meta n -> Control_Meta n -> Bool
compare :: Control_Meta n -> Control_Meta n -> Ordering
$ccompare :: forall n. Ord n => Control_Meta n -> Control_Meta n -> Ordering
Ord, Control_Meta n -> Control_Meta n -> Bool
forall n. Eq n => Control_Meta n -> Control_Meta n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Control_Meta n -> Control_Meta n -> Bool
$c/= :: forall n. Eq n => Control_Meta n -> Control_Meta n -> Bool
== :: Control_Meta n -> Control_Meta n -> Bool
$c== :: forall n. Eq n => Control_Meta n -> Control_Meta n -> Bool
Eq, ReadPrec [Control_Meta n]
ReadPrec (Control_Meta n)
ReadS [Control_Meta n]
forall n. Read n => ReadPrec [Control_Meta n]
forall n. Read n => ReadPrec (Control_Meta n)
forall n. Read n => Int -> ReadS (Control_Meta n)
forall n. Read n => ReadS [Control_Meta n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Control_Meta n]
$creadListPrec :: forall n. Read n => ReadPrec [Control_Meta n]
readPrec :: ReadPrec (Control_Meta n)
$creadPrec :: forall n. Read n => ReadPrec (Control_Meta n)
readList :: ReadS [Control_Meta n]
$creadList :: forall n. Read n => ReadS [Control_Meta n]
readsPrec :: Int -> ReadS (Control_Meta n)
$creadsPrec :: forall n. Read n => Int -> ReadS (Control_Meta n)
Read, Int -> Control_Meta n -> ShowS
forall n. Show n => Int -> Control_Meta n -> ShowS
forall n. Show n => [Control_Meta n] -> ShowS
forall n. Show n => Control_Meta n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Control_Meta n] -> ShowS
$cshowList :: forall n. Show n => [Control_Meta n] -> ShowS
show :: Control_Meta n -> String
$cshow :: forall n. Show n => Control_Meta n -> String
showsPrec :: Int -> Control_Meta n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Control_Meta n -> ShowS
Show)

-- * Control Meta (T)

-- | 3-tuple form of 'Control_Meta' data.
type Control_Meta_T3 n = (n, n, String)

-- | Lift 'Control_Meta_T3' to 'Control_Meta' allowing type coercion.
control_meta_t3 :: Num m => (n -> m) -> Control_Meta_T3 n -> Control_Meta m
control_meta_t3 :: forall m n.
Num m =>
(n -> m) -> Control_Meta_T3 n -> Control_Meta m
control_meta_t3 n -> m
f (n
l,n
r,String
w) = forall n.
n
-> n
-> String
-> n
-> String
-> Maybe Control_Group
-> Control_Meta n
Control_Meta (n -> m
f n
l) (n -> m
f n
r) String
w m
0 String
"" forall a. Maybe a
Nothing

-- | 5-tuple form of 'Control_Meta' data.
type Control_Meta_T5 n = (n,n,String,n,String)

-- | Lift 'Control_Meta_T5' to 'Control_Meta' allowing type coercion.
control_meta_t5 :: (n -> m) -> Control_Meta_T5 n -> Control_Meta m
control_meta_t5 :: forall n m. (n -> m) -> Control_Meta_T5 n -> Control_Meta m
control_meta_t5 n -> m
f (n
l,n
r,String
w,n
stp,String
u) = forall n.
n
-> n
-> String
-> n
-> String
-> Maybe Control_Group
-> Control_Meta n
Control_Meta (n -> m
f n
l) (n -> m
f n
r) String
w (n -> m
f n
stp) String
u forall a. Maybe a
Nothing

-- * Control

{- | Control inputs.
It is an unchecked invariant that controls with equal names within a Ugen graph must be equal in all other respects.
-}
data Control =
  Control
  {Control -> Rate
controlOperatingRate :: Rate
  ,Control -> Maybe Int
controlIndex :: Maybe Int
  ,Control -> String
controlName :: String
  ,Control -> Double
controlDefault :: Double
  ,Control -> Bool
controlTriggered :: Bool
  ,Control -> Maybe (Control_Meta Double)
controlMeta :: Maybe (Control_Meta Double)
  ,Control -> Brackets
controlBrackets :: Brackets}
  deriving (Eq Control
Control -> Control -> Bool
Control -> Control -> Ordering
Control -> Control -> Control
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Control -> Control -> Control
$cmin :: Control -> Control -> Control
max :: Control -> Control -> Control
$cmax :: Control -> Control -> Control
>= :: Control -> Control -> Bool
$c>= :: Control -> Control -> Bool
> :: Control -> Control -> Bool
$c> :: Control -> Control -> Bool
<= :: Control -> Control -> Bool
$c<= :: Control -> Control -> Bool
< :: Control -> Control -> Bool
$c< :: Control -> Control -> Bool
compare :: Control -> Control -> Ordering
$ccompare :: Control -> Control -> Ordering
Ord, Control -> Control -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Control -> Control -> Bool
$c/= :: Control -> Control -> Bool
== :: Control -> Control -> Bool
$c== :: Control -> Control -> Bool
Eq, ReadPrec [Control]
ReadPrec Control
Int -> ReadS Control
ReadS [Control]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Control]
$creadListPrec :: ReadPrec [Control]
readPrec :: ReadPrec Control
$creadPrec :: ReadPrec Control
readList :: ReadS [Control]
$creadList :: ReadS [Control]
readsPrec :: Int -> ReadS Control
$creadsPrec :: Int -> ReadS Control
Read, Int -> Control -> ShowS
[Control] -> ShowS
Control -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Control] -> ShowS
$cshowList :: [Control] -> ShowS
show :: Control -> String
$cshow :: Control -> String
showsPrec :: Int -> Control -> ShowS
$cshowsPrec :: Int -> Control -> ShowS
Show)

{-
-- | Control type
data CVarTy = CVarInit | CVarControl | CVarTrigger deriving (Eq,Read,Show)
CVar CVarTy String Double -- ^ Control input (named)
-}