module Music.Score.Meta.Annotations (
Annotation,
getAnnotation,
annotate,
annotateSpan,
showAnnotations,
showAnnotations',
withAnnotations,
) where
import Control.Monad.Plus
import qualified Data.List
import Data.Semigroup
import Data.String
import Data.Typeable
import Music.Score.Meta
import Music.Score.Part
import Music.Score.Text (HasText, text)
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 (0 >-> _duration x) str x
annotateSpan :: Span -> String -> Score a -> Score a
annotateSpan span str x = addMetaNote (transform span $ return $ Annotation [str]) x
showAnnotations :: (HasPart' a, Ord (Part a), HasText a) => Score a -> Score a
showAnnotations = showAnnotations' ":"
showAnnotations' :: (HasPart' a, Ord (Part a), HasText a) => String -> Score a -> Score a
showAnnotations' prefix = withAnnotations (flip $ \s -> foldr (text . (prefix ++ )) s)
withAnnotations :: ([String] -> Score a -> Score a) -> Score a -> Score a
withAnnotations f = withMeta (f . getAnnotation)