Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parsed_mei = meiinfo.read_MEI(mei_as_text).getMeiDocument()
except CannotReadMEIException as ex:
return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR
try:
mei_slicer = meislicer.MeiSlicer(
parsed_mei,
measures,
staves,
beats,
completeness
)
mei_slice = mei_slicer.slice()
except BadApiRequest as ex:
return {"message": ex.message}, status.HTTP_400_BAD_REQUEST
except UnsupportedEncoding as ex:
return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR
if completeness == "compile":
return mei_slicer.compiled_exp
else:
# this will write it to a temporary directory automatically
try:
filename = meiinfo.write_MEI(mei_slice)
except CannotWriteMEIException as ex:
return (
{"message": ex.message},
status.HTTP_500_INTERNAL_SERVER_ERROR
)
return send_file(filename,
as_attachment=True,
dot_dur = duration
for d in range(1, int(dots)+1):
dot_dur = dot_dur * 2
relative_dur += float(int(meter["unit"]) / dot_dur)
# Is this element contained in a tuplet element?
# (TODO account for tupletspan)
if element.hasAncestor("tuplet"):
tupl = element.getAncestor("tuplet")
numbase = tupl.getAttribute("numbase")
num = tupl.getAttribute("num")
if not num or not numbase:
raise UnsupportedEncoding(
"Cannot understand tuplet beat: both @num and @numbase must be present")
else:
tupl_ratio = float(numbase.getValue()) / float(num.getValue())
relative_dur = relative_dur * tupl_ratio
return relative_dur
# at the first available layer
try:
layer = (
staff.getChildrenByName("layer")
)
first_id = layer[0].getChildren()[0].getId()
ev.getAttribute("startid").setValue("#"+first_id)
except IndexError:
msg = """
Unsupported encoding. Omas attempted to adjust the
starting point of a selected multi-measure element
that starts before the selection, but the staff or
layer could not be located.
"""
msg = re.sub(r'\s+', ' ', msg.strip())
raise UnsupportedEncoding(msg)
if ev.hasAttribute("tstamp"):
# Set tstamp to first in beat selection
tstamp_first = 0
for e_s in ema_m.staves:
if e_s.number == staff_no:
tstamp_first = e_s.beat_ranges[0].tstamp_first
ev.getAttribute("tstamp").setValue(str(tstamp_first))
# Truncate to end of range if completeness = cut
# (actual beat cutting will happen when beat ranges are procesed)
if "cut" in self.ema_exp.completenessOptions:
if ev.hasAttribute("tstamp2"):
att = ev.getAttribute("tstamp2")
t2 = att.getValue()
p = re.compile(r"([1-9]+)(?=m\+)")
else:
marked_as_selected.add(event)
elif event.hasAttribute("startid"):
startid = (
event.getAttribute("startid")
.getValue()
.replace("#", "")
)
target = self.doc.getElementById(startid)
if not target:
msg = """Unsupported Encoding: attribute
startid on element {0} does not point to any
element in the document.""".format(
event.getName())
raise UnsupportedEncoding(
re.sub(r'\s+', ' ', msg.strip()))
# Make sure the target event is in the same measure
event_m = event.getAncestor("measure").getId()
target_m = target.getAncestor("measure").getId()
if not event_m == target_m:
msg = """Unsupported Encoding: attribute
startid on element {0} does not point to an
element in the same measure.""".format(
event.getName())
raise UnsupportedEncoding(
re.sub(r'\s+', ' ', msg.strip()))
else:
if marked_as_selected.get(target):
marked_as_selected.add(event)
marked_for_removal.discard(event)
elif not event.hasAttribute("endid"):