How to use the omas.exceptions.UnsupportedEncoding function in omas

To help you get started, we’ve selected a few omas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umd-mith / ema / Omas / api.py View on Github external
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,
github umd-mith / ema / Omas / omas / meislicer.py View on Github external
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
github umd-mith / ema / Omas / omas / meislicer.py View on Github external
# 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\+)")
github umd-mith / ema / Omas / omas / meislicer.py View on Github external
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"):