-- |
-- Maintainer : [email protected] -- Stability : experimental
-- Portability: HaXML
--module Text .XML.MusicXML.Identity where import Text .XML.MusicXML.Common import Text .XML.HaXml .Types (Content ) import Control .Monad (MonadPlus (. .))
import Prelude (Maybe, Monad (. .), Functor (. .), Show , Eq , (·), (++))
The identify DTD module contains the identification element and its children, containing metadata about a score.
Identification contains basic metadata about the score. It includes the information in MuseData headers that may apply at a score-wide, movement-wide, or part-wide level. The creator, rights, source, and relation elements are based on Dublin Core.
-- * Identification -- |
type Identification = ([Creator ], [Rights ], Maybe Encoding, Maybe Source, [Relation ], Maybe Miscellaneous)
-- |
read Identification :: Eq i ⇒ STM Result [Content i ] Identification read Identification = do
y ← read ELEMENT "identification"
read 6 (read LIST read Creator ) (read LIST read Rights) (read MAYBE read Encoding ) (read MAYBE read Source) (read LIST read Relation) (read MAYBE read Miscellaneous) (childs y )
-- |
show Identification :: Identification → [Content ()]
show Identification (a, b, c, d , e, f ) =
show ELEMENT "identification" [ ]
(show LIST show Creator a ++ show LIST show Rights b ++
show MAYBE show Encoding c ++ show MAYBE show Source d ++ show LIST show Relation e ++ show MAYBE show Miscellaneous f ) -- |
update Identification :: ([Software ], Encoding Date) → Identification → Identification update Identification x (a, b, c, d , e, f ) = (a, b, fmap (update Encoding x ) c, d , e, f )
The creator element is borrowed from Dublin Core. It is used for the creators of the score. The type attribute is used to distinguish different creative contributions. Thus, there can be multiple creators within an identification. Standard type values are composer, lyricist, and arranger. Other type values may be used for different types of creative roles. The type attribute should usually be used even if there is just a single creator element. The MusicXML format does not use the creator / contributor distinction from Dublin Core.
-- ** Creator -- |
type Creator = (Maybe CDATA, PCDATA) -- |
read Creator :: Eq i ⇒ STM Result [Content i ] Creator read Creator = do
y ← read ELEMENT "creator"
y1 ← read 1 (read IMPLIED "type" read CDATA) (attributes y) y2 ← read 1 read PCDATA (childs y )
return (y1 , y2 ) -- |
show Creator :: Creator → [Content ()]
show Creator (a, b) =
show ELEMENT "creator" (show IMPLIED "type" show CDATA a) (show PCDATA b)
Rights is borrowed from Dublin Core. It contains copyright and other intellectual property notices.
Words, music, and derivatives can have different types, so multiple rights tags with different type attributes are supported. Standard type values are music, words, and arrangement, but other types may be used.
The type attribute is only needed when there are multiple rights elements.
-- ** Rights -- |
type Rights = (Maybe CDATA, CDATA) -- |
read Rights :: Eq i ⇒ STM Result [Content i ] Rights read Rights = do
y ← read ELEMENT "rights"
y1 ← read 1 (read IMPLIED "type" read CDATA) (attributes y) y2 ← read 1 read PCDATA (childs y )
return (y1 , y2 ) -- |
show Rights :: Rights → [Content ()]
show Rights (a, b) =
show ELEMENT "rights" (show IMPLIED "type" show CDATA a) (show PCDATA b)
Encoding contains information about who did the digital encoding, when, with what software, and in what aspects. Standard type values for the encoder element are music, words, and arrangement, but other types may be used. The type attribute is only needed when there are multiple encoder elements.
The supports element indicates if the encoding supports a particular MusicXML element. This is recommended for elements like beam, stem, and accidental, where the absence of an element is ambiguous if you do not know if the encoding supports that element. For Version 2.0, the supports element is expanded to allow programs to indicate support for particular attributes or particular values. This lets applications communicate, for example, that all system and/or page breaks are contained in the MusicXML file.
-- ** Encoding -- |
type Encoding = [Encoding ] -- |
read Encoding :: Eq i ⇒ STM Result [Content i ] Encoding read Encoding = do
y ← read ELEMENT "encoding"
read 1 (read LIST read Encoding ) (childs y ) -- |
show Encoding :: Encoding → [Content ()]
show Encoding a = show ELEMENT "encoding" [ ] (show LIST show Encoding a) -- |
update Encoding :: ([Software ], Encoding Date) → Encoding → Encoding update Encoding (s, d ) = (Encoding 1 d ) : (fmap Encoding 3 s)
-- |
data Encoding = Encoding 1 Encoding Date
| Encoding 2 Encoder
| Encoding 3 Software
| Encoding 4 Encoding Description
| Encoding 5 Supports deriving (Eq , Show ) -- |
read Encoding :: Eq i ⇒ STM Result [Content i ] Encoding read Encoding =
(read Encoding Date >>= return · Encoding 1 ) ‘mplus‘
(read Encoder >>= return · Encoding 2 ) ‘mplus‘
(read Software >>= return · Encoding 3 ) ‘mplus‘
(read Encoding Description >>= return · Encoding 4 ) ‘mplus‘
(read Supports >>= return · Encoding 5 ) -- |
show Encoding :: Encoding → [Content ()]
show Encoding (Encoding 1 a) = show Encoding Date a show Encoding (Encoding 2 a) = show Encoder a show Encoding (Encoding 3 a) = show Software a
show Encoding (Encoding 4 a) = show Encoding Description a show Encoding (Encoding 5 a) = show Supports a
-- |
type Encoding Date = YYYY MM DD -- |
read Encoding Date :: Eq i ⇒ STM Result [Content i ] Encoding Date read Encoding Date = do
y ← read ELEMENT "encoding-date"
read 1 (read YYYY MM DD ) (childs y ) -- |
show Encoding Date :: Encoding Date → [Content ()]
show Encoding Date a =
show ELEMENT "encoding-date" [ ] (show YYYY MM DD a) -- |
type Encoder = (Maybe CDATA, PCDATA) -- |
read Encoder :: Eq i ⇒ STM Result [Content i ] Encoder read Encoder = do
y ← read ELEMENT "encoder"
y1 ← read 1 (read IMPLIED "type" read CDATA) (attributes y) y2 ← read 1 read PCDATA (childs y )
return (y1 , y2 ) -- |
show Encoder :: Encoder → [Content ()]
show Encoder (a, b) =
show ELEMENT "encoder" (show IMPLIED "type" show CDATA a) (show PCDATA b)
-- |
type Software = PCDATA -- |
read Software :: Eq i ⇒ STM Result [Content i ] Software read Software = do
y ← read ELEMENT "software"
read 1 read PCDATA (childs y ) -- |
show Software :: Software → [Content ()]
show Software a = show ELEMENT "software" [ ] (show PCDATA a) -- |
type Encoding Description = PCDATA -- |
read Encoding Description :: STM Result [Content i ] Encoding Description read Encoding Description = do
y ← read ELEMENT "encoding-description"
read 1 read PCDATA (childs y ) -- |
show Encoding Description :: Encoding Description → [Content ()]
show Encoding Description a =
show ELEMENT "encoding-description" [ ] (show PCDATA a) -- |
type Supports = ((Yes No, CDATA, Maybe CDATA, Maybe CDATA), ()) -- |
read Supports :: Eq i ⇒ STM Result [Content i ] Supports read Supports = do
y ← read ELEMENT "supports"
y1 ← read 4 (read REQUIRED "type" read Yes No) (read REQUIRED "element" read CDATA) (read IMPLIED "attribute" read CDATA)
(read IMPLIED "value" read CDATA) (attributes y) return (y1 , ())
-- |
show Supports :: Supports → [Content ()]
show Supports ((a, b, c, d ), ) =
show ELEMENT "supports" (show REQUIRED "type" show Yes No a ++ show REQUIRED "element" show CDATA b ++
show IMPLIED "attribute" show CDATA c ++ show IMPLIED "value" show CDATA d ) [ ]
The source for the music that is encoded. This is similar to the Dublin Core source element.
-- ** Source -- |
type Source = PCDATA -- |
read Source :: STM Result [Content i ] Source read Source = do
y ← read ELEMENT "source"
read 1 read PCDATA (childs y ) -- |
show Source :: Source → [Content ()]
show Source a = show ELEMENT "source" [ ] (show PCDATA a)
A related resource for the music that is encoded. This is similar to the Dublin Core relation element.
Standard type values are music, words, and arrangement, but other types may be used.
-- ** Relation -- |
type Relation = (Maybe CDATA, CDATA) -- |
read Relation :: STM Result [Content i ] Relation read Relation = do
y ← read ELEMENT "relation"
y1 ← read 1 (read IMPLIED "type" read CDATA) (attributes y) y2 ← read 1 read PCDATA (childs y )
return (y1 , y2 ) -- |
show Relation :: Relation → [Content ()]
show Relation (a, b) =
show ELEMENT "relation" (show IMPLIED "type" show CDATA a) (show PCDATA b)
If a program has other metadata not yet supported in the MusicXML format, it can go in the miscel-laneous area.
-- ** Miscellaneous -- |
type Miscellaneous = [Miscellaneous Field ] -- |
read Miscellaneous :: Eq i ⇒ STM Result [Content i ] Miscellaneous read Miscellaneous = do
y ← read ELEMENT "miscellaneous"
read 1 (read LIST read Miscellaneous Field ) (childs y ) -- |
show Miscellaneous :: Miscellaneous → [Content ()]
show Miscellaneous a =
show ELEMENT "miscellaneous" [ ] (show LIST show Miscellaneous Field a) -- |
type Miscellaneous Field = (CDATA, PCDATA) -- |
read Miscellaneous Field :: STM Result [Content i ] Miscellaneous Field read Miscellaneous Field = do
y ← read ELEMENT "miscellaneous-field"
y1 ← read 1 (read REQUIRED "name" read CDATA) (attributes y) y2 ← read 1 read PCDATA (childs y )
return (y1 , y2 ) -- |
show Miscellaneous Field :: Miscellaneous Field → [Content ()]
show Miscellaneous Field (a, b) =
show ELEMENT "miscellaneous-field"
(show REQUIRED "name" show CDATA a) (show PCDATA b)