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 = (Char -> Bool) -> String -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
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) = (Bool -> Bool) -> [Bool] -> ([Bool], [Bool])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True) (String -> [Bool]
sc3_name_edges_plain String
s)
n :: Int
n = [Bool] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Bool]
p
in if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
2 Bool -> Bool -> Bool
|| [Bool] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Bool]
q
then Int -> Bool -> [Bool]
forall a. Int -> a -> [a]
replicate Int
n Bool
False [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++ [Bool]
q
else Int -> Bool -> [Bool]
forall a. Int -> a -> [a]
replicate (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Bool
False [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++ [Bool
True] [Bool] -> [Bool] -> [Bool]
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 (Char -> Bool -> Char) -> String -> [Bool] -> String
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (((Char, Bool) -> Char) -> Char -> Bool -> Char
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (Char, Bool) -> Char
f) ((Char -> Char) -> String -> String
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 Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' then [] else [Char
c]
in ((Char, Bool) -> String) -> [(Char, Bool)] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Char, Bool) -> String
f (String -> [Bool] -> [(Char, Bool)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Char -> Char) -> String -> String
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] -> (String, Maybe Rate) -> Maybe (String, Maybe Rate)
forall a. a -> Maybe a
Just (String
nm, String -> Maybe Rate
rate_parse ((Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper String
rt))
[String
nm] -> (String, Maybe Rate) -> Maybe (String, Maybe Rate)
forall a. a -> Maybe a
Just (String
nm, Maybe Rate
forall a. Maybe a
Nothing)
[String]
_ -> Maybe (String, Maybe Rate)
forall a. Maybe a
Nothing