Пример #1
0
 def check_misrepresented_flags(
     self, argument=None
 ) -> typing.Tuple[typing.List, int]:
     """
     Checks misrepresented flags.
     """
     violators: typing.List[Leaf] = []
     total = set()
     for leaf in iterate(argument).leaves():
         total.add(leaf)
         flags = leaf.written_duration.flag_count
         left = getattr(setting(leaf), "stem_left_beam_count", None)
         right = getattr(setting(leaf), "stem_right_beam_count", None)
         if left is not None:
             if flags < left or (
                 left < flags and right not in (flags, None)
             ):
                 if leaf not in violators:
                     violators.append(leaf)
         if right is not None:
             if flags < right or (
                 right < flags and left not in (flags, None)
             ):
                 if leaf not in violators:
                     violators.append(leaf)
     return violators, len(total)
Пример #2
0
 def check_misrepresented_flags(
     self, argument=None
 ) -> typing.Tuple[typing.List, int]:
     """
     Checks misrepresented flags.
     """
     violators: typing.List[Leaf] = []
     total = set()
     for leaf in iterate(argument).leaves():
         total.add(leaf)
         flags = leaf.written_duration.flag_count
         left = getattr(setting(leaf), "stem_left_beam_count", None)
         right = getattr(setting(leaf), "stem_right_beam_count", None)
         if left is not None:
             if flags < left or (
                 left < flags and right not in (flags, None)
             ):
                 if leaf not in violators:
                     violators.append(leaf)
         if right is not None:
             if flags < right or (
                 right < flags and left not in (flags, None)
             ):
                 if leaf not in violators:
                     violators.append(leaf)
     return violators, len(total)
Пример #3
0
    def __copy__(self, *arguments):
        """
        Shallow copies component.

        Copies indicators.

        Does not copy spanners.

        Does not copy children.

        Returns new component.
        """
        new_component = type(self)(*self.__getnewargs__())
        if getattr(self, "_overrides", None) is not None:
            manager = copy.copy(override(self))
            new_component._overrides = manager
        if getattr(self, "_lilypond_setting_name_manager", None) is not None:
            manager = copy.copy(setting(self))
            new_component._lilypond_setting_name_manager = manager
        for wrapper in inspect(self).annotation_wrappers():
            new_wrapper = copy.copy(wrapper)
            attach(new_wrapper, new_component)
        for wrapper in inspect(self).wrappers():
            new_wrapper = copy.copy(wrapper)
            attach(new_wrapper, new_component)
        return new_component
Пример #4
0
    def __copy__(self, *arguments):
        """
        Shallow copies component.

        Copies indicators.

        Does not copy spanners.

        Does not copy children.

        Returns new component.
        """
        new_component = type(self)(*self.__getnewargs__())
        if getattr(self, "_overrides", None) is not None:
            manager = copy.copy(override(self))
            new_component._overrides = manager
        if getattr(self, "_lilypond_setting_name_manager", None) is not None:
            manager = copy.copy(setting(self))
            new_component._lilypond_setting_name_manager = manager
        for wrapper in inspect(self).annotation_wrappers():
            new_wrapper = copy.copy(wrapper)
            attach(new_wrapper, new_component)
        for wrapper in inspect(self).wrappers():
            new_wrapper = copy.copy(wrapper)
            attach(new_wrapper, new_component)
        return new_component
Пример #5
0
 def _get_format_pieces(self, tag=None):
     indent = LilyPondFormatManager.indent
     result = []
     string = f'{self._escaped_name} {{'
     result.append(string)
     manager = LilyPondFormatManager
     # CAUTION: source context name must come before type_ to allow
     # context redefinition.
     if self.source_lilypond_type is not None:
         string = indent + rf'\{self.source_lilypond_type}'
         result.append(string)
     if self.name is not None:
         string = indent + rf'\name {self.name}'
         result.append(string)
     if self.type_ is not None:
         string = indent + rf'\type {self.type_}'
         result.append(string)
     if self.alias is not None:
         string = indent + rf'\alias {self.alias}'
         result.append(string)
     for statement in self.remove_commands:
         string = indent + rf'\remove {statement}'
         result.append(string)
     # CAUTION: LilyPond \consists statements are order-significant!
     for statement in self.consists_commands:
         string = indent + rf'\consists {statement}'
         result.append(string)
     for statement in self.accepts_commands:
         string = indent + rf'\accepts {statement}'
         result.append(string)
     overrides = override(self)._list_format_contributions('override')
     for statement in overrides:
         string = indent + statement
         result.append(string)
     setting_contributions = []
     for key, value in setting(self)._get_attribute_tuples():
         setting_contribution = \
             manager.format_lilypond_context_setting_in_with_block(
                 key, value)
         setting_contributions.append(setting_contribution)
     for setting_contribution in sorted(setting_contributions):
         string = indent + setting_contribution
         result.append(string)
     for item in self.items:
         if isinstance(item, str):
             string = indent + f'{item}'
             result.append(string)
         elif '_get_format_pieces' in dir(item):
             for piece in item._get_format_pieces():
                 if piece.isspace():
                     piece = ''
                 else:
                     piece = indent + piece
                 result.append(piece)
         else:
             pass
     result.append('}')
     return result
Пример #6
0
 def _get_format_pieces(self, tag=None):
     indent = LilyPondFormatManager.indent
     result = []
     string = f"{self._escaped_name} {{"
     result.append(string)
     manager = LilyPondFormatManager
     # CAUTION: source context name must come before type_ to allow
     # context redefinition.
     if self.source_lilypond_type is not None:
         string = indent + rf"\{self.source_lilypond_type}"
         result.append(string)
     if self.name is not None:
         string = indent + rf"\name {self.name}"
         result.append(string)
     if self.type_ is not None:
         string = indent + rf"\type {self.type_}"
         result.append(string)
     if self.alias is not None:
         string = indent + rf"\alias {self.alias}"
         result.append(string)
     for statement in self.remove_commands:
         string = indent + rf"\remove {statement}"
         result.append(string)
     # CAUTION: LilyPond \consists statements are order-significant!
     for statement in self.consists_commands:
         string = indent + rf"\consists {statement}"
         result.append(string)
     for statement in self.accepts_commands:
         string = indent + rf"\accepts {statement}"
         result.append(string)
     overrides = override(self)._list_format_contributions("override")
     for statement in overrides:
         string = indent + statement
         result.append(string)
     setting_contributions = []
     for key, value in setting(self)._get_attribute_tuples():
         setting_contribution = manager.format_lilypond_context_setting_in_with_block(
             key, value
         )
         setting_contributions.append(setting_contribution)
     for setting_contribution in sorted(setting_contributions):
         string = indent + setting_contribution
         result.append(string)
     for item in self.items:
         if isinstance(item, str):
             string = indent + f"{item}"
             result.append(string)
         elif "_get_format_pieces" in dir(item):
             for piece in item._get_format_pieces():
                 if piece.isspace():
                     piece = ""
                 else:
                     piece = indent + piece
                 result.append(piece)
         else:
             pass
     result.append("}")
     return result
Пример #7
0
 def _copy_override_and_set_from_leaf(self, leaf):
     if getattr(leaf, '_overrides', None) is not None:
         self._overrides = copy.copy(override(leaf))
     if getattr(leaf, '_lilypond_setting_name_manager', None) is not None:
         self._lilypond_setting_name_manager = copy.copy(setting(leaf))
     new_wrappers = []
     for wrapper in leaf._wrappers:
         new_wrapper = copy.copy(wrapper)
         new_wrappers.append(new_wrapper)
     for new_wrapper in new_wrappers:
         attach(new_wrapper, self)
Пример #8
0
 def _copy_override_and_set_from_leaf(self, leaf):
     if getattr(leaf, "_overrides", None) is not None:
         self._overrides = copy.copy(override(leaf))
     if getattr(leaf, "_lilypond_setting_name_manager", None) is not None:
         self._lilypond_setting_name_manager = copy.copy(setting(leaf))
     new_wrappers = []
     for wrapper in leaf._wrappers:
         new_wrapper = copy.copy(wrapper)
         new_wrappers.append(new_wrapper)
     for new_wrapper in new_wrappers:
         attach(new_wrapper, self)
Пример #9
0
    def __copy__(self, *arguments):
        """
        Copies spanner.

        Does not copy spanner leaves.
        """
        new = type(self)(*self.__getnewargs__())
        if getattr(self, '_lilypond_setting_name_manager', None) is not None:
            new._lilypond_setting_name_manager = copy.copy(setting(self))
        if getattr(self, '_tweaks', None) is not None:
            new._tweaks = copy.copy(tweak(self))
        self._copy_keywords(new)
        return new