-- | Brackets
module Sound.Sc3.Ugen.Brackets where

import Data.Bifunctor {- base -}

import qualified Sound.Osc.Packet as Osc {- hosc -}

{- | Brackets are two sets of Open Sound Control messages that can be associated with a Ugen.
The first is to be run prior to the graph being executed, the other after it has ended.
-}
type Brackets = ([Osc.Message], [Osc.Message])

-- | No messages.
emptyBrackets :: Brackets
emptyBrackets :: Brackets
emptyBrackets = ([], [])

{- | Combine a sequence of Brackets into one Bracket.

> f = bimap concat concat . unzip
> f [(['a'],['A']),(['b'],['B'])]
-}
concatBrackets :: [Brackets] -> Brackets
concatBrackets :: [Brackets] -> Brackets
concatBrackets = forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. [(a, b)] -> ([a], [b])
unzip