-- $Date: 2004/03/04 05:12:49 $
-- $Revision: 1.6 $
-- $Author: jcrocholl $

with Ada.Tags;
with Writers; use Writers;
with Readers; use Readers;
with Token_Readers; use Token_Readers;

with Notations.Slurs; use Notations.Slurs;
with Notations.Simple; use Notations.Simple;
with Notations.Articulations; use Notations.Articulations;

with Notations.Slurs.MusicXML; use Notations.Slurs.MusicXML;
with Notations.Simple.MusicXML; use Notations.Simple.MusicXML;
with Notations.Articulations.MusicXML; use Notations.Articulations.MusicXML;

with Placements; use Placements;

package body Notations.MusicXML is

   -- Read notation data from an XML reader.
   function Read_Notation
     (XML : access XML_Reader-- Use this XML reader.
     return Notation_Access    -- The newly created notation.
   is
      use Notations.Simple;
   begin
      if not Context_Is(XML, "slur") then
         Exit_Tag(XML);
      end if;

      if Context_Is(XML, "slur") then
         return Notation_Access(Read_Slur(XML));
      elsif Context_Is(XML, "arpeggiate") then
         return Notation_Access(Create(Arpeggiate));
      else
         XML_Expect_Error(XML, "/notations", "slur");
      end if;
      return null;
   end Read_Notation;

   -- Write notation data to an XML writer.
   procedure Write_Notation
     (XML  : access XML_Writer;          -- Use this XML writer.
      This : access Notation'Class-- Write this notation.
      Arti : in out Boolean)             -- Inside articulations?
   is
      -- use type Ada.Tags.Tag;
      -- Tag : Ada.Tags.Tag := This.all'Tag;
      Tag : String := Ada.Tags.External_Tag(This.all'Tag);
   begin
      if Tag = Articulation_Tag and not Arti then
         Start_Element(XML, "articulations");
         Arti := True;
      end if;

      if Arti and Tag /= Articulation_Tag then
         Close_Element(XML, "articulations");
         Arti := False;
      end if;

      if Tag = Slur_Tag then
         Write_Slur(XML, Slur_Access(This));
      elsif Tag = Simple_Tag then
         Write_Simple(XML, Simple_Access(This));
      elsif Tag = Articulation_Tag then
         Write_Articulation(XML, Articulation_Access(This));
      else
         Unknown_Tag_Error("Write_Notation", Tag);
      end if;
   end Write_Notation;

end Notations.MusicXML;