{- | Non-standard mathematical enumerations, classes and base instances.

Enumerations of the unary and binary math unit generators.
Names that conflict with existing names have a @_@ suffix.

The Eq and Ord classes in the Prelude require Bool, hence EqE and OrdE.
True is 1.0, False is 0.0

The RealFrac class requires Integral results, hence RealFracE.
-}
module Sound.Sc3.Common.Math.Operator where

import Control.Monad {- base -}
import qualified Data.Fixed as F {- base -}
import Data.Int {- base -}
import Data.Maybe {- base -}

import qualified Sound.Sc3.Common.Base as Base {- hsc3 -}
import qualified Sound.Sc3.Common.Math as Math {- hsc3 -}

-- * Unary

{- | Enumeration of @Sc3@ unary operator Ugens.
     The names here are from the enumeration at "server/plugins/UnaryOpUgens.cpp".
     The capitalisation is edited since these names become function names in rsc3.
     Names have a _ suffix if they conflict with Ugen names.

> zip (map show [minBound :: Sc3_Unary_Op .. maxBound]) [0..]
-}
data Sc3_Unary_Op
  = OpNeg -- -
  | OpNot -- !
  | OpIsNil
  | OpNotNil
  | OpBitNot
  | OpAbs -- 5
  | OpAsFloat
  | OpAsInt
  | OpCeil -- 8
  | OpFloor -- 9
  | OpFrac -- 10
  | OpSign -- 11
  | OpSquared -- 12
  | OpCubed -- 13
  | OpSqrt -- 14
  | OpExp -- 15
  | OpRecip -- 16
  | OpMidiCps -- 17
  | OpCpsMidi -- 18
  | OpMidiRatio -- 19
  | OpRatioMidi -- 20
  | OpDbAmp -- 21
  | OpAmpDb -- 22
  | OpOctCps
  | OpCpsOct
  | OpLog -- 25 (natural, base e)
  | OpLog2 -- 26 (base 2)
  | OpLog10 -- 27 (base 10)
  | OpSin -- 28
  | OpCos -- 29
  | OpTan -- 30
  | OpArcSin
  | OpArcCos
  | OpArcTan
  | OpSinh
  | OpCosh -- 35
  | OpTanh -- 36
  | OpRand_ -- 37 ; Ugen
  | OpRand2
  | OpLinRand_ -- 39 ; Ugen
  | OpBiLinRand -- 40
  | OpSum3Rand
  | OpDistort -- 42
  | OpSoftClip -- 43
  | OpCoin
  | OpDigitValue -- 45
  | OpSilence -- 46
  | OpThru -- 47
  | OpRectWindow -- 48
  | OpHanWindow -- 49
  | OpWelchWindow -- 50
  | OpTriWindow
  | OpRamp_ -- 52 ; Ugen
  | OpScurve
  deriving (Sc3_Unary_Op -> Sc3_Unary_Op -> Bool
(Sc3_Unary_Op -> Sc3_Unary_Op -> Bool)
-> (Sc3_Unary_Op -> Sc3_Unary_Op -> Bool) -> Eq Sc3_Unary_Op
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Sc3_Unary_Op -> Sc3_Unary_Op -> Bool
== :: Sc3_Unary_Op -> Sc3_Unary_Op -> Bool
$c/= :: Sc3_Unary_Op -> Sc3_Unary_Op -> Bool
/= :: Sc3_Unary_Op -> Sc3_Unary_Op -> Bool
Eq, Int -> Sc3_Unary_Op -> ShowS
[Sc3_Unary_Op] -> ShowS
Sc3_Unary_Op -> String
(Int -> Sc3_Unary_Op -> ShowS)
-> (Sc3_Unary_Op -> String)
-> ([Sc3_Unary_Op] -> ShowS)
-> Show Sc3_Unary_Op
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Sc3_Unary_Op -> ShowS
showsPrec :: Int -> Sc3_Unary_Op -> ShowS
$cshow :: Sc3_Unary_Op -> String
show :: Sc3_Unary_Op -> String
$cshowList :: [Sc3_Unary_Op] -> ShowS
showList :: [Sc3_Unary_Op] -> ShowS
Show, Int -> Sc3_Unary_Op
Sc3_Unary_Op -> Int
Sc3_Unary_Op -> [Sc3_Unary_Op]
Sc3_Unary_Op -> Sc3_Unary_Op
Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
Sc3_Unary_Op -> Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
(Sc3_Unary_Op -> Sc3_Unary_Op)
-> (Sc3_Unary_Op -> Sc3_Unary_Op)
-> (Int -> Sc3_Unary_Op)
-> (Sc3_Unary_Op -> Int)
-> (Sc3_Unary_Op -> [Sc3_Unary_Op])
-> (Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op])
-> (Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op])
-> (Sc3_Unary_Op -> Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op])
-> Enum Sc3_Unary_Op
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Sc3_Unary_Op -> Sc3_Unary_Op
succ :: Sc3_Unary_Op -> Sc3_Unary_Op
$cpred :: Sc3_Unary_Op -> Sc3_Unary_Op
pred :: Sc3_Unary_Op -> Sc3_Unary_Op
$ctoEnum :: Int -> Sc3_Unary_Op
toEnum :: Int -> Sc3_Unary_Op
$cfromEnum :: Sc3_Unary_Op -> Int
fromEnum :: Sc3_Unary_Op -> Int
$cenumFrom :: Sc3_Unary_Op -> [Sc3_Unary_Op]
enumFrom :: Sc3_Unary_Op -> [Sc3_Unary_Op]
$cenumFromThen :: Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
enumFromThen :: Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
$cenumFromTo :: Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
enumFromTo :: Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
$cenumFromThenTo :: Sc3_Unary_Op -> Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
enumFromThenTo :: Sc3_Unary_Op -> Sc3_Unary_Op -> Sc3_Unary_Op -> [Sc3_Unary_Op]
Enum, Sc3_Unary_Op
Sc3_Unary_Op -> Sc3_Unary_Op -> Bounded Sc3_Unary_Op
forall a. a -> a -> Bounded a
$cminBound :: Sc3_Unary_Op
minBound :: Sc3_Unary_Op
$cmaxBound :: Sc3_Unary_Op
maxBound :: Sc3_Unary_Op
Bounded, ReadPrec [Sc3_Unary_Op]
ReadPrec Sc3_Unary_Op
Int -> ReadS Sc3_Unary_Op
ReadS [Sc3_Unary_Op]
(Int -> ReadS Sc3_Unary_Op)
-> ReadS [Sc3_Unary_Op]
-> ReadPrec Sc3_Unary_Op
-> ReadPrec [Sc3_Unary_Op]
-> Read Sc3_Unary_Op
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Sc3_Unary_Op
readsPrec :: Int -> ReadS Sc3_Unary_Op
$creadList :: ReadS [Sc3_Unary_Op]
readList :: ReadS [Sc3_Unary_Op]
$creadPrec :: ReadPrec Sc3_Unary_Op
readPrec :: ReadPrec Sc3_Unary_Op
$creadListPrec :: ReadPrec [Sc3_Unary_Op]
readListPrec :: ReadPrec [Sc3_Unary_Op]
Read)

-- | Enum name without Op prefix.
sc3_unary_op_name :: Sc3_Unary_Op -> String
sc3_unary_op_name :: Sc3_Unary_Op -> String
sc3_unary_op_name = Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
2 ShowS -> (Sc3_Unary_Op -> String) -> Sc3_Unary_Op -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sc3_Unary_Op -> String
forall a. Show a => a -> String
show

{- | 'Base.parse_enum' with Op prefix.

>>> Data.Maybe.mapMaybe (parse_unary Base.Cs) (words "Abs Rand")
[OpAbs]
-}
parse_unary :: Base.Case_Rule -> String -> Maybe Sc3_Unary_Op
parse_unary :: Case_Rule -> String -> Maybe Sc3_Unary_Op
parse_unary Case_Rule
cr = Case_Rule -> String -> Maybe Sc3_Unary_Op
forall t.
(Show t, Enum t, Bounded t) =>
Case_Rule -> String -> Maybe t
Base.parse_enum Case_Rule
cr (String -> Maybe Sc3_Unary_Op)
-> ShowS -> String -> Maybe Sc3_Unary_Op
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
forall a. [a] -> [a] -> [a]
(++) String
"Op"

{- | Table of operator names (non-symbolic) and indices.

> map fst sc3_unary_op_tbl
-}
sc3_unary_op_tbl :: [(String, Int)]
sc3_unary_op_tbl :: [(String, Int)]
sc3_unary_op_tbl = [String] -> [Int] -> [(String, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Sc3_Unary_Op -> String) -> [Sc3_Unary_Op] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Sc3_Unary_Op -> String
sc3_unary_op_name [Sc3_Unary_Op
forall a. Bounded a => a
minBound .. Sc3_Unary_Op
forall a. Bounded a => a
maxBound]) [Int
0 ..]

-- | Table of symbolic names for standard unary operators.
unary_sym_tbl :: [(Sc3_Unary_Op, String)]
unary_sym_tbl :: [(Sc3_Unary_Op, String)]
unary_sym_tbl = [] -- (Neg,"-"),(Not,"!")

-- | Lookup possibly symbolic name for standard unary operators.
unaryName :: Int -> String
unaryName :: Int -> String
unaryName Int
n =
  let e :: Sc3_Unary_Op
e = Int -> Sc3_Unary_Op
forall a. Enum a => Int -> a
toEnum Int
n
  in String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe (Sc3_Unary_Op -> String
sc3_unary_op_name Sc3_Unary_Op
e) (Sc3_Unary_Op -> [(Sc3_Unary_Op, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Sc3_Unary_Op
e [(Sc3_Unary_Op, String)]
unary_sym_tbl)

{- | Given name of unary operator derive index.

>>> Data.Maybe.mapMaybe (unaryIndex Base.Ci) (words "abs Cubed midiCps Neg")
[5,13,17,0]

>>> unaryIndex Base.Cs "SinOsc"
Nothing
-}
unaryIndex :: Base.Case_Rule -> String -> Maybe Int
unaryIndex :: Case_Rule -> String -> Maybe Int
unaryIndex Case_Rule
cr String
nm =
  let ix :: Maybe Sc3_Unary_Op
ix = Case_Rule
-> String -> [(Sc3_Unary_Op, String)] -> Maybe Sc3_Unary_Op
forall a. Case_Rule -> String -> [(a, String)] -> Maybe a
Base.rlookup_str Case_Rule
cr String
nm [(Sc3_Unary_Op, String)]
unary_sym_tbl
      ix' :: Maybe Sc3_Unary_Op
ix' = Case_Rule -> String -> Maybe Sc3_Unary_Op
parse_unary Case_Rule
cr String
nm
  in (Sc3_Unary_Op -> Int) -> Maybe Sc3_Unary_Op -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sc3_Unary_Op -> Int
forall a. Enum a => a -> Int
fromEnum (Maybe Sc3_Unary_Op -> Maybe Sc3_Unary_Op -> Maybe Sc3_Unary_Op
forall a. Maybe a -> Maybe a -> Maybe a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus Maybe Sc3_Unary_Op
ix' Maybe Sc3_Unary_Op
ix)

{- | 'isJust' of 'unaryIndex'.

>>> map (is_unary Base.Ci) (words "Abs MidiCps Neg")
[True,True,True]

>>> map (is_unary Base.Ci) (words "- rand")
[False,False]

>>> map (is_unary Base.Ci) (words "arctan atan")
[True,False]
-}
is_unary :: Base.Case_Rule -> String -> Bool
is_unary :: Case_Rule -> String -> Bool
is_unary Case_Rule
cr = Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Int -> Bool) -> (String -> Maybe Int) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Case_Rule -> String -> Maybe Int
unaryIndex Case_Rule
cr

-- * Binary

{- | Enumeration of @Sc3@ unary operator Ugens.
The names here are from the enumeration at "server/plugins/BinaryOpUgens.cpp".

> zip (map show [minBound :: Sc3_Binary_Op .. maxBound]) [0..]
-}
data Sc3_Binary_Op
  = OpAdd -- 0
  | OpSub -- 1
  | OpMul -- 2
  | OpIdiv -- 3
  | OpFdiv -- 4
  | OpMod -- 5
  | OpEq -- 6
  | OpNe -- 7
  | OpLt -- 8
  | OpGt -- 9
  | OpLe -- 10
  | OpGe -- 11
  | OpMin -- 12
  | OpMax -- 13
  | OpBitAnd -- 14
  | OpBitOr -- 15
  | OpBitXor
  | OpLcm -- 17
  | OpGcd -- 18
  | OpRoundTo -- 19 -- i.e. roundTo: (renamed)
  | OpRoundUp -- 20
  | OpTrunc -- 21
  | OpAtan2 -- 22
  | OpHypot -- 23
  | OpHypotx
  | OpPow -- 25
  | OpShiftLeft -- 26
  | OpShiftRight -- 27
  | OpUnsignedShift
  | OpFill
  | OpRing1 -- 30
  | OpRing2
  | OpRing3
  | OpRing4
  | OpDifSqr
  | OpSumSqr -- 35
  | OpSqrSum
  | OpSqrDif
  | OpAbsDif -- 38
  | OpThresh
  | OpAmClip -- 40
  | OpScaleNeg -- 41
  | OpClip2 -- 42
  | OpExcess
  | OpFold2 -- 44
  | OpWrap2 -- 45
  | OpFirstArg -- 46
  | OpRandRange -- 47
  | OpExpRandRange -- 48
  deriving (Sc3_Binary_Op -> Sc3_Binary_Op -> Bool
(Sc3_Binary_Op -> Sc3_Binary_Op -> Bool)
-> (Sc3_Binary_Op -> Sc3_Binary_Op -> Bool) -> Eq Sc3_Binary_Op
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Sc3_Binary_Op -> Sc3_Binary_Op -> Bool
== :: Sc3_Binary_Op -> Sc3_Binary_Op -> Bool
$c/= :: Sc3_Binary_Op -> Sc3_Binary_Op -> Bool
/= :: Sc3_Binary_Op -> Sc3_Binary_Op -> Bool
Eq, Int -> Sc3_Binary_Op -> ShowS
[Sc3_Binary_Op] -> ShowS
Sc3_Binary_Op -> String
(Int -> Sc3_Binary_Op -> ShowS)
-> (Sc3_Binary_Op -> String)
-> ([Sc3_Binary_Op] -> ShowS)
-> Show Sc3_Binary_Op
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Sc3_Binary_Op -> ShowS
showsPrec :: Int -> Sc3_Binary_Op -> ShowS
$cshow :: Sc3_Binary_Op -> String
show :: Sc3_Binary_Op -> String
$cshowList :: [Sc3_Binary_Op] -> ShowS
showList :: [Sc3_Binary_Op] -> ShowS
Show, Int -> Sc3_Binary_Op
Sc3_Binary_Op -> Int
Sc3_Binary_Op -> [Sc3_Binary_Op]
Sc3_Binary_Op -> Sc3_Binary_Op
Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
Sc3_Binary_Op -> Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
(Sc3_Binary_Op -> Sc3_Binary_Op)
-> (Sc3_Binary_Op -> Sc3_Binary_Op)
-> (Int -> Sc3_Binary_Op)
-> (Sc3_Binary_Op -> Int)
-> (Sc3_Binary_Op -> [Sc3_Binary_Op])
-> (Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op])
-> (Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op])
-> (Sc3_Binary_Op
    -> Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op])
-> Enum Sc3_Binary_Op
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Sc3_Binary_Op -> Sc3_Binary_Op
succ :: Sc3_Binary_Op -> Sc3_Binary_Op
$cpred :: Sc3_Binary_Op -> Sc3_Binary_Op
pred :: Sc3_Binary_Op -> Sc3_Binary_Op
$ctoEnum :: Int -> Sc3_Binary_Op
toEnum :: Int -> Sc3_Binary_Op
$cfromEnum :: Sc3_Binary_Op -> Int
fromEnum :: Sc3_Binary_Op -> Int
$cenumFrom :: Sc3_Binary_Op -> [Sc3_Binary_Op]
enumFrom :: Sc3_Binary_Op -> [Sc3_Binary_Op]
$cenumFromThen :: Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
enumFromThen :: Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
$cenumFromTo :: Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
enumFromTo :: Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
$cenumFromThenTo :: Sc3_Binary_Op -> Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
enumFromThenTo :: Sc3_Binary_Op -> Sc3_Binary_Op -> Sc3_Binary_Op -> [Sc3_Binary_Op]
Enum, Sc3_Binary_Op
Sc3_Binary_Op -> Sc3_Binary_Op -> Bounded Sc3_Binary_Op
forall a. a -> a -> Bounded a
$cminBound :: Sc3_Binary_Op
minBound :: Sc3_Binary_Op
$cmaxBound :: Sc3_Binary_Op
maxBound :: Sc3_Binary_Op
Bounded, ReadPrec [Sc3_Binary_Op]
ReadPrec Sc3_Binary_Op
Int -> ReadS Sc3_Binary_Op
ReadS [Sc3_Binary_Op]
(Int -> ReadS Sc3_Binary_Op)
-> ReadS [Sc3_Binary_Op]
-> ReadPrec Sc3_Binary_Op
-> ReadPrec [Sc3_Binary_Op]
-> Read Sc3_Binary_Op
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Sc3_Binary_Op
readsPrec :: Int -> ReadS Sc3_Binary_Op
$creadList :: ReadS [Sc3_Binary_Op]
readList :: ReadS [Sc3_Binary_Op]
$creadPrec :: ReadPrec Sc3_Binary_Op
readPrec :: ReadPrec Sc3_Binary_Op
$creadListPrec :: ReadPrec [Sc3_Binary_Op]
readListPrec :: ReadPrec [Sc3_Binary_Op]
Read)

-- | Enum name without Op prefix.
sc3_binary_op_name :: Sc3_Binary_Op -> String
sc3_binary_op_name :: Sc3_Binary_Op -> String
sc3_binary_op_name = Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
2 ShowS -> (Sc3_Binary_Op -> String) -> Sc3_Binary_Op -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sc3_Binary_Op -> String
forall a. Show a => a -> String
show

-- | Table of operator names (non-symbolic) and indices.
sc3_binary_op_tbl :: [(String, Int)]
sc3_binary_op_tbl :: [(String, Int)]
sc3_binary_op_tbl = [String] -> [Int] -> [(String, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Sc3_Binary_Op -> String) -> [Sc3_Binary_Op] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Sc3_Binary_Op -> String
sc3_binary_op_name [Sc3_Binary_Op
forall a. Bounded a => a
minBound .. Sc3_Binary_Op
forall a. Bounded a => a
maxBound]) [Int
0 ..]

{- | 'parse_enum' with Op prefix.

>>> parse_binary Base.Ci "mul"
Just OpMul
-}
parse_binary :: Base.Case_Rule -> String -> Maybe Sc3_Binary_Op
parse_binary :: Case_Rule -> String -> Maybe Sc3_Binary_Op
parse_binary Case_Rule
cr = Case_Rule -> String -> Maybe Sc3_Binary_Op
forall t.
(Show t, Enum t, Bounded t) =>
Case_Rule -> String -> Maybe t
Base.parse_enum Case_Rule
cr (String -> Maybe Sc3_Binary_Op)
-> ShowS -> String -> Maybe Sc3_Binary_Op
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
forall a. [a] -> [a] -> [a]
(++) String
"Op"

-- | Table of symbolic names for standard binary operators.
binary_sym_tbl :: [(Sc3_Binary_Op, String)]
binary_sym_tbl :: [(Sc3_Binary_Op, String)]
binary_sym_tbl =
  [ (Sc3_Binary_Op
OpAdd, String
"+")
  , (Sc3_Binary_Op
OpSub, String
"-")
  , (Sc3_Binary_Op
OpMul, String
"*")
  , (Sc3_Binary_Op
OpFdiv, String
"/")
  , (Sc3_Binary_Op
OpMod, String
"%")
  , (Sc3_Binary_Op
OpEq, String
"==")
  , (Sc3_Binary_Op
OpNe, String
"/=") -- or !=
  , (Sc3_Binary_Op
OpLt, String
"<")
  , (Sc3_Binary_Op
OpGt, String
">")
  , (Sc3_Binary_Op
OpLe, String
"<=")
  , (Sc3_Binary_Op
OpGe, String
">=")
  , (Sc3_Binary_Op
OpBitAnd, String
".&.") -- or &
  , (Sc3_Binary_Op
OpBitOr, String
".|.") -- or |
  , (Sc3_Binary_Op
OpPow, String
"**")
  ]

{- | Table of operator names (non-symbolic) and indices.

> map fst sc3_binary_op_sym_tbl
-}
sc3_binary_op_sym_tbl :: [(String, Int)]
sc3_binary_op_sym_tbl :: [(String, Int)]
sc3_binary_op_sym_tbl =
  let f :: Sc3_Binary_Op -> String
f Sc3_Binary_Op
x = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe (Sc3_Binary_Op -> String
sc3_binary_op_name Sc3_Binary_Op
x) (Sc3_Binary_Op -> [(Sc3_Binary_Op, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Sc3_Binary_Op
x [(Sc3_Binary_Op, String)]
binary_sym_tbl)
  in [String] -> [Int] -> [(String, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Sc3_Binary_Op -> String) -> [Sc3_Binary_Op] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Sc3_Binary_Op -> String
f [Sc3_Binary_Op
forall a. Bounded a => a
minBound .. Sc3_Binary_Op
forall a. Bounded a => a
maxBound]) [Int
0 ..]

{- | Lookup possibly symbolic name for standard binary operators.

>>> map binaryName [1,2,8,12]
["-","*","<","Min"]
-}
binaryName :: Int -> String
binaryName :: Int -> String
binaryName Int
n =
  let e :: Sc3_Binary_Op
e = Int -> Sc3_Binary_Op
forall a. Enum a => Int -> a
toEnum Int
n
  in String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe (Sc3_Binary_Op -> String
sc3_binary_op_name Sc3_Binary_Op
e) (Sc3_Binary_Op -> [(Sc3_Binary_Op, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Sc3_Binary_Op
e [(Sc3_Binary_Op, String)]
binary_sym_tbl)

{- | Given name of binary operator derive index.

>>> Data.Maybe.mapMaybe (binaryIndex Base.Ci) (words "* mul ring1 +")
[2,2,30,0]

>>> binaryIndex Base.Ci "sinosc"
Nothing

>>> map (\x -> (x,binaryIndex Base.Ci x)) (map snd binary_sym_tbl)
[("+",Just 0),("-",Just 1),("*",Just 2),("/",Just 4),("%",Just 5),("==",Just 6),("/=",Just 7),("<",Just 8),(">",Just 9),("<=",Just 10),(">=",Just 11),(".&.",Just 14),(".|.",Just 15),("**",Just 25)]
-}
binaryIndex :: Base.Case_Rule -> String -> Maybe Int
binaryIndex :: Case_Rule -> String -> Maybe Int
binaryIndex Case_Rule
cr String
nm =
  let ix :: Maybe Sc3_Binary_Op
ix = Case_Rule
-> String -> [(Sc3_Binary_Op, String)] -> Maybe Sc3_Binary_Op
forall a. Case_Rule -> String -> [(a, String)] -> Maybe a
Base.rlookup_str Case_Rule
cr String
nm [(Sc3_Binary_Op, String)]
binary_sym_tbl
      ix' :: Maybe Sc3_Binary_Op
ix' = Case_Rule -> String -> Maybe Sc3_Binary_Op
parse_binary Case_Rule
cr String
nm
  in (Sc3_Binary_Op -> Int) -> Maybe Sc3_Binary_Op -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sc3_Binary_Op -> Int
forall a. Enum a => a -> Int
fromEnum (Maybe Sc3_Binary_Op -> Maybe Sc3_Binary_Op -> Maybe Sc3_Binary_Op
forall a. Maybe a -> Maybe a -> Maybe a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus Maybe Sc3_Binary_Op
ix' Maybe Sc3_Binary_Op
ix)

{- | 'isJust' of 'binaryIndex'.

>>> map (is_binary Base.Ci) (words "== > % Trunc max")
[True,True,True,True,True]
-}
is_binary :: Base.Case_Rule -> String -> Bool
is_binary :: Case_Rule -> String -> Bool
is_binary Case_Rule
cr = Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Int -> Bool) -> (String -> Maybe Int) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Case_Rule -> String -> Maybe Int
binaryIndex Case_Rule
cr

-- * Operator

-- | Lookup operator name for operator Ugens, else Ugen name.
ugen_operator_name :: String -> Int -> Maybe String
ugen_operator_name :: String -> Int -> Maybe String
ugen_operator_name String
nm Int
n =
  case String
nm of
    String
"UnaryOpUGen" -> String -> Maybe String
forall a. a -> Maybe a
Just (Int -> String
unaryName Int
n)
    String
"BinaryOpUGen" -> String -> Maybe String
forall a. a -> Maybe a
Just (Int -> String
binaryName Int
n)
    String
_ -> Maybe String
forall a. Maybe a
Nothing

{- | Order of lookup: binary then unary.

>>> map (resolve_operator Base.Ci) (words "+ - sub abs max")
[("BinaryOpUGen",Just 0),("BinaryOpUGen",Just 1),("BinaryOpUGen",Just 1),("UnaryOpUGen",Just 5),("BinaryOpUGen",Just 13)]

>>> map (resolve_operator Base.Cs) (words "Abs Add Neg")
[("UnaryOpUGen",Just 5),("BinaryOpUGen",Just 0),("UnaryOpUGen",Just 0)]
-}
resolve_operator :: Base.Case_Rule -> String -> (String, Maybe Int)
resolve_operator :: Case_Rule -> String -> (String, Maybe Int)
resolve_operator Case_Rule
cr String
nm =
  case Case_Rule -> String -> Maybe Int
binaryIndex Case_Rule
cr String
nm of
    Just Int
sp -> (String
"BinaryOpUGen", Int -> Maybe Int
forall a. a -> Maybe a
Just Int
sp)
    Maybe Int
Nothing -> case Case_Rule -> String -> Maybe Int
unaryIndex Case_Rule
cr String
nm of
      Just Int
sp -> (String
"UnaryOpUGen", Int -> Maybe Int
forall a. a -> Maybe a
Just Int
sp)
      Maybe Int
_ -> (String
nm, Maybe Int
forall a. Maybe a
Nothing)

-- | Case-insensitive resolve_operator.
resolve_operator_ci :: String -> (String, Maybe Int)
resolve_operator_ci :: String -> (String, Maybe Int)
resolve_operator_ci = Case_Rule -> String -> (String, Maybe Int)
resolve_operator Case_Rule
Base.Ci

-- * Classes

-- | Variant on 'Eq' class, result is of the same type as the values compared.
class (Eq a, Num a) => EqE a where
  equal_to :: a -> a -> a
  equal_to = a -> a -> a
forall n. (Num n, Eq n) => n -> n -> n
Math.sc3_eq
  not_equal_to :: a -> a -> a
  not_equal_to = a -> a -> a
forall n. (Num n, Eq n) => n -> n -> n
Math.sc3_neq

instance EqE Int
instance EqE Integer
instance EqE Int32
instance EqE Int64
instance EqE Float
instance EqE Double

-- | Variant on Ord class, result is of the same type as the values compared.
class (Ord a, Num a) => OrdE a where
  less_than :: a -> a -> a
  less_than = a -> a -> a
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_lt
  less_than_or_equal_to :: a -> a -> a
  less_than_or_equal_to = a -> a -> a
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_lte
  greater_than :: a -> a -> a
  greater_than = a -> a -> a
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_gt
  greater_than_or_equal_to :: a -> a -> a
  greater_than_or_equal_to = a -> a -> a
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_gte

instance OrdE Int
instance OrdE Integer
instance OrdE Int32
instance OrdE Int64
instance OrdE Float
instance OrdE Double

-- | Variant of 'RealFrac' with non 'Integral' results.
class RealFrac a => RealFracE a where
  properFractionE :: a -> (a, a)
  properFractionE = a -> (a, a)
forall t. RealFrac t => t -> (t, t)
Math.sc3_properFraction
  truncateE :: a -> a
  truncateE = a -> a
forall a. RealFrac a => a -> a
Math.sc3_truncate
  roundE :: a -> a
  roundE = a -> a
forall a. RealFrac a => a -> a
Math.sc3_round
  ceilingE :: a -> a
  ceilingE = a -> a
forall a. RealFrac a => a -> a
Math.sc3_ceiling
  floorE :: a -> a
  floorE = a -> a
forall a. RealFrac a => a -> a
Math.sc3_floor

instance RealFracE Float
instance RealFracE Double

{- | Unary operator class.

>>> map (floor . (* 1e4) . dbAmp) [-90,-60,-30,0]
[0,10,316,10000]
-}
class (Floating a, Ord a) => UnaryOp a where
  ampDb :: a -> a
  ampDb = a -> a
forall a. Floating a => a -> a
Math.amp_to_db
  asFloat :: a -> a
  asFloat = String -> a -> a
forall a. HasCallStack => String -> a
error String
"asFloat"
  asInt :: a -> a
  asInt = String -> a -> a
forall a. HasCallStack => String -> a
error String
"asInt"
  cpsMidi :: a -> a
  cpsMidi = a -> a
forall a. Floating a => a -> a
Math.cps_to_midi
  cpsOct :: a -> a
  cpsOct = a -> a
forall a. Floating a => a -> a
Math.cps_to_oct
  cubed :: a -> a
  cubed a
n = a
n a -> a -> a
forall a. Num a => a -> a -> a
* a
n a -> a -> a
forall a. Num a => a -> a -> a
* a
n
  dbAmp :: a -> a
  dbAmp = a -> a
forall a. Floating a => a -> a
Math.db_to_amp
  distort :: a -> a
  distort = a -> a
forall n. Fractional n => n -> n
Math.sc3_distort
  frac :: a -> a
  frac = String -> a -> a
forall a. HasCallStack => String -> a
error String
"frac"
  isNil :: a -> a
  isNil a
a = if a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0.0 then a
0.0 else a
1.0
  log10 :: a -> a
  log10 = a -> a -> a
forall a. Floating a => a -> a -> a
logBase a
10
  log2 :: a -> a
  log2 = a -> a -> a
forall a. Floating a => a -> a -> a
logBase a
2
  midiCps :: a -> a
  midiCps = a -> a
forall a. Floating a => a -> a
Math.midi_to_cps
  midiRatio :: a -> a
  midiRatio = a -> a
forall a. Floating a => a -> a
Math.midi_to_ratio
  notE :: a -> a
  notE a
a = if a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0.0 then a
0.0 else a
1.0
  notNil :: a -> a
  notNil a
a = if a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
0.0 then a
0.0 else a
1.0
  octCps :: a -> a
  octCps = a -> a
forall a. Floating a => a -> a
Math.oct_to_cps
  ramp_ :: a -> a
  ramp_ a
_ = String -> a
forall a. HasCallStack => String -> a
error String
"ramp_"
  ratioMidi :: a -> a
  ratioMidi = a -> a
forall a. Floating a => a -> a
Math.ratio_to_midi
  softClip :: a -> a
  softClip = a -> a
forall n. (Ord n, Fractional n) => n -> n
Math.sc3_softclip
  squared :: a -> a
  squared = \a
z -> a
z a -> a -> a
forall a. Num a => a -> a -> a
* a
z

instance UnaryOp Float
instance UnaryOp Double

-- | Sc3_Binary_Op operator class.
class (Floating a, RealFrac a, Ord a) => BinaryOp a where
  absDif :: a -> a -> a
  absDif a
a a
b = a -> a
forall a. Num a => a -> a
abs (a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
b)
  amClip :: a -> a -> a
  amClip a
a a
b = if a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 then a
0 else a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b
  atan2E :: a -> a -> a
  atan2E a
a a
b = a -> a
forall a. Floating a => a -> a
atan (a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
a)
  clip2 :: a -> a -> a
  clip2 a
a a
b = a -> a -> a -> a
forall a. Ord a => a -> a -> a -> a
Math.sc3_clip a
a (-a
b) a
b
  difSqr :: a -> a -> a
  difSqr = a -> a -> a
forall a. Num a => a -> a -> a
Math.sc3_dif_sqr
  excess :: a -> a -> a
  excess a
a a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
- a -> a -> a -> a
forall a. Ord a => a -> a -> a -> a
Math.sc3_clip a
a (-a
b) a
b
  exprandRange :: a -> a -> a
  exprandRange = String -> a -> a -> a
forall a. HasCallStack => String -> a
error String
"exprandRange"
  fill :: a -> a -> a
  fill = String -> a -> a -> a
forall a. HasCallStack => String -> a
error String
"fill"
  firstArg :: a -> a -> a
  firstArg a
a a
_ = a
a
  fold2 :: a -> a -> a
  fold2 a
a a
b = a -> a -> a -> a
forall a. (Ord a, Num a) => a -> a -> a -> a
Math.sc3_fold a
a (-a
b) a
b
  gcdE :: a -> a -> a
  gcdE = a -> a -> a
forall t. t -> t -> t
Math.sc3_gcd
  hypot :: a -> a -> a
  hypot = a -> a -> a
forall a. Floating a => a -> a -> a
Math.sc3_hypot
  hypotx :: a -> a -> a
  hypotx = a -> a -> a
forall a. (Ord a, Floating a) => a -> a -> a
Math.sc3_hypotx
  iDiv :: a -> a -> a
  iDiv = a -> a -> a
forall n. RealFrac n => n -> n -> n
Math.sc3_idiv
  lcmE :: a -> a -> a
  lcmE = a -> a -> a
forall t. t -> t -> t
Math.sc3_lcm
  modE :: a -> a -> a
  modE = a -> a -> a
forall n. RealFrac n => n -> n -> n
Math.sc3_mod
  randRange :: a -> a -> a
  randRange = String -> a -> a -> a
forall a. HasCallStack => String -> a
error String
"randRange"
  ring1 :: a -> a -> a
  ring1 a
a a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
a
  ring2 :: a -> a -> a
  ring2 a
a a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
b
  ring3 :: a -> a -> a
  ring3 a
a a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b
  ring4 :: a -> a -> a
  ring4 a
a a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
b
  roundUp :: a -> a -> a
  roundUp = String -> a -> a -> a
forall a. HasCallStack => String -> a
error String
"roundUp"
  scaleNeg :: a -> a -> a
  scaleNeg a
a a
b = (a -> a
forall a. Num a => a -> a
abs a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
a) a -> a -> a
forall a. Num a => a -> a -> a
* a
b' a -> a -> a
forall a. Num a => a -> a -> a
+ a
a where b' :: a
b' = a
0.5 a -> a -> a
forall a. Num a => a -> a -> a
* a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
0.5
  sqrDif :: a -> a -> a
  sqrDif a
a a
b = (a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
b) a -> a -> a
forall a. Num a => a -> a -> a
* (a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
b)
  sqrSum :: a -> a -> a
  sqrSum a
a a
b = (a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
b) a -> a -> a
forall a. Num a => a -> a -> a
* (a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
b)
  sumSqr :: a -> a -> a
  sumSqr a
a a
b = (a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
a) a -> a -> a
forall a. Num a => a -> a -> a
+ (a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
b)
  thresh :: a -> a -> a
  thresh a
a a
b = if a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
b then a
0 else a
a
  trunc :: a -> a -> a
  trunc = String -> a -> a -> a
forall a. HasCallStack => String -> a
error String
"trunc"
  wrap2 :: a -> a -> a
  wrap2 = String -> a -> a -> a
forall a. HasCallStack => String -> a
error String
"wrap2"

instance BinaryOp Float where
  fold2 :: Float -> Float -> Float
fold2 Float
a Float
b = Float -> Float -> Float -> Float
forall a. (Ord a, Num a) => a -> a -> a -> a
Math.sc3_fold Float
a (-Float
b) Float
b
  modE :: Float -> Float -> Float
modE = Float -> Float -> Float
forall a. Real a => a -> a -> a
F.mod'
  roundUp :: Float -> Float -> Float
roundUp Float
a Float
b = if Float
b Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Float
0 then Float
a else Float -> Float
forall a. RealFracE a => a -> a
ceilingE (Float
a Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
b Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
0.5) Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
b
  wrap2 :: Float -> Float -> Float
wrap2 Float
a Float
b = Float -> Float -> Float -> Float
forall a. RealFrac a => a -> a -> a -> a
Math.sc3_wrap_ni (-Float
b) Float
b Float
a

instance BinaryOp Double where
  fold2 :: Double -> Double -> Double
fold2 Double
a Double
b = Double -> Double -> Double -> Double
forall a. (Ord a, Num a) => a -> a -> a -> a
Math.sc3_fold Double
a (-Double
b) Double
b
  modE :: Double -> Double -> Double
modE = Double -> Double -> Double
forall a. Real a => a -> a -> a
F.mod'
  roundUp :: Double -> Double -> Double
roundUp Double
a Double
b = if Double
b Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
0 then Double
a else Double -> Double
forall a. RealFracE a => a -> a
ceilingE (Double
a Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
b Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
0.5) Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
b
  wrap2 :: Double -> Double -> Double
wrap2 Double
a Double
b = Double -> Double -> Double -> Double
forall a. RealFrac a => a -> a -> a -> a
Math.sc3_wrap_ni (-Double
b) Double
b Double
a

-- * Infix

(==**) :: EqE a => a -> a -> a
==** :: forall a. EqE a => a -> a -> a
(==**) = a -> a -> a
forall a. EqE a => a -> a -> a
equal_to

(/=**) :: EqE a => a -> a -> a
/=** :: forall a. EqE a => a -> a -> a
(/=**) = a -> a -> a
forall a. EqE a => a -> a -> a
not_equal_to

(<**) :: OrdE a => a -> a -> a
<** :: forall a. OrdE a => a -> a -> a
(<**) = a -> a -> a
forall a. OrdE a => a -> a -> a
less_than

(<=**) :: OrdE a => a -> a -> a
<=** :: forall a. OrdE a => a -> a -> a
(<=**) = a -> a -> a
forall a. OrdE a => a -> a -> a
less_than_or_equal_to

(>**) :: OrdE a => a -> a -> a
>** :: forall a. OrdE a => a -> a -> a
(>**) = a -> a -> a
forall a. OrdE a => a -> a -> a
greater_than

(>=**) :: OrdE a => a -> a -> a
>=** :: forall a. OrdE a => a -> a -> a
(>=**) = a -> a -> a
forall a. OrdE a => a -> a -> a
greater_than_or_equal_to

-- * Tables

-- | Association table for 'Sc3_Binary_Op' to haskell function implementing operator.
binop_hs_tbl :: (Real n, Floating n, RealFrac n) => [(Sc3_Binary_Op, n -> n -> n)]
binop_hs_tbl :: forall n.
(Real n, Floating n, RealFrac n) =>
[(Sc3_Binary_Op, n -> n -> n)]
binop_hs_tbl =
  [ (Sc3_Binary_Op
OpAdd, n -> n -> n
forall a. Num a => a -> a -> a
(+))
  , (Sc3_Binary_Op
OpSub, (-))
  , (Sc3_Binary_Op
OpFdiv, n -> n -> n
forall a. Fractional a => a -> a -> a
(/))
  , (Sc3_Binary_Op
OpIdiv, n -> n -> n
forall n. RealFrac n => n -> n -> n
Math.sc3_idiv)
  , (Sc3_Binary_Op
OpMod, n -> n -> n
forall n. RealFrac n => n -> n -> n
Math.sc3_mod)
  , (Sc3_Binary_Op
OpEq, n -> n -> n
forall n. (Num n, Eq n) => n -> n -> n
Math.sc3_eq)
  , (Sc3_Binary_Op
OpNe, n -> n -> n
forall n. (Num n, Eq n) => n -> n -> n
Math.sc3_neq)
  , (Sc3_Binary_Op
OpLt, n -> n -> n
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_lt)
  , (Sc3_Binary_Op
OpLe, n -> n -> n
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_lte)
  , (Sc3_Binary_Op
OpGt, n -> n -> n
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_gt)
  , (Sc3_Binary_Op
OpGe, n -> n -> n
forall n. (Num n, Ord n) => n -> n -> n
Math.sc3_gte)
  , (Sc3_Binary_Op
OpMin, n -> n -> n
forall a. Ord a => a -> a -> a
min)
  , (Sc3_Binary_Op
OpMax, n -> n -> n
forall a. Ord a => a -> a -> a
max)
  , (Sc3_Binary_Op
OpMul, n -> n -> n
forall a. Num a => a -> a -> a
(*))
  , (Sc3_Binary_Op
OpPow, n -> n -> n
forall a. Floating a => a -> a -> a
(**))
  , (Sc3_Binary_Op
OpMin, n -> n -> n
forall a. Ord a => a -> a -> a
min)
  , (Sc3_Binary_Op
OpMax, n -> n -> n
forall a. Ord a => a -> a -> a
max)
  , (Sc3_Binary_Op
OpRoundTo, n -> n -> n
forall n. RealFrac n => n -> n -> n
Math.sc3_round_to)
  ]

-- | 'lookup' 'binop_hs_tbl' via 'toEnum'.
binop_special_hs :: (RealFrac n, Floating n) => Int -> Maybe (n -> n -> n)
binop_special_hs :: forall n. (RealFrac n, Floating n) => Int -> Maybe (n -> n -> n)
binop_special_hs Int
z = Sc3_Binary_Op
-> [(Sc3_Binary_Op, n -> n -> n)] -> Maybe (n -> n -> n)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup (Int -> Sc3_Binary_Op
forall a. Enum a => Int -> a
toEnum Int
z) [(Sc3_Binary_Op, n -> n -> n)]
forall n.
(Real n, Floating n, RealFrac n) =>
[(Sc3_Binary_Op, n -> n -> n)]
binop_hs_tbl

-- | Association table for 'Unary' to haskell function implementing operator.
uop_hs_tbl :: (RealFrac n, Floating n) => [(Sc3_Unary_Op, n -> n)]
uop_hs_tbl :: forall n. (RealFrac n, Floating n) => [(Sc3_Unary_Op, n -> n)]
uop_hs_tbl =
  [ (Sc3_Unary_Op
OpNeg, n -> n
forall a. Num a => a -> a
negate)
  , (Sc3_Unary_Op
OpNot, \n
z -> if n
z n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
0 then n
0 else n
1)
  , (Sc3_Unary_Op
OpAbs, n -> n
forall a. Num a => a -> a
abs)
  , (Sc3_Unary_Op
OpCeil, n -> n
forall a. RealFrac a => a -> a
Math.sc3_ceiling)
  , (Sc3_Unary_Op
OpFloor, n -> n
forall a. RealFrac a => a -> a
Math.sc3_floor)
  , (Sc3_Unary_Op
OpSquared, \n
z -> n
z n -> n -> n
forall a. Num a => a -> a -> a
* n
z)
  , (Sc3_Unary_Op
OpCubed, \n
z -> n
z n -> n -> n
forall a. Num a => a -> a -> a
* n
z n -> n -> n
forall a. Num a => a -> a -> a
* n
z)
  , (Sc3_Unary_Op
OpSqrt, n -> n
forall a. Floating a => a -> a
sqrt)
  , (Sc3_Unary_Op
OpRecip, n -> n
forall n. Fractional n => n -> n
recip)
  , (Sc3_Unary_Op
OpMidiCps, n -> n
forall a. Floating a => a -> a
Math.midi_to_cps)
  , (Sc3_Unary_Op
OpCpsMidi, n -> n
forall a. Floating a => a -> a
Math.cps_to_midi)
  , (Sc3_Unary_Op
OpSin, n -> n
forall a. Floating a => a -> a
sin)
  , (Sc3_Unary_Op
OpCos, n -> n
forall a. Floating a => a -> a
cos)
  , (Sc3_Unary_Op
OpTan, n -> n
forall a. Floating a => a -> a
tan)
  ]

-- | 'lookup' 'uop_hs_tbl' via 'toEnum'.
uop_special_hs :: (RealFrac n, Floating n) => Int -> Maybe (n -> n)
uop_special_hs :: forall n. (RealFrac n, Floating n) => Int -> Maybe (n -> n)
uop_special_hs Int
z = Sc3_Unary_Op -> [(Sc3_Unary_Op, n -> n)] -> Maybe (n -> n)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup (Int -> Sc3_Unary_Op
forall a. Enum a => Int -> a
toEnum Int
z) [(Sc3_Unary_Op, n -> n)]
forall n. (RealFrac n, Floating n) => [(Sc3_Unary_Op, n -> n)]
uop_hs_tbl