我对编程和Python还不熟悉,但我目前的很多研究都是从musicxml文件中提取数据。我有一段音乐,想提取出一段音乐中发生的不属于密钥签名一部分的意外事件的数量。我不知道该怎么办?下面是我正在查看的musicxml文件中的一个度量的示例:
<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>
问题转化为搜索musicxml文件并计算次数
^{pr2}$在*不是(F或C)的情况下发生,并查找*是F或C且后面不跟<alter>
标记的次数。在
任何帮助或建议将不胜感激!在
对于Python的细节我无能为力,但我有两个与MusicXML相关的建议:
1)您的问题是以意外事件的形式表达的,但是您的代码集中在alter元素上。alter元素用于改变音调;意外元素用于书写意外。你在找哪一个?在MusicXML中,声音大小和符号形式之间的二元性是很常见的,这对于研究MusicXML文件非常重要。在
2)如果您不熟悉编程和Python,我建议您使用一个为音乐学专门设计的高级工具箱,并提供良好的MusicXML支持。你将把问题域移到一个更高的层次,这样你的进度会更快。最明显的选择是music21工具包,它也是用Python编写的。在http://web.mit.edu/music21/有更多信息。在
祝你的研究好运!在
python有一个xml.dom模块,允许您快速浏览xml文件。如果您有任何web开发经验,它非常类似于javascript的文档对象模型。在
输出:
^{pr2}$相关问题 更多 >
编程相关推荐