当前位置: 首页>>代码示例>>Python>>正文


Python MeiElement.addChild方法代码示例

本文整理汇总了Python中pymei.MeiElement.addChild方法的典型用法代码示例。如果您正苦于以下问题:Python MeiElement.addChild方法的具体用法?Python MeiElement.addChild怎么用?Python MeiElement.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymei.MeiElement的用法示例。


在下文中一共展示了MeiElement.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: move_recon_staves

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
def move_recon_staves(recon_staves, al):
	"""Move reconstructed staves to their proper place within
	the <app> element created inplace of the original (placeholder) staff.
	"""
	def orig(staff_n, alternates_list):
		"""Return the number of staff that the given staff
		is a reconstruction of.
		"""
		for i in alternates_list:
			if i[0] == staff_n:
				return i[2]

	def resp(staff_n, alternates_list):
		for i in alternates_list:
			if i[0] == staff_n:
				return i[3]

	for staff in recon_staves:
		staff_n = staff.getAttribute('n').getValue()
		parent_measure = staff.getParent()
		sibling_apps = parent_measure.getChildrenByName('app')
		for app in sibling_apps:
			# If it's the right <app> element -- that is,
			# the number matches with the original staff
			# for this reconstruction
			if orig(staff_n, al) == app.getAttribute('n').getValue():
				new_rdg = MeiElement('rdg')
				# Number <rdg> with old staff number
				new_rdg.addAttribute('n', staff_n)
				# Add responsibility to new reading element
				new_rdg.addAttribute('resp', '#' + resp(staff_n, al))
				app.addChild(new_rdg)
				new_rdg.addChild(staff)
				parent_measure.removeChild(staff)
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:36,代码来源:reconstructions.py

示例2: test_getpositionindocument

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_getpositionindocument(self):
        m = MeiElement("mei")
        m1 = MeiElement("music")
        musicid = m1.id
        b1 = MeiElement("body")
        s1 = MeiElement("staff")
        n1 = MeiElement("note")
        noteid = n1.id
        n2 = MeiElement("note")
        n3 = MeiElement("note")
        n4 = MeiElement("note")
        note4id = n4.id

        m.addChild(m1)
        m1.addChild(b1)
        b1.addChild(s1)
        s1.addChild(n1)
        s1.addChild(n2)
        s1.addChild(n3)

        doc = MeiDocument()
        doc.root = m

        self.assertEqual(4, n1.getPositionInDocument())

        # an unattached element will return -1
        self.assertEqual(-1, n4.getPositionInDocument())
开发者ID:gburlet,项目名称:libmei,代码行数:29,代码来源:meielement_test.py

示例3: insert_puncta

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def insert_puncta(self, nid, bboxes):
        '''
        Insert a punctum for each note in the reference neume
        before the reference neume in the MEI document.
        '''
        ref_neume = self.mei.getElementById(nid)
        parent = ref_neume.getParent()

        # get underlying notes
        notes = ref_neume.getDescendantsByName("note")
        nids = []
        for n, bb in zip(notes, bboxes):
            punctum = MeiElement("neume")
            punctum.addAttribute("name", "punctum")
            nc = MeiElement("nc")
            nc.addChild(n)
            punctum.addChild(nc)

            # add generated punctum id to return to client
            nids.append(punctum.getId())

            # add facs data for the punctum
            zone = self.get_new_zone(bb["ulx"], bb["uly"], bb["lrx"], bb["lry"])
            self.add_zone(punctum, zone)

            # insert the punctum before the reference neume
            parent.addChildBefore(ref_neume, punctum)

        return nids
开发者ID:sequoiar,项目名称:Neon.js,代码行数:31,代码来源:api.py

示例4: _redistribute

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def _redistribute(self):
        '''
        Redistribute notes in the measures to match the 4/4 time signature
        '''
        
        layers = self.mei_doc.getElementsByName('layer')
        note_events = []
        for l in layers:
            note_events.extend(l.getChildren())

        # remove all measures
        for m in self.mei_doc.getElementsByName('measure'):
            m.getParent().removeChild(m)
        
        section = self.mei_doc.getElementsByName('section')[0]
        score_def = self.mei_doc.getElementsByName('scoreDef')[0]
        meter_count = int(score_def.getAttribute('meter.count').value)

        # insert the note events again
        note_container = None
        for i, note_event in enumerate(note_events):
            if i % meter_count == 0:
                measure = MeiElement('measure')
                measure.addAttribute('n', str(int(i/meter_count + 1)))
                staff = MeiElement('staff')
                staff.addAttribute('n', '1')
                layer = MeiElement('layer')
                layer.addAttribute('n', '1')
                section.addChild(measure)
                measure.addChild(staff)
                staff.addChild(layer)
                note_container = layer

            note_container.addChild(note_event)
开发者ID:gburlet,项目名称:robotaba,代码行数:36,代码来源:guitarify.py

示例5: test_object_equality

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_object_equality(self):
        el1 = MeiElement("note")
        el2 = MeiElement("accid")

        el1.addChild(el2)

        self.assertEqual(el1, el2.parent)
开发者ID:lpugin,项目名称:libmei,代码行数:9,代码来源:meielement_test.py

示例6: test_removechild

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
 def test_removechild(self):
     p = MeiElement("layer")
     el1 = MeiElement("note")
     el2 = MeiElement("note")
     
     p.addChild(el1)
     p.addChild(el2)
     
     self.assertEqual(2, len(p.children))
     p.removeChild(el1)
     self.assertEqual(1, len(p.children))
开发者ID:lpugin,项目名称:libmei,代码行数:13,代码来源:meielement_test.py

示例7: test_getnextmeasure

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
 def test_getnextmeasure(self):
     section = MeiElement('section')
     m1 = MeiElement('measure')
     sb = MeiElement('sb')
     m2 = MeiElement('measure')
     
     section.addChild(m1)
     section.addChild(sb)
     section.addChild(m2)
     
     self.assertEqual(utilities.get_next_measure(m1), m2)
     self.assertEqual(utilities.get_next_measure(m2), None)
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:14,代码来源:unit_test.py

示例8: test_children

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_children(self):
        el1 = MeiElement("mei")
        el2 = MeiElement("meiHead")
        el3 = MeiElement("music")

        self.assertEqual(0, len(el1.children))

        el1.addChild(el2)
        el1.addChild(el3)

        self.assertEqual("mei", el2.parent.name)
        self.assertTrue(el1.hasChildren("music"))
开发者ID:lpugin,项目名称:libmei,代码行数:14,代码来源:meielement_test.py

示例9: test_deleteallchildren

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_deleteallchildren(self):
        p = MeiElement("layer")
        el1 = MeiElement("note")
        el2 = MeiElement("note")
        el3 = MeiElement("chord")

        p.addChild(el1)
        p.addChild(el2)
        p.addChild(el3)

        self.assertEqual(3, len(p.children))
        p.deleteAllChildren()
        self.assertEqual(0, len(p.children))
开发者ID:lpugin,项目名称:libmei,代码行数:15,代码来源:meielement_test.py

示例10: change_arranger_element

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
def change_arranger_element(MEI_tree):
	"""Changes all occurrence of the <arranger> tag to <editor>"""
	all_arranger = MEI_tree.getDescendantsByName('arranger')
	for arranger in all_arranger:
		parent = arranger.getParent()
		editor = MeiElement('editor')
		arranger_children = arranger.getChildren()
		arranger_value = arranger.getValue()
		for child in arranger_children:
			editor.addChild(child)
		editor.setValue(arranger_value)
		parent.addChild(editor)
		parent.removeChild(arranger)
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:15,代码来源:arranger.py

示例11: test_get_descendants

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_get_descendants(self):

        measure = MeiElement('measure')
        layer   = MeiElement('layer')
        note1   = MeiElement('note')
        note2   = MeiElement('note')
        note3   = MeiElement('note')
        rest1   = MeiElement('rest')
        rest2   = MeiElement('rest')

        note1.addAttribute('pname', 'c')
        note1.addAttribute('oct', '4')
        note1.addAttribute('dur', 'breve')
        note2.addAttribute('pname', 'd')
        note2.addAttribute('dur', '1')
        note3.addAttribute('pname', 'd')
        note3.addAttribute('dur', '2')
        rest1.addAttribute('dur', '1')
        rest2.addAttribute('dur', '2')

        layer.addChild(note1)
        layer.addChild(note2)
        layer.addChild(note3)
        layer.addChild(rest1)
        layer.addChild(rest2)
        measure.addChild(layer)

        self.assertEqual(3, len(utilities.get_descendants(measure, 'note')))
        self.assertEqual(5, len(utilities.get_descendants(measure, 'note rest')))
        self.assertEqual(1, len(utilities.get_descendants(measure, 'note[dur=1]')))
        self.assertEqual(1, len(utilities.get_descendants(measure, 'note[pname=d,dur=1]')))
        self.assertEqual(4, len(utilities.get_descendants(measure, 'note[pname=d,dur=1] note[pname=c,oct=4,dur=breve] rest[dur=2] layer')))
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:34,代码来源:unit_test.py

示例12: test_peers

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_peers(self):
        m1 = MeiElement("music")
        musicid = m1.id
        b1 = MeiElement("body")
        s1 = MeiElement("staff")
        n1 = MeiElement("note")
        noteid = n1.id
        n2 = MeiElement("note")
        n3 = MeiElement("note")
        n4 = MeiElement("note")
        note4id = n4.id

        m1.addChild(b1)
        b1.addChild(s1)
        s1.addChild(n1)
        s1.addChild(n2)
        s1.addChild(n3)
        s1.addChild(n4)

        res = n2.getPeers()

        self.assertEqual(4, len(res))

        self.assertEqual(noteid, res[0].id)
        self.assertEqual(note4id, res[3].id)
开发者ID:gburlet,项目名称:libmei,代码行数:27,代码来源:meielement_test.py

示例13: test_changechildvalue

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_changechildvalue(self):
        """ Check if we can replace an attribute value in-place"""
        p = MeiElement("layer")
        el1 = MeiElement("note")
        el2 = MeiElement("note")

        p.addChild(el1)
        p.addChild(el2)

        el1.addAttribute("pname", "c")

        self.assertEqual("c", p.children[0].getAttribute("pname").value)
        el1.getAttribute("pname").value = "d"
        self.assertEqual("d", p.children[0].getAttribute("pname").value)
开发者ID:lpugin,项目名称:libmei,代码行数:16,代码来源:meielement_test.py

示例14: test_exportcomment

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_exportcomment(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"

        doc.root = root

        comment = MeiElement("_comment")
        comment.value = "comment"
        comment.tail = "t"

        root.addChild(comment)
        expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mei xml:id=\"myid\" xmlns=\"http://www.music-encoding.org/ns/mei\" meiversion=\"2013\">\n\t<!--comment-->t</mei>\n"
        ret = documentToText(doc)
        self.assertEqual(expected, ret)
开发者ID:AFFogarty,项目名称:libmei,代码行数:17,代码来源:xmlexport_test.py

示例15: test_removechildrenbyname

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addChild [as 别名]
    def test_removechildrenbyname(self):
        p = MeiElement("layer")
        el1 = MeiElement("note")
        el2 = MeiElement("note")
        el3 = MeiElement("chord")

        p.addChild(el1)
        p.addChild(el2)
        p.addChild(el3)

        self.assertEqual(3, len(p.children))
        p.removeChildrenWithName("note")
        self.assertEqual(1, len(p.children))

        # check that el1 was not actually deleted
        self.assertTrue(el1)
开发者ID:lpugin,项目名称:libmei,代码行数:18,代码来源:meielement_test.py


注:本文中的pymei.MeiElement.addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。