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


Python MeiElement.setChildren方法代码示例

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


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

示例1: neumify

# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import setChildren [as 别名]
    def neumify(self, ids, type_id, liquescence, head_shapes, ulx, uly, lrx, lry):
        '''
        Neumify a group of neumes (with provided ids)
        and give it the given neume name. Also update
        bounding box information.
        '''
        
        # get neume name and variant from type id
        type_split = type_id.split(".")
        if type_split[-1].isdigit():
             type_split.pop()

        if len(type_split) == 1:
            attrs = [MeiAttribute("name", type_split[0])]
        else:
            variant = " ".join(type_split[1:])
            attrs = [MeiAttribute("name", type_split[0]), MeiAttribute("variant", variant)]

        '''
        # need to determine how to encode these different types of liquescence in the MEI document
        if liquescence:
            if liquescence == "alt":
                attrs.append(MeiAttribute("variant", "liquescence"))
            elif liquescence == "aug":
                attrs.append(MeiAttribute("variant", "liquescence_aug"))
            elif liquescence == "dim":
                attrs.append(MeiAttribute("variant", "liquescence_dim"))
        '''

        new_neume = MeiElement("neume")
        new_neume.setAttributes(attrs)
        ncs = []
        cur_nc = None

        iNote = 0
        for id in ids:
            ref_neume = self.mei.getElementById(str(id))
            if ref_neume:
                # get underlying notes
                notes = ref_neume.getDescendantsByName("note")
                for n in notes:
                    head = str(head_shapes[iNote])
                    # check if a new nc must be opened
                    if head == 'punctum' and cur_nc != 'punctum':
                        ncs.append(MeiElement("nc"))
                        cur_nc = head
                    elif head == 'punctum_inclinatum' and cur_nc != 'punctum_inclinatum':
                        new_nc = MeiElement("nc")
                        new_nc.addAttribute("inclinatum", "true")
                        ncs.append(new_nc)
                        cur_nc = head
                    elif head == 'punctum_inclinatum_parvum' and cur_nc != 'punctum_inclinatum_parvum':
                        new_nc = MeiElement("nc")
                        new_nc.addAttribute("inclinatum", "true")
                        new_nc.addAttribute("deminutus", "true")
                        ncs.append(new_nc)
                        cur_nc = head 
                    elif head == 'quilisma' and cur_nc != 'quilisma':
                        new_nc = MeiElement("nc")
                        new_nc.addAttribute("quilisma", "true")
                        ncs.append(new_nc)
                        cur_nc = head
                    elif cur_nc is None:
                        ncs.append(MeiElement("nc"))
                        cur_nc = 'punctum'

                    ncs[-1].addChild(n)
                    iNote += 1

        new_neume.setChildren(ncs)

        # insert the new neume
        before = self.mei.getElementById(ids[0])
        parent = before.getParent()

        if before and parent:
            parent.addChildBefore(before, new_neume)

        # remove the old neumes from the mei document
        for id in ids:
            neume = self.mei.getElementById(str(id))
            if neume:
                # remove facs data
                facs = neume.getAttribute("facs")
                if facs:
                    facsid = facs.value
                    # Remove the zone if it exists
                    zone = self.mei.getElementById(str(facsid))
                    if zone and zone.name == "zone":
                        zone.parent.removeChild(zone)

                # now remove the neume
                neume.parent.removeChild(neume)

        # update bounding box data
        self.update_or_add_zone(new_neume, ulx, uly, lrx, lry)

        result = {"id": new_neume.getId()}
        return result
开发者ID:avorio,项目名称:Neon.js,代码行数:101,代码来源:modifymei.py


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