module Sound.Sc3.Ugen.Name where
import Data.Char
import Sound.Sc3.Common.Base
import Sound.Sc3.Common.Rate
sc3_name_edges_plain :: String -> [Bool]
sc3_name_edges_plain :: String -> [Bool]
sc3_name_edges_plain = forall a b. (a -> b) -> [a] -> [b]
map (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isLower)
sc3_name_edges :: String -> [Bool]
sc3_name_edges :: String -> [Bool]
sc3_name_edges String
s =
let ([Bool]
p,[Bool]
q) = forall a. (a -> Bool) -> [a] -> ([a], [a])
span (forall a. Eq a => a -> a -> Bool
== Bool
True) (String -> [Bool]
sc3_name_edges_plain String
s)
n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Bool]
p
in if Int
n forall a. Ord a => a -> a -> Bool
< Int
2 Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Bool]
q
then forall a. Int -> a -> [a]
replicate Int
n Bool
False forall a. [a] -> [a] -> [a]
++ [Bool]
q
else forall a. Int -> a -> [a]
replicate (Int
n forall a. Num a => a -> a -> a
- Int
1) Bool
False forall a. [a] -> [a] -> [a]
++ [Bool
True] forall a. [a] -> [a] -> [a]
++ [Bool]
q
sc3_name_to_hs_name :: String -> String
sc3_name_to_hs_name :: String -> String
sc3_name_to_hs_name String
s =
let f :: (Char, Bool) -> Char
f (Char
c,Bool
e) = if Bool
e then Char -> Char
toUpper Char
c else Char
c
in forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall a b c. ((a, b) -> c) -> a -> b -> c
curry (Char, Bool) -> Char
f) (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
s) (String -> [Bool]
sc3_name_edges String
s)
sc3_name_to_lisp_name :: String -> String
sc3_name_to_lisp_name :: String -> String
sc3_name_to_lisp_name String
s =
let f :: (Char, Bool) -> String
f (Char
c,Bool
e) = if Bool
e then [Char
'-',Char
c] else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'_' then [] else [Char
c]
in forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Char, Bool) -> String
f (forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
s) (String -> [Bool]
sc3_name_edges String
s))
sc3_ugen_name_sep :: String -> Maybe (String,Maybe Rate)
sc3_ugen_name_sep :: String -> Maybe (String, Maybe Rate)
sc3_ugen_name_sep String
u =
case Char -> String -> [String]
string_split_at_char Char
'.' String
u of
[String
nm,String
rt] -> forall a. a -> Maybe a
Just (String
nm,String -> Maybe Rate
rate_parse (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper String
rt))
[String
nm] -> forall a. a -> Maybe a
Just (String
nm,forall a. Maybe a
Nothing)
[String]
_ -> forall a. Maybe a
Nothing