當前位置: 首頁>>代碼示例>>Python>>正文


Python XmlImport.read方法代碼示例

本文整理匯總了Python中pymei.XmlImport.read方法的典型用法代碼示例。如果您正苦於以下問題:Python XmlImport.read方法的具體用法?Python XmlImport.read怎麽用?Python XmlImport.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pymei.XmlImport的用法示例。


在下文中一共展示了XmlImport.read方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from pymei import XmlImport [as 別名]
# 或者: from pymei.XmlImport import read [as 別名]
    def post(self, file):
        '''
        Change the shape of a given clef. Must also update
        bounding box data since the glyphs for c and f clefs
        are different. Must also update pitched elements on the
        affected staff to correspond with the new clef shape.
        '''

        data = json.loads(self.get_argument("data", ""))
        clef_id = str(data["id"])

        # bounding box
        ulx = str(data["ulx"])
        uly = str(data["uly"])
        lrx = str(data["lrx"])
        lry = str(data["lry"])

        mei_directory = os.path.abspath(conf.MEI_DIRECTORY)
        fname = os.path.join(mei_directory, file)
        self.mei = XmlImport.read(fname)

        clef = self.mei.getElementById(clef_id)

        # update clef shape
        clef.addAttribute("shape", str(data["shape"]).upper())

        self.update_or_add_zone(clef, ulx, uly, lrx, lry)
        self.update_pitched_elements(data["pitchInfo"])

        XmlExport.write(self.mei, fname)

        self.set_status(200)
開發者ID:sequoiar,項目名稱:Neon.js,代碼行數:34,代碼來源:api.py

示例2: test_readmethod_unicode

# 需要導入模塊: from pymei import XmlImport [as 別名]
# 或者: from pymei.XmlImport import read [as 別名]
 def test_readmethod_unicode(self):
     fn = unicode(os.path.join("test", "testdocs", "beethoven.mei"))
     doc = XmlImport.read(fn)
     self.assertNotEqual(None, doc)
     el = doc.getElementById("d1e41")
     self.assertEqual("c", el.getAttribute("pname").value)
     self.assertEqual("4", el.getAttribute("oct").value)
開發者ID:lpugin,項目名稱:libmei,代碼行數:9,代碼來源:xmlimport_test.py

示例3: meitoalphatex

# 需要導入模塊: from pymei import XmlImport [as 別名]
# 或者: from pymei.XmlImport import read [as 別名]
def meitoalphatex(mei_path):
    alphatex = ""

    # read in the mei document
    meidoc = XmlImport.read(mei_path)
    mei = meidoc.getRootElement()

    ###########################
    #         MetaData        #
    ###########################
    title = mei.getDescendantsByName("title")
    if len(title):
        tex_title = '\\title "%s"\n' % title[0].getValue()
        alphatex += tex_title

    pers_name = mei.getDescendantsByName("persName")
    if len(pers_name):
        for p in pers_name:
            role = p.getAttribute("role").value
            if role == "artist":
                tex_artist = '\\artist "%s"\n' % p.getValue()
                alphatex += tex_artist
            elif role == "tabber":
                tex_copywrite = '\\copyright "%s"\n' % p.getValue()
                alphatex += tex_copywrite
            elif role == "lyricist":
                tex_words = '\\words "%s"\n' % p.getValue()
                alphatex += tex_words

    staff_def = mei.getDescendantsByName("staffDef")
    if len(staff_def):
        # capo position
        if staff_def[0].hasAttribute("tab.capo"):
            capo = staff_def[0].getAttribute("tab.capo").value

            if int(capo) > 0:
                alphatex += "\\capo %s\n" % capo  # this doesn't display
                alphatex += "\\words %s\n" % capo  # hack this to display

        # guitar tuning
        pnames = ["C", "D", "E", "F", "G", "A", "B"]

        if staff_def[0].hasAttribute("tab.strings"):
            strings = staff_def[0].getAttribute("tab.strings").value.split(" ")
            if len(strings) != 6:
                raise ValueError("Invalid number of strings: should be 6")

            # convert pitch names to those used in alphatab (flats vs. sharps)
            for i in range(len(strings)):
                pattern = re.compile("^([a-zA-z][#s])")
                match = pattern.match(strings[i])
                if match:
                    mei_pname = match.group()
                    alpha_pname = pnames[pnames.index(mei_pname[0]) + 1 % len(pnames)] + "b"
                    oct = strings[i][-1]
                    # replace string
                    strings[i] = alpha_pname + oct

            alphatex += "\\tuning %s\n" % " ".join(strings)

    # set midi instrument to play the tab with
    # 27 is Electric Guitar Clean
    alphatex += "\\instrument 27\n"

    # in alphatex the metadata and body are separated by a period character
    alphatex += ".\n"

    ###########################
    #           Body          #
    ###########################

    measures = mei.getDescendantsByName("measure")
    alpha_measures = []
    for m in measures:
        measure_events = []
        # only parse first staff (instrument), the instrument display
        staff = m.getChildrenByName("staff")[0]
        # only parse first layer (assume only one voice)
        layer = staff.getChildrenByName("layer")[0]
        score_events = layer.getChildren()
        for e in score_events:
            if e.getName() == "chord":
                # get notes in this chord
                notes = e.getChildrenByName("note")
                alpha_notes = [
                    n.getAttribute("tab.fret").value + "." + n.getAttribute("tab.string").value for n in notes
                ]
                alpha_chord = "(" + " ".join(alpha_notes) + ")"
                measure_events.append(alpha_chord)
            elif e.getName() == "note":
                alpha_note = e.getAttribute("tab.fret").value + "." + e.getAttribute("tab.string").value
                measure_events.append(alpha_note)

        alpha_measures.append(" ".join(measure_events))

    alphatex += " |\n".join(alpha_measures)

    return alphatex
開發者ID:gburlet,項目名稱:robotaba,代碼行數:100,代碼來源:meitoalphatex.py

示例4: __init__

# 需要導入模塊: from pymei import XmlImport [as 別名]
# 或者: from pymei.XmlImport import read [as 別名]
 def __init__(self, filename):
     self.mei = XmlImport.read(filename)
     self.filename = filename
開發者ID:avorio,項目名稱:Neon.js,代碼行數:5,代碼來源:modifymei.py


注:本文中的pymei.XmlImport.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。