-- Measure Attributes
pAttr
  = xpElem "attributes" $ wAttr
    pdivs -- Divisions
    pkey  -- Key
    ptime -- Time
    pclef -- Clef
  where pdivs  = maySelNodeAndPickle "divisions"            -- Divisions per beat

        pkey   = xpOption $ xpElem "key" (wKey pfif pmode)  :: PU (Maybe MXKey)
        pfif   = selNodeAndPickle "fifths"                  -- Key Fifths     
        pmode  = selNodeAndPickle "mode"                    -- Key Mode       

        ptime  = xpOption $
                 xpElem "time" (wTime pbeats pbtyp pattr)   :: PU (Maybe MXTime)       
        pbeats = selNodeAndPickle "beats"                   -- Time Beats per measure
        pbtyp  = selNodeAndPickle "beat-type"               -- Time Beat Division
        pattr  = xpOption $ xpWrap (read, show) $           -- Time Annotation
                 xpAttr "symbol" xpText

        pclef  = xpOption $
                 xpElem "clef" (wClef pcsign pcline pcalt)   :: PU (Maybe MXClef)       
        pcsign = selNodeAndPickle "sign"                     -- Clef Sign   
        pcline = xpDefault def $ selNodeAndPickle "line"     -- Clef Line             -- BUG: Should use xpWrap so (NoneClef,0) to MXML doesn't include line # 0
        pcalt  = maySelNodeAndPickle "clef-octave-change"    -- Clef octave change

        -- Wrap functions. Converts tuple to type and vice versa
        wAttr a b c d = xpWrap (uncurry4 MXAttr, \(MXAttr divs key time clef) -> (divs,key,time,clef)) $ xp4Tuple a b c d
        wKey a b = xpWrap (uncurry MXKey, \ (MXKey fifths mode) -> (fifths, mode)) $ xpPair a b
        wTime a b c = xpWrap (uncurry3 MXTime, \(MXTime beats beatType anno) -> (beats, beatType, anno)) $ xpTriple a b c
        wClef a b c = xpWrap (uncurry3 MXClef, \(MXClef sign line octalt) -> (sign, line, octalt)) $ xpTriple a b c

        maySelNodeAndPickle a = xpOption $ selNodeAndPickle a

-- Measure Notes
pAttr
  = xpElem "attributes" $ wAttr
    pdivs -- Divisions
    pkey  -- Key
    ptime -- Time
    pclef -- Clef
  where pdivs  = maySelNodeAndPickle "divisions"            -- Divisions per beat

        pkey   = xpOption $ xpElem "key" (wKey pfif pmode)  :: PU (Maybe MXKey)
        pfif   = selNodeAndPickle "fifths"                  -- Key Fifths     
        pmode  = selNodeAndPickle "mode"                    -- Key Mode       

        ptime  = xpOption $
                 xpElem "time" (wTime pbeats pbtyp pattr)   :: PU (Maybe MXTime)       
        pbeats = selNodeAndPickle "beats"                   -- Time Beats per measure
        pbtyp  = selNodeAndPickle "beat-type"               -- Time Beat Division
        pattr  = xpOption $ xpWrap (read, show) $           -- Time Annotation
                 xpAttr "symbol" xpText

        pclef  = xpOption $
                 xpElem "clef" (wClef pcsign pcline pcalt)   :: PU (Maybe MXClef)       
        pcsign = selNodeAndPickle "sign"                     -- Clef Sign   
        pcline = xpDefault def $ selNodeAndPickle "line"     -- Clef Line             -- BUG: Should use xpWrap so (NoneClef,0) to MXML doesn't include line # 0
        pcalt  = maySelNodeAndPickle "clef-octave-change"    -- Clef octave change

        -- Wrap functions. Converts tuple to type and vice versa
        wAttr a b c d = xpWrap (uncurry4 MXAttr, \(MXAttr divs key time clef) -> (divs,key,time,clef)) $ xp4Tuple a b c d
        wKey a b = xpWrap (uncurry MXKey, \ (MXKey fifths mode) -> (fifths, mode)) $ xpPair a b
        wTime a b c = xpWrap (uncurry3 MXTime, \(MXTime beats beatType anno) -> (beats, beatType, anno)) $ xpTriple a b c
        wClef a b c = xpWrap (uncurry3 MXClef, \(MXClef sign line octalt) -> (sign, line, octalt)) $ xpTriple a b c

        maySelNodeAndPickle a = xpOption $ selNodeAndPickle a

-- Measure Notes
pAttr
  = xpElem "attributes" $ wAttr
    pdivs -- Divisions
    pkey  -- Key
    ptime -- Time
    pclef -- Clef
  where pdivs  = maySelNodeAndPickle "divisions"            -- Divisions per beat

        pkey   = xpOption $ xpElem "key" (wKey pfif pmode)  :: PU (Maybe MXKey)
        pfif   = selNodeAndPickle "fifths"                  -- Key Fifths     
        pmode  = selNodeAndPickle "mode"                    -- Key Mode       

        ptime  = xpOption $
                 xpElem "time" (wTime pbeats pbtyp pattr)   :: PU (Maybe MXTime)       
        pbeats = selNodeAndPickle "beats"                   -- Time Beats per measure
        pbtyp  = selNodeAndPickle "beat-type"               -- Time Beat Division
        pattr  = xpOption $ xpWrap (read, show) $           -- Time Annotation
                 xpAttr "symbol" xpText

        pclef  = xpOption $
                 xpElem "clef" (wClef pcsign pcline pcalt)   :: PU (Maybe MXClef)       
        pcsign = selNodeAndPickle "sign"                     -- Clef Sign   
        pcline = xpDefault def $ selNodeAndPickle "line"     -- Clef Line             -- BUG: Should use xpWrap so (NoneClef,0) to MXML doesn't include line # 0
        pcalt  = maySelNodeAndPickle "clef-octave-change"    -- Clef octave change

        -- Wrap functions. Converts tuple to type and vice versa
        wAttr a b c d = xpWrap (uncurry4 MXAttr, \(MXAttr divs key time clef) -> (divs,key,time,clef)) $ xp4Tuple a b c d
        wKey a b = xpWrap (uncurry MXKey, \ (MXKey fifths mode) -> (fifths, mode)) $ xpPair a b
        wTime a b c = xpWrap (uncurry3 MXTime, \(MXTime beats beatType anno) -> (beats, beatType, anno)) $ xpTriple a b c
        wClef a b c = xpWrap (uncurry3 MXClef, \(MXClef sign line octalt) -> (sign, line, octalt)) $ xpTriple a b c

        maySelNodeAndPickle a = xpOption $ selNodeAndPickle a

-- Measure Notes