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

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

with Music.Notes; use Music.Notes;
with Music.Backups; use Music.Backups;
with Music.Forwards; use Music.Forwards;
with Music.Directions; use Music.Directions;
with Music.Barlines; use Music.Barlines;

with Music.Notes.MusicXML; use Music.Notes.MusicXML;
with Music.Backups.MusicXML; use Music.Backups.MusicXML;
with Music.Forwards.MusicXML; use Music.Forwards.MusicXML;
with Music.Directions.MusicXML; use Music.Directions.MusicXML;
with Music.Barlines.MusicXML; use Music.Barlines.MusicXML;

package body Music.MusicXML is

   -- Read music data from an XML reader.
   function Read_Music
     (XML   : access XML_Reader-- Use this XML reader.
      Final : in String)         -- The current element's closing tag.
     return Music_Data_Access is -- The newly created music data.
   begin
      if Context_Is(XML, "note") then
         return Music_Data_Access(Read_Note(XML));
      elsif Context_Is(XML, "backup") then
         return Music_Data_Access(Read_Backup(XML));
      elsif Context_Is(XML, "forward") then
         return Music_Data_Access(Read_Forward(XML));
      elsif Context_Is(XML, "direction") then
         return Music_Data_Access(Read_Direction(XML));
      elsif Context_Is(XML, "barline") then
         return Music_Data_Access(Read_Barline(XML));
      else
         XML_Expect_Error(XML, Final,
           "note" / "backup" / "forward" / "direction" / "barline");
      end if;
      return null;
   end Read_Music;

   -- Write music data to an XML writer.
   procedure Write_Music
     (XML  : access XML_Writer;            -- Use this XML writer.
      This : access Music_Data'Class-- Write this music data.
   is
      Tag : String := External_Tag(This.All'Tag);
   begin
      if Tag = Note_Tag then
         Write_Note(XML, Note_Access(This));
      elsif Tag = Backup_Tag then
         Write_Backup(XML, Backup_Access(This));
      elsif Tag = Forward_Tag then
         Write_Forward(XML, Forward_Access(This));
      elsif Tag = Direction_Tag then
         Write_Direction(XML, Direction_Access(This));
      elsif Tag = Barline_Tag then
         Write_Barline(XML, Barline_Access(This));
      else
         Unknown_Tag_Error("Write_Music", Tag);
      end if;
   end Write_Music;

end Music.MusicXML;