本文整理汇总了Python中pymei.MeiDocument.getElementsByName方法的典型用法代码示例。如果您正苦于以下问题:Python MeiDocument.getElementsByName方法的具体用法?Python MeiDocument.getElementsByName怎么用?Python MeiDocument.getElementsByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.MeiDocument
的用法示例。
在下文中一共展示了MeiDocument.getElementsByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_elementsbyname
# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import getElementsByName [as 别名]
def test_elementsbyname(self):
mei = MeiElement("mei")
mus = MeiElement("music")
body = MeiElement("body")
staff = MeiElement("staff")
staff2 = MeiElement("staff")
n1 = MeiElement("note")
n2 = MeiElement("note")
n3 = MeiElement("note")
n4 = MeiElement("note")
mei.addChild(mus)
mus.addChild(body)
body.addChild(staff)
body.addChild(staff2)
staff.addChild(n1)
staff.addChild(n2)
staff.addChild(n3)
staff2.addChild(n4)
doc = MeiDocument()
doc.root = mei
notes = doc.getElementsByName("note")
self.assertEqual(4, len(notes))
rests = doc.getElementsByName("rest")
self.assertEqual(0, len(rests))
n5 = MeiElement("note")
staff2.addChild(n5)
notes_new = doc.getElementsByName('note')
self.assertEqual(5, len(notes_new))
示例2: __init__
# 需要导入模块: from pymei import MeiDocument [as 别名]
# 或者: from pymei.MeiDocument import getElementsByName [as 别名]
#.........这里部分代码省略.........
Calculate the bounding box of the provided measures
by calculating the min and max of the bounding boxes
of the staves which compose the measure.
'''
# for each measure
for m in measures:
staff_measure_zones = []
min_ulx = sys.maxint
min_uly = sys.maxint
max_lrx = -sys.maxint - 1
max_lry = -sys.maxint - 1
for s in m.getChildrenByName('staff'):
# have to skip # at the beginning of the id ref since using URIs
s_zone = self.meidoc.getElementById(s.getAttribute('facs').value[1:])
ulx = int(s_zone.getAttribute('ulx').value)
if ulx < min_ulx:
min_ulx = ulx
uly = int(s_zone.getAttribute('uly').value)
if uly < min_uly:
min_uly = uly
lrx = int(s_zone.getAttribute('lrx').value)
if lrx > max_lrx:
max_lrx = lrx
lry = int(s_zone.getAttribute('lry').value)
if lry > max_lry:
max_lry = lry
m_zone = self._create_zone(min_ulx, min_uly, max_lrx, max_lry)
m.addAttribute('facs', '#'+m_zone.getId())
surface = self.meidoc.getElementsByName('surface')[0]
surface.addChild(m_zone)
def _create_header(self, rodan_version='0.1'):
'''
Create a meiHead element
'''
mei_head = MeiElement('meiHead')
today = datetime.date.today().isoformat()
app_name = 'RODAN/barlineFinder'
# file description
file_desc = MeiElement('fileDesc')
title_stmt = MeiElement('titleStmt')
title = MeiElement('title')
resp_stmt = MeiElement('respStmt')
corp_name = MeiElement('corpName')
corp_name.setValue('Distributed Digital Music Archives and Libraries Lab (DDMAL)')
title_stmt.addChild(title)
title_stmt.addChild(resp_stmt)
resp_stmt.addChild(corp_name)
pub_stmt = MeiElement('pubStmt')
resp_stmt = MeiElement('respStmt')
corp_name = MeiElement('corpName')
corp_name.setValue('Distributed Digital Music Archives and Libraries Lab (DDMAL)')
pub_stmt.addChild(resp_stmt)
resp_stmt.addChild(corp_name)
mei_head.addChild(file_desc)