Exemplo n.º 1
0
 def active_transposition_at(self, pos_x: Unit) -> Optional[Transposition]:
     """Return the active transposition at a given x position, if any."""
     for item in self.descendants_of_class_or_subclass(OctaveLine):
         line_pos = map_between_x(self, item)
         if line_pos <= pos_x <= line_pos + item.length:
             return item.transposition
     return None
Exemplo n.º 2
0
    def spanner_x_length(self) -> Unit:
        """The x-axis length of the spanner.

        Implementing subclasses will often want to override
        `GraphicObject.length` to return this.
        """
        if self.end_parent == self:
            return self.end_pos.x
        else:
            return (
                map_between_x(cast(Positioned, self), self.end_parent) + self.end_pos.x
            )
Exemplo n.º 3
0
    def distance_to_next_of_type(self, staff_object: StaffObject) -> Unit:
        """Find the x distance until the next occurrence of an object's type.

        If the object is the last of its type, this gives the remaining length
        of the staff after the object.

        This is useful for determining rendering behavior of `StaffObject`s
        who are active until another of their type occurs,
        such as `KeySignature`s, or `Clef`s.
        """
        start_x = map_between_x(self, cast(Positioned, staff_object))
        all_others_of_class = (
            item
            for item in self.descendants_of_exact_class(type(staff_object))
            if item != staff_object)
        closest_x = Unit(float("inf"))
        for item in all_others_of_class:
            relative_x = map_between_x(self, item)
            if start_x < relative_x < closest_x:
                closest_x = relative_x
        if closest_x == Unit(float("inf")):
            return self.length - start_x
        return closest_x - start_x
Exemplo n.º 4
0
Arquivo: path.py Projeto: ajyoon/brown
    def length(self) -> Unit:
        """The breakable length of the path.

        This is calculated automatically from path contents. By extension,
        this means that by default all `Path` objects will automatically
        wrap in `Flowable`s.
        """
        # Find the positions of every path element relative to the path
        min_x = Unit(float("inf"))
        max_x = Unit(-float("inf"))
        for element in self.elements:
            # Determine element X relative to self
            relative_x = map_between_x(self, element)
            # Now update min/max accordingly
            if relative_x > max_x:
                max_x = relative_x
            if relative_x < min_x:
                min_x = relative_x
        return max_x - min_x
Exemplo n.º 5
0
    def length(self):
        """Unit: The breakable width of the object.

        This is used to determine how and where rendering cuts should be made.
        """
        return self.staff.length - map_between_x(self.staff, self)
Exemplo n.º 6
0
 def pos_x_in_staff(self) -> Unit:
     """A specialized version of `pos_in_staff` which only finds the x pos"""
     return mapping.map_between_x(self.staff, cast(mapping.Positioned,
                                                   self))