module Csound.Dynamic.Render(
    renderCsd
) where

import qualified Text.PrettyPrint.Leijen as P

import Csound.Dynamic.Render.Instr
import Csound.Dynamic.Render.Pretty
import Csound.Dynamic.Types

renderCsd :: Csd -> String
renderCsd :: Csd -> String
renderCsd Csd
a = Doc -> String
forall a. Show a => a -> String
show (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc -> [Plugin] -> Doc
ppCsdFile
    (Flags -> Doc
renderFlags (Flags -> Doc) -> Flags -> Doc
forall a b. (a -> b) -> a -> b
$ Csd -> Flags
csdFlags Csd
a)
    (Orc -> Doc
renderOrc (Orc -> Doc) -> Orc -> Doc
forall a b. (a -> b) -> a -> b
$ Csd -> Orc
csdOrc Csd
a)
    (Sco -> Doc
renderSco   (Sco -> Doc) -> Sco -> Doc
forall a b. (a -> b) -> a -> b
$ Csd -> Sco
csdSco Csd
a)
    (Csd -> [Plugin]
csdPlugins Csd
a)

renderFlags :: Flags -> Doc
renderFlags :: Flags -> Doc
renderFlags = Flags -> Doc
forall a. Pretty a => a -> Doc
P.pretty

renderOrc :: Orc -> Doc
renderOrc :: Orc -> Doc
renderOrc Orc
a = [Doc] -> Doc
vcatSep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
headExpr Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: [Doc]
instrExprs
    where
        headExpr :: Doc
headExpr    = E -> Doc
renderInstrBody (Orc -> E
orcHead Orc
a)
        instrExprs :: [Doc]
instrExprs  = (Instr -> Doc) -> [Instr] -> [Doc]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Instr -> Doc
renderInstr (Orc -> [Instr]
orcInstruments Orc
a)

renderSco :: Sco -> Doc
renderSco :: Sco -> Doc
renderSco Sco
a = [Doc] -> Doc
vcatSep
    [ [Doc] -> Doc
P.vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ ((Int, Gen) -> Doc) -> [(Int, Gen)] -> [Doc]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Int -> Gen -> Doc) -> (Int, Gen) -> Doc
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> Gen -> Doc
ppGen)   ([(Int, Gen)] -> [Doc]) -> [(Int, Gen)] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Sco -> [(Int, Gen)]
scoGens Sco
a
    , Doc -> (Double -> Doc) -> Maybe Double -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
P.empty Double -> Doc
ppTotalDur (Maybe Double -> Doc) -> Maybe Double -> Doc
forall a b. (a -> b) -> a -> b
$ Sco -> Maybe Double
scoTotalDur Sco
a
    , [Doc] -> Doc
P.vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ ((InstrId, [CsdEvent]) -> Doc) -> [(InstrId, [CsdEvent])] -> [Doc]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((InstrId -> [CsdEvent] -> Doc) -> (InstrId, [CsdEvent]) -> Doc
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry InstrId -> [CsdEvent] -> Doc
ppNotes) ([(InstrId, [CsdEvent])] -> [Doc])
-> [(InstrId, [CsdEvent])] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Sco -> [(InstrId, [CsdEvent])]
scoNotes Sco
a ]