本文整理汇总了Python中pymei.MeiElement.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python MeiElement.addAttribute方法的具体用法?Python MeiElement.addAttribute怎么用?Python MeiElement.addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.MeiElement
的用法示例。
在下文中一共展示了MeiElement.addAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_custos
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def insert_custos(self, pname, oct, before_id, ulx, uly, lrx, lry):
'''
Insert a custos. Also add a bounding box
for this element.
'''
# create custos
custos = MeiElement("custos")
if pname and oct:
custos.addAttribute("pname", pname)
custos.addAttribute("oct", oct)
# insert the custos
if before_id is None:
# get last layer
layers = self.mei.getElementsByName("layer")
if len(layers):
layers[-1].addChild(custos)
else:
before = self.mei.getElementById(str(before_id))
parent = before.getParent()
if parent and before:
parent.addChildBefore(before, custos)
# update the bounding box
self.update_or_add_zone(custos, ulx, uly, lrx, lry)
result = {"id": custos.getId()}
return result
示例2: insert_clef
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def insert_clef(self, line, shape, pitch_info, before_id, ulx, uly, lrx, lry):
'''
Insert a doh or fah clef, with a given bounding box.
Must also update pitched elements on the staff that
affected by this clef being inserted.
'''
clef = MeiElement("clef")
clef.addAttribute("shape", shape)
clef.addAttribute("line", line)
# perform clef insertion
if before_id is None:
# get last layer
layers = self.mei.getElementsByName("layer")
if len(layers):
layers[-1].addChild(clef)
else:
before = self.mei.getElementById(str(before_id))
parent = before.getParent()
if parent and before:
parent.addChildBefore(before, clef)
self.update_or_add_zone(clef, ulx, uly, lrx, lry)
if pitch_info:
self.update_pitched_elements(pitch_info)
result = {"id": clef.getId()}
return result
示例3: _create_graphic_element
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def _create_graphic_element(self, imgfile):
graphic = MeiElement("graphic")
# xlink = MeiNamespace("xlink", "http://www.w3.org/1999/xlink")
# ns_attr = MeiAttribute("xlink")
graphic.addAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink")
graphic.addAttribute("xlink:href", imgfile)
return graphic
示例4: test_getattributeval
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def test_getattributeval(self):
measure = MeiElement('measure')
staff = MeiElement('staff')
measure.addAttribute('n', '2')
self.assertEqual(utilities.get_attribute_val(measure, 'n'), '2')
self.assertEqual(utilities.get_attribute_val(staff, 'n', '1'), '1')
示例5: add_source
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def add_source(sourceDesc, adi):
existing = sourceDesc.getDocument().getElementById(adi[3])
if not existing:
source = MeiElement('source')
source.id = adi[3]
source.addAttribute('type', adi[1])
sourceDesc.addChild(source)
示例6: test_getattributeval
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def test_getattributeval(self):
measure = MeiElement("measure")
staff = MeiElement("staff")
measure.addAttribute("n", "2")
self.assertEqual(utilities.get_attribute_val(measure, "n"), "2")
self.assertEqual(utilities.get_attribute_val(staff, "n", "1"), "1")
示例7: make_invisible_space
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def make_invisible_space(MEI_tree, handle_mRest=False):
"""Turns all invisible notes, rests and mRests into
<space> elements.
"""
all_note_rest = MEI_tree.getDescendantsByName('note rest')
all_mRest = MEI_tree.getDescendantsByName('mRest')
# Replace notes and rests with spaces
for item in all_note_rest:
try:
if item.getAttribute('visible').getValue() == 'false':
space = MeiElement('space')
attributes = item.getAttributes()
for attr in attributes:
# Don't add octave or pitch attributes to space
if attr.getName() not in ['oct', 'pname']:
space.addAttribute(attr)
# If mRest, calculate duration here?
parent = item.getParent()
parent.addChildBefore(item, space)
parent.removeChild(item)
except: # doesn't have attribute `visible`
pass
# Replace mRests with nothing -- just remove them
# Not currently supported by MEItoVexFlow
if handle_mRest:
for item in all_mRest:
try:
if item.getAttribute('visible').getValue() == 'false':
item.getParent().removeChild(item)
except: # doesn't have attribute `visible`
pass
示例8: insert_puncta
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [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
示例9: _create_staff_group
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def _create_staff_group(self, sg_list, staff_grp, n):
'''
Recursively create the staff group element from the parsed
user input of the staff groupings
'''
if not sg_list:
return staff_grp, n
else:
if type(sg_list[0]) is list:
new_staff_grp, n = self._create_staff_group(sg_list[0], MeiElement('staffGrp'), n)
staff_grp.addChild(new_staff_grp)
else:
# check for barthrough character
if sg_list[0][-1] == '|':
# the barlines go through all the staves in the staff group
staff_grp.addAttribute('barthru', 'true')
# remove the barthrough character, should now only be an integer
sg_list[0] = sg_list[0][:-1]
n_staff_defs = int(sg_list[0])
# get current staffDef number
for i in range(n_staff_defs):
staff_def = MeiElement('staffDef')
staff_def.addAttribute('n', str(n + i + 1))
staff_grp.addChild(staff_def)
n += n_staff_defs
return self._create_staff_group(sg_list[1:], staff_grp, n)
示例10: test_removeattr
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def test_removeattr(self):
el = MeiElement("mei")
el.addAttribute("meiversion", "2012")
self.assertTrue(el.hasAttribute("meiversion"))
el.removeAttribute("meiversion")
self.assertFalse(el.hasAttribute("meiversion"))
示例11: parse_token
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def parse_token(token):
def parse_attrs(token):
def parse_attrs_str(attrs_str):
res = []
attr_pairs = attrs_str.split(",")
for attr_pair in attr_pairs:
if attr_pair == '':
continue
name_val = attr_pair.split("=")
if len(name_val) > 1:
attr = MeiAttribute(name_val[0], name_val[1])
res.append(attr)
else:
logging.warning("get_descendants(): invalid attribute specifier in expression: " + expr)
return res
m = re.search("\[(.*)\]", token)
attrs_str = ""
if m is not None:
attrs_str = m.group(1)
return parse_attrs_str(attrs_str)
m = re.search("^([^\[]+)", token)
elem = MeiElement(m.group(1))
attrs = parse_attrs(token)
for attr in attrs:
elem.addAttribute(attr)
return elem
示例12: post
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def post(self, file):
'''
Add a dot ornament to a given element.
'''
neumeid = str(self.get_argument("id", ""))
dot_form = str(self.get_argument("dotform", ""))
# Bounding box
ulx = str(self.get_argument("ulx", None))
uly = str(self.get_argument("uly", None))
lrx = str(self.get_argument("lrx", None))
lry = str(self.get_argument("lry", None))
mei_directory = os.path.abspath(conf.MEI_DIRECTORY)
fname = os.path.join(mei_directory, file)
self.mei = XmlImport.read(fname)
punctum = self.mei.getElementById(neumeid)
# check that a punctum element was provided
if punctum.getName() == "neume" and punctum.getAttribute("name").getValue() == "punctum":
note = punctum.getDescendantsByName("note")
if len(note):
# if a dot does not already exist on the note
if len(note[0].getChildrenByName("dot")) == 0:
dot = MeiElement("dot")
dot.addAttribute("form", dot_form)
note[0].addChild(dot)
self.update_or_add_zone(punctum, ulx, uly, lrx, lry)
XmlExport.write(self.mei, fname)
self.set_status(200)
示例13: move_recon_staves
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [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)
示例14: insert_custos
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def insert_custos(self, pname, oct, before_id, ulx, uly, lrx, lry):
'''
Insert a custos. Also add a bounding box
for this element.
'''
# create custos
custos = MeiElement("custos")
if pname and oct:
custos.addAttribute("pname", pname)
custos.addAttribute("oct", oct)
# insert the custos
before = self.mei.getElementById(before_id)
# get layer element
parent = before.getParent()
if parent and before:
parent.addChildBefore(before, custos)
# update the bounding box
self.update_or_add_zone(custos, ulx, uly, lrx, lry)
result = {"id": custos.getId()}
return result
示例15: create_zone
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import addAttribute [as 别名]
def create_zone(self, ulx, uly, lrx, lry):
zone = MeiElement("zone")
zone.addAttribute("ulx", ulx)
zone.addAttribute("uly", uly)
zone.addAttribute("lrx", lrx)
zone.addAttribute("lry", lry)
return zone