Hosted by
|
with Integer_Strings; use Integer_Strings;
with Readers; use Readers;
with Token_Readers; use Token_Readers;
package body Pitches.MusicXML is
function Read_Pitch
(XML : access XML_Reader)
return Pitch_Access
is
Step : Step_Enum := C;
Alter : Integer := 0;
Octave : Integer := 4;
begin
while Descend(XML) loop
Exit_Tag(XML);
if Found(XML, "step") then
Step := To_Step_Enum(Read_Data(XML));
elsif Found(XML, "alter") then
Alter := To_Number(Read_Data(XML));
elsif Found(XML, "octave") then
Octave := To_Number(Read_Data(XML));
else
XML_Expect_Error(XML, "/pitch",
"step" / "octave");
end if;
Exit_Element(XML);
end loop;
Exit_Tag(XML);
return Create(Step, Alter, Octave);
end Read_Pitch;
procedure Write_Pitch
(XML : access XML_Writer;
This : access Pitch)
is
begin
Start_Element(XML, "pitch");
Write_Element(XML, "step", Get_Step(This)'Img);
if Get_Alter(This) /= 0 then
Write_Element(XML, "alter", To_String(Get_Alter(This)));
end if;
Write_Element(XML, "octave", To_String(Get_Octave(This)));
Close_Element(XML, "pitch");
end Write_Pitch;
end Pitches.MusicXML;
|