-- | 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 = Data.Bifunctor.bimap concat concat . unzip
>>> f [(['a'],['A']),(['b'],['B'])]
("ab","AB")
-}
concatBrackets :: [Brackets] -> Brackets
concatBrackets :: [Brackets] -> Brackets
concatBrackets = ([[Message]] -> [Message])
-> ([[Message]] -> [Message])
-> ([[Message]], [[Message]])
-> Brackets
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap [[Message]] -> [Message]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Message]] -> [Message]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (([[Message]], [[Message]]) -> Brackets)
-> ([Brackets] -> ([[Message]], [[Message]]))
-> [Brackets]
-> Brackets
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Brackets] -> ([[Message]], [[Message]])
forall a b. [(a, b)] -> ([a], [b])
unzip