-- | 'Ugen' pretty-printer.
module Sound.Sc3.Ugen.Pp where

import Data.List {- split -}

import Sound.Sc3.Common.Math
import Sound.Sc3.Common.Mce

import Sound.Sc3.Ugen.Types

{- | Print constants and labels directly,
     primitives as un-adorned names,
     mce as [p,q],
     mrg as p&q,
     contols as nm=def,
     proxies as u@n.
     Brackets are not printed.
-}
ugen_concise_pp :: Ugen -> String
ugen_concise_pp :: Ugen -> String
ugen_concise_pp Ugen
u =
    let bracketed :: (a, a) -> [a] -> [a]
bracketed (a
l,a
r) [a]
x = a
l forall a. a -> [a] -> [a]
: [a]
x forall a. [a] -> [a] -> [a]
++ [a
r]
        prim_pp :: Primitive t -> String
prim_pp (Primitive Rate
_ String
nm [t]
_ [Rate]
_ Special
sp UgenId
_ Brackets
_) = String -> Special -> String
ugen_user_name String
nm Special
sp
        k :: Int
k = Int
5
    in case Ugen
u of
         Constant_U (Constant Double
n Brackets
_) -> Int -> Double -> String
real_pp Int
k Double
n
         Control_U (Control Rate
_ Maybe Int
_ String
nm Double
def Bool
_ Maybe (Control_Meta Double)
_ Brackets
_) -> String
nm forall a. [a] -> [a] -> [a]
++ String
"=" forall a. [a] -> [a] -> [a]
++ Int -> Double -> String
real_pp Int
k Double
def
         Label_U (Label String
s) -> forall {a}. (a, a) -> [a] -> [a]
bracketed (Char
'"',Char
'"') String
s
         Primitive_U Primitive Ugen
p -> forall {t}. Primitive t -> String
prim_pp Primitive Ugen
p
         Proxy_U (Proxy Primitive Ugen
p Int
n) -> forall {t}. Primitive t -> String
prim_pp Primitive Ugen
p forall a. [a] -> [a] -> [a]
++ String
"@" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
n
         Mce_U (Mce_Scalar Ugen
s) -> Ugen -> String
ugen_concise_pp Ugen
s
         Mce_U (Mce_Vector [Mce Ugen]
v) -> forall {a}. (a, a) -> [a] -> [a]
bracketed (Char
'[',Char
']') (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a. a -> [a] -> [a]
intersperse String
"," (forall a b. (a -> b) -> [a] -> [b]
map (Ugen -> String
ugen_concise_pp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Mce t -> t
mce_scalar_value) [Mce Ugen]
v))) -- hugs
         Mrg_U (Mrg Ugen
l Ugen
r) -> [String] -> String
unwords [Ugen -> String
ugen_concise_pp Ugen
l,String
"&",Ugen -> String
ugen_concise_pp Ugen
r]