hsc3-db-0.12: Sound/SC3/UGen/DB.hs
-- | SuperCollider 'UGen' database.
--
-- The database is generated by an @sclang@ program and is given by
-- the constant value 'ugenDB', which is a list of 'U' entries.
--
-- > length ugenDB == 740
module Sound.SC3.UGen.DB where
import Data.Char
import Sound.SC3.UGen.DB.Data
import Sound.SC3.UGen.DB.Record
-- | Lookup 'U' at 'ugenDB'.
--
-- > fmap ugen_default_rate (uLookup "SinOsc") == Just Sound.SC3.AR
uLookup :: String -> Maybe U
uLookup nm = lookup nm (zip (map ugen_name ugenDB) ugenDB)
-- | Case-insensitive variant of 'uLookup'.
--
-- > fmap ugen_default_rate (uLookup_ci "fft") == Just Sound.SC3.KR
uLookup_ci :: String -> Maybe U
uLookup_ci nm =
let lc = map toLower
db_nm = map (lc . ugen_name) ugenDB
in lookup (lc nm) (zip db_nm ugenDB)
-- | Is the input 'I' mce collapsed at 'U'.
i_is_mce :: U -> I -> Bool
i_is_mce u i =
let (_,n) = input_indices i
in case ugen_mce_input u of
Just m -> n == m
Nothing -> False
-- | Pretty printer for 'I'.
--
-- > let Just u = uLookup "SinOsc"
-- > in iPP u (I (0,0) "freq" 440.0) == "freq=440.0"
--
-- > let Just u = uLookup "Out"
-- > in iPP u (I (1,1) "channelsArray" 0) == "*channelsArray=0.0"
iPP :: U -> I -> String
iPP u i =
let m = if i_is_mce u i then "*" else ""
in m ++ input_name i ++ "=" ++ show (input_default i)
-- | Generate simple summary string for 'U'.
u_summary :: U -> String
u_summary u =
unwords [ugen_name u
,show (ugen_operating_rates u)
,unwords (map (iPP u) (ugen_inputs u))]
-- | Lookup named 'UGen' and generate simple summary string. If the
-- /fold case/ flag is true the name lookup is case insensitive.
ugenSummary' :: Bool -> String -> String
ugenSummary' fc nm =
let r = if fc then uLookup_ci nm else uLookup nm
in case r of
Just u -> u_summary u
Nothing -> error "unknown UGen?"
-- | Lookup named 'UGen' and generate simple summary string.
--
-- > ugenSummary "SinOsc" == "SinOsc [AR,KR] freq=440.0 phase=0.0"
ugenSummary :: String -> String
ugenSummary = ugenSummary' False
-- | Case-insensitive variant of 'ugenSummary'.
--
-- > ugenSummary_ci "fSinOsc" == "FSinOsc [AR,KR] freq=440.0 iphase=0.0"
ugenSummary_ci :: String -> String
ugenSummary_ci = ugenSummary' True