本文整理汇总了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)
示例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)
示例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
示例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