-- $Date: 2004/02/14 06:20:08 $
-- $Revision: 1.4 $
-- $Author: jcrocholl $

with Token_Readers; use Token_Readers;
with Integer_Strings; use Integer_Strings;

package body Midi_Instruments.MusicXML is

   -- Read midi instrument data from an XML reader.
   function Read_Midi_Instrument
     (XML : access XML_Reader)     -- Use this XML reader.
     return Midi_Instrument_Access -- The newly created midi instrument.
   is
      Channel : Natural;
      Program : Natural;
   begin
      Assert_Attribute_Name(XML, "id");
      Read_Attribute_Value(XML);
      Exit_Tag(XML);
      Channel := To_Number(Read_Element_Data(XML, "midi-channel"));
      Program := To_Number(Read_Element_Data(XML, "midi-program"));
      return Create(Get_Token(XML), Channel, Program);
   end Read_Midi_Instrument;

   -- Write midi instrument data to an XML writer.
   procedure Write_Midi_Instrument
     (XML  : access XML_Writer;      -- Use this XML writer.
      This : access Midi_Instrument-- Write this midi instrument.
   is
   begin
      Start_Element(XML, "midi-instrument", "id", Get_ID(This));
      Write_Element(XML, "midi-channel", To_String(Get_Channel(This)));
      Write_Element(XML, "midi-program", To_String(Get_Program(This)));
      Close_Element(XML, "midi-instrument");
   end Write_Midi_Instrument;

end Midi_Instruments.MusicXML;