-- $Date: 2004/02/14 06:24:07 $
-- $Revision: 1.5 $
-- $Author: jcrocholl $

with Integer_Strings; use Integer_Strings;
with Enum_Strings; use Enum_Strings;
with Readers; use Readers;
with Token_Readers; use Token_Readers;
with Writers; use Writers;
with Indent_Writers; use Indent_Writers;

package body Notations.Slurs.MusicXML is

   -- Read slur data from an XML reader.
   function Read_Slur
     (XML : access XML_Reader-- Use this XML reader.
     return Slur_Access        -- The newly created slur.
   is
      use Placements;
      Slur_Type : Slur_Type_Enum;
      Placement : Placement_Enum := Default;
      Number    : Positive;
   begin
      while not End_Of_Tag(XML) loop
         Read_Attribute_Name(XML);
         if Found(XML, "type") then
            Read_Attribute_Value(XML);
            Slur_Type := To_Slur_Type_Enum(Get_Token(XML));
         elsif Found(XML, "placement") then
            Read_Attribute_Value(XML);
            Placement := To_Placement_Enum(Get_Token(XML));
         elsif Found(XML, "number") then
            Read_Attribute_Value(XML);
            Number := To_Number(Get_Token(XML));
         else
            XML_Expect_Error(XML, "",
              "type" / "placement" / "number");
         end if;
      end loop;
      Exit_Tag(XML);

      return Create(Slur_Type, Placement, Number);
   end Read_Slur;

   -- Write slur data to an XML writer.
   procedure Write_Slur
     (XML  : access XML_Writer-- Use this XML writer.
      This : access Slur)       -- Write this slur.
   is
   begin
      Write_Indent(XML);
      Start_Tag(XML, "slur");

      Write_Attribute(XML, "type", To_XML(Get_Slur_Type(This)'Img));

      if Get_Placement(This) /= Default then
         Write_Attribute(XML, "placement", To_XML(Get_Placement(This)'Img));
      end if;

      Write_Attribute(XML, "number", To_String(Get_Number(This)));

      Close_Tag(XML, "/");
      New_Line(XML);
   end Write_Slur;

end Notations.Slurs.MusicXML;