I am new to programming and Python, but a lot of my current research concerns extracting data from musicxml files. I have a piece of music and want to extract the number of accidentals that occur in a piece that do not form part of the key signature. I have no idea how to do this, please could someone help? Here's an example of one measure from the musicxml file I am looking at:
<measure number='19'>
<print new-system='no'/>
<note>
<rest/>
<duration>768</duration>
<voice>1</voice>
<type>quarter</type>
<staff>1</staff>
</note>
<backup>
<duration>768</duration>
</backup>
<note>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>2304</duration>
<tie type='start'/>
<voice>2</voice>
<type>half</type>
<dot/>
<staff>1</staff>
<notations>
<tied type='start'/>
<slur type='stop' number='1'/>
</notations>
</note>
<backup>
<duration>1536</duration>
</backup>
<note>
<pitch>
<step>E</step>
<alter>3</alter>
<octave>3</octave>
</pitch>
<duration>1536</duration>
<voice>1</voice>
<type>half</type>
<staff>1</staff>
</note>
<note>
<chord/>
<pitch>
<step>G</step>
<alter>4</alter>
<octave>3</octave>
</pitch>
<duration>1536</duration>
<voice>1</voice>
<type>half</type>
<staff>1</staff>
</note>
<backup>
<duration>2304</duration>
</backup>
<note>
<pitch>
<step>E</step>
<octave>2</octave>
</pitch>
<duration>2304</duration>
<voice>5</voice>
<type>half</type>
<dot/>
<staff>2</staff>
</note>
</measure>
The problem translates to searching through the musicxml file and counting the number of times
<pitch>
<step>*</step>
<alter>**</alter>
...
occurs where * is not (F or C) and also finding the number of times that * is F or C and is not followed by the <alter>
tag.
Any help or advice would be much appreciated!