module Music.Score.Meta.Annotations (
Annotation,
annotate,
annotateSpan,
showAnnotations,
showAnnotations',
withAnnotations,
) where
import Control.Arrow
import Control.Monad.Plus
import qualified Data.List
import Data.Semigroup
import Data.String
import Data.Typeable
import Data.Void
import Music.Score.Combinators (withGlobalMeta)
import Music.Score.Meta
import Music.Score.Note
import Music.Score.Ornaments (HasText, text)
import Music.Score.Part
import Music.Score.Score
import Music.Time
import Music.Time.Reactive
newtype Annotation = Annotation { getAnnotation_ :: [String] }
deriving (Semigroup, Monoid, Typeable)
instance IsString Annotation where fromString = Annotation . return
getAnnotation :: Annotation -> [String]
getAnnotation = Data.List.nub . getAnnotation_
annotate :: String -> Score a -> Score a
annotate str x = annotateSpan (start >-> duration x) str x
annotateSpan :: Span -> String -> Score a -> Score a
annotateSpan span str x = addGlobalMetaNote (sapp span $ return $ Annotation [str]) x
showAnnotations :: (HasPart' a, HasText a) => Score a -> Score a
showAnnotations = showAnnotations' ":"
showAnnotations' :: (HasPart' a, HasText a) => String -> Score a -> Score a
showAnnotations' prefix = withAnnotations (flip $ \s -> foldr (text . (prefix ++ )) s)
withAnnotations :: (HasPart' a, HasText a) => ([String] -> Score a -> Score a) -> Score a -> Score a
withAnnotations f = withGlobalMeta (f . getAnnotation)