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


Python pymei.MeiDocument类代码示例

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


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

示例1: test_documentpointers

    def test_documentpointers(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")

        self.assertEqual(None, mei.document)
        mei.addChild(mus)
        self.assertEqual(None, mus.document)

        doc = MeiDocument()
        mus.addChild(body)
        doc.root = mei

        self.assertEqual(doc, mei.document)
        self.assertEqual(doc, mus.document)
        self.assertEqual(doc, body.document)

        self.assertEqual(None, staff.document)
        body.addChild(staff)
        self.assertEqual(doc, staff.document)
开发者ID:Breakend,项目名称:libmei,代码行数:25,代码来源:meidocument_test.py

示例2: test_elementsbyname

    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))
开发者ID:lpugin,项目名称:libmei,代码行数:34,代码来源:meidocument_test.py

示例3: test_getpositionindocument

    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,代码行数:27,代码来源:meielement_test.py

示例4: test_effective_meter

    def test_effective_meter(self):
        music   = MeiElement('music')
        body    = MeiElement('body')
        mdiv    = MeiElement('mdiv')
        score   = MeiElement('score')
        sctn    = MeiElement('section')
        scD1    = MeiElement('scoreDef')
        scD2    = MeiElement('scoreDef')
        stG1    = MeiElement('staffGrp')
        stG2    = MeiElement('staffGrp')
        stD1    = MeiElement('staffDef')
        stD2    = MeiElement('staffDef')

        m1      = MeiElement('measure')
        m2      = MeiElement('measure')
        l1      = MeiElement('layer')
        l2      = MeiElement('layer')
        s1      = MeiElement('staff')
        s2      = MeiElement('staff')

        mR1     = MeiElement('mRest')
        mR2     = MeiElement('mRest')

        scD1.addAttribute('meter.unit', '2')
        stD1.addAttribute('meter.count', '2')
        stD2.addAttribute('meter.count', '3')

        s1.addAttribute('n', '1')
        
        music.addChild(body)
        body.addChild(mdiv)
        mdiv.addChild(score)
        score.addChild(sctn)
        sctn.addChild(scD1)
        scD1.addChild(stG1)
        stG1.addChild(stD1)
        sctn.addChild(m1)
        m1.addChild(s1)
        s1.addChild(l1)
        l1.addChild(mR1)

        sctn.addChild(scD2)
        scD2.addChild(stG2)
        stG2.addChild(stD2)
        sctn.addChild(m2)
        m2.addChild(s2)
        s2.addChild(l2)
        l2.addChild(mR2)

        doc = MeiDocument()
        doc.setRootElement(music)

        meter1  = utilities.effective_meter(mR1)
        meter2  = utilities.effective_meter(mR2)

        self.assertEqual(meter1.count, '2')
        self.assertEqual(meter1.unit, '2')
        self.assertEqual(meter2.count, '3')
        self.assertEqual(meter2.unit, '2')
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:59,代码来源:unit_test.py

示例5: test_documentwritefailure

 def test_documentwritefailure(self):
     doc = MeiDocument()
     root = MeiElement("mei")
     root.id = "myid"
     doc.root = root
     with self.assertRaises(FileWriteFailureException) as cm:
         ret = XmlExport.meiDocumentToFile(doc, "C:/StupidPath")
     self.assertTrue(isinstance(cm.exception, FileWriteFailureException))
开发者ID:lpugin,项目名称:libmei,代码行数:8,代码来源:xmlexport_test.py

示例6: test_effective_meter

    def test_effective_meter(self):
        music = MeiElement("music")
        body = MeiElement("body")
        mdiv = MeiElement("mdiv")
        score = MeiElement("score")
        sctn = MeiElement("section")
        scD1 = MeiElement("scoreDef")
        scD2 = MeiElement("scoreDef")
        stG1 = MeiElement("staffGrp")
        stG2 = MeiElement("staffGrp")
        stD1 = MeiElement("staffDef")
        stD2 = MeiElement("staffDef")

        m1 = MeiElement("measure")
        m2 = MeiElement("measure")
        l1 = MeiElement("layer")
        l2 = MeiElement("layer")
        s1 = MeiElement("staff")
        s2 = MeiElement("staff")

        mR1 = MeiElement("mRest")
        mR2 = MeiElement("mRest")

        scD1.addAttribute("meter.unit", "2")
        stD1.addAttribute("meter.count", "2")
        stD2.addAttribute("meter.count", "3")

        s1.addAttribute("n", "1")
        music.addChild(body)
        body.addChild(mdiv)
        mdiv.addChild(score)
        score.addChild(sctn)
        sctn.addChild(scD1)
        scD1.addChild(stG1)
        stG1.addChild(stD1)
        sctn.addChild(m1)
        m1.addChild(s1)
        s1.addChild(l1)
        l1.addChild(mR1)

        sctn.addChild(scD2)
        scD2.addChild(stG2)
        stG2.addChild(stD2)
        sctn.addChild(m2)
        m2.addChild(s2)
        s2.addChild(l2)
        l2.addChild(mR2)

        doc = MeiDocument()
        doc.setRootElement(music)

        meter1 = utilities.effective_meter(mR1)
        meter2 = utilities.effective_meter(mR2)

        self.assertEqual(meter1.count, "2")
        self.assertEqual(meter1.unit, "2")
        self.assertEqual(meter2.count, "3")
        self.assertEqual(meter2.unit, "2")
开发者ID:RichardFreedman,项目名称:MEIMassaging,代码行数:58,代码来源:unit_test.py

示例7: test_exporttostring

    def test_exporttostring(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

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

示例8: test_dur_in_semibreves_mRests

    def test_dur_in_semibreves_mRests(self):
        music = MeiElement('music')
        body = MeiElement('body')
        mdiv = MeiElement('mdiv')
        score = MeiElement('score')
        sctn = MeiElement('section')
        scD1 = MeiElement('scoreDef')
        scD2 = MeiElement('scoreDef')
        stG1 = MeiElement('staffGrp')
        stG2 = MeiElement('staffGrp')
        stD1 = MeiElement('staffDef')
        stD2 = MeiElement('staffDef')

        m1 = MeiElement('measure')
        m2 = MeiElement('measure')
        l1 = MeiElement('layer')
        l2 = MeiElement('layer')
        s1 = MeiElement('staff')
        s2 = MeiElement('staff')

        mR1 = MeiElement('mRest')
        mR2 = MeiElement('mRest')

        scD1.addAttribute('meter.unit', '2')
        stD1.addAttribute('meter.count', '2')
        stD2.addAttribute('meter.count', '3')

        s1.addAttribute('n', '1')

        music.addChild(body)
        body.addChild(mdiv)
        mdiv.addChild(score)
        score.addChild(sctn)

        sctn.addChild(scD1)
        scD1.addChild(stG1)
        stG1.addChild(stD1)
        sctn.addChild(m1)
        m1.addChild(l1)
        l1.addChild(s1)
        s1.addChild(mR1)

        sctn.addChild(scD2)
        scD2.addChild(stG2)
        stG2.addChild(stD2)
        sctn.addChild(m2)
        m2.addChild(l2)
        l2.addChild(s2)
        s2.addChild(mR2)

        doc = MeiDocument()
        doc.setRootElement(music)

        self.assertEqual(doc.lookBack(body, 'music'), music)

        self.assertEqual(utilities.dur_in_semibreves(mR1), 1)
        self.assertEqual(utilities.dur_in_semibreves(mR2), 1.5)
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:57,代码来源:unit_test.py

示例9: test_setdocument

    def test_setdocument(self):
        m = MeiElement("mei")
        doc = MeiDocument()

        with self.assertRaises(DocumentRootNotSetException) as cm:
            m.setDocument(doc)
        self.assertTrue(isinstance(cm.exception, DocumentRootNotSetException))
        doc.setRootElement(m)

        self.assertEqual(doc.root, m)
开发者ID:lpugin,项目名称:libmei,代码行数:10,代码来源:meielement_test.py

示例10: test_exportcomment

    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,代码行数:15,代码来源:xmlexport_test.py

示例11: test_exportnamespace

    def test_exportnamespace(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        xlink = MeiNamespace("xlink", "http://www.w3.org/1999/xlink")
        attr = MeiAttribute(xlink, "title", "my awesome thing")
        root.addAttribute(attr)

        expected = "<?xml version=\"1.0\"?>\n<mei xmlns=\"http://www.music-encoding.org/ns/mei\" \
xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:id=\"myid\" xlink:title=\"my awesome thing\" meiversion=\"2013\"/>\n";

        ret = XmlExport.meiDocumentToText(doc)
        self.assertEqual(expected, ret)
开发者ID:lpugin,项目名称:libmei,代码行数:15,代码来源:xmlexport_test.py

示例12: test_exportvalueandtail

    def test_exportvalueandtail(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        note = MeiElement("note")
        note.id = "noteid"
        note.value = "value"
        note.tail = "tail"
        root.addChild(note)

        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<note xml:id=\"noteid\">value</note>tail</mei>\n"
        ret = documentToText(doc)

        self.assertEqual(expected, ret)
开发者ID:AFFogarty,项目名称:libmei,代码行数:16,代码来源:xmlexport_test.py

示例13: test_lookback

    def test_lookback(self):
        m = MeiElement("mei")
        m1 = MeiElement("music")
        b1 = MeiElement("body")
        s1 = MeiElement("staff")
        n1 = MeiElement("note")

        doc = MeiDocument()
        doc.setRootElement(m)
        m.addChild(m1)
        m1.addChild(b1)
        b1.addChild(s1)
        s1.addChild(n1)
        
        self.assertEqual(m1.lookBack('mei'), m)

        self.assertEqual(s1.lookBack('mei'), m)
开发者ID:lpugin,项目名称:libmei,代码行数:17,代码来源:meielement_test.py

示例14: test_getnamespace

    def test_getnamespace(self):
        doc = MeiDocument()
        ns = MeiNamespace("prefix", "http://example.com/ns")
        self.assertEqual("http://www.music-encoding.org/ns/mei", doc.getNamespaces()[0].href)

        doc.addNamespace(ns)
        self.assertEqual(2, len(doc.getNamespaces()))
        self.assertEqual(ns, doc.getNamespace("http://example.com/ns"))

        self.assertTrue(doc.hasNamespace("http://www.music-encoding.org/ns/mei"))
        self.assertFalse(doc.hasNamespace("http://www.mcgill.ca"))
开发者ID:lpugin,项目名称:libmei,代码行数:11,代码来源:meidocument_test.py

示例15: test_exportProcessingInstructions

    def test_exportProcessingInstructions(self):
        procinst = XmlInstructions()

        xpi1 = XmlProcessingInstruction("xml-model", "href=\"mei-2012.rng\" type=\"application/xml\" schematypens=\"http://purl.oclc.org/dsdl/schematron\"")
        xpi2 = XmlProcessingInstruction("xml-stylesheet", "href=\"mei-2012.rng\" type=\"application/xml\" schematypens=\"http://purl.oclc.org/dsdl/schematron\"")

        procinst.extend([xpi1, xpi2])

        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root

        ret = XmlExport.meiDocumentToText(doc, procinst)

        expected = "<?xml version=\"1.0\"?>\n<?xml-model href=\"mei-2012.rng\" type=\"application/xml\" \
schematypens=\"http://purl.oclc.org/dsdl/schematron\"?>\n<?xml-stylesheet href=\"mei-2012.rng\" type=\"application/xml\" \
schematypens=\"http://purl.oclc.org/dsdl/schematron\"?>\n<mei xmlns=\"http://www.music-encoding.org/ns/mei\" \
xml:id=\"myid\" meiversion=\"2013\"/>\n"

        self.assertEqual(expected, ret)
开发者ID:lpugin,项目名称:libmei,代码行数:21,代码来源:xmlexport_test.py


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