def _list_format_contributions(self, directed=True): result = [] for attribute_tuple in self._get_attribute_tuples(): if len(attribute_tuple) == 2: grob = None attribute = attribute_tuple[0] value = attribute_tuple[1] elif len(attribute_tuple) == 3: grob = attribute_tuple[0] attribute = attribute_tuple[1] value = attribute_tuple[2] else: message = f"invalid attribute tuple: {attribute_tuple!r}." raise ValueError(message) deactivate = False if isinstance(value, tuple) and value[0] == "TAGGED": if len(value) == 4: deactivate = value[3] tag = value[2] value = value[1] else: tag = None string = LilyPondFormatManager.make_lilypond_tweak_string( attribute, value, directed=directed, grob=grob) if tag is not None: strings = [string] strings = LilyPondFormatManager.tag(strings, deactivate=deactivate, tag=tag) string = strings[0] result.append(string) result.sort() return result
def _list_format_contributions(self, directed=True): result = [] for attribute_tuple in self._get_attribute_tuples(): if len(attribute_tuple) == 2: grob = None attribute = attribute_tuple[0] value = attribute_tuple[1] elif len(attribute_tuple) == 3: grob = attribute_tuple[0] attribute = attribute_tuple[1] value = attribute_tuple[2] else: message = f"invalid attribute tuple: {attribute_tuple!r}." raise ValueError(message) deactivate = False if isinstance(value, tuple) and value[0] == "TAGGED": if len(value) == 4: deactivate = value[3] tag = value[2] value = value[1] else: tag = None string = LilyPondFormatManager.make_lilypond_tweak_string( attribute, value, directed=directed, grob=grob ) if tag is not None: strings = [string] strings = LilyPondFormatManager.tag( strings, deactivate=deactivate, tag=tag ) string = strings[0] result.append(string) result.sort() return result
def _get_lilypond_format(self, formatted_duration=None): pieces = self._get_format_pieces() if formatted_duration is not None: pieces[-1] = pieces[-1] + formatted_duration if self.alternative: pieces = LilyPondFormatManager.tag(pieces, tag=self.alternative[2]) pieces_ = self.alternative[0]._get_format_pieces() if formatted_duration is not None: pieces_[-1] = pieces_[-1] + formatted_duration pieces_ = LilyPondFormatManager.tag( pieces_, deactivate=True, tag=self.alternative[1] ) pieces.extend(pieces_) result = "\n".join(pieces) return result
def _get_lilypond_format(self, formatted_duration=None): pieces = self._get_format_pieces() if formatted_duration is not None: pieces[-1] = pieces[-1] + formatted_duration if self.alternative: pieces = LilyPondFormatManager.tag(pieces, tag=self.alternative[2]) pieces_ = self.alternative[0]._get_format_pieces() if formatted_duration is not None: pieces_[-1] = pieces_[-1] + formatted_duration pieces_ = LilyPondFormatManager.tag( pieces_, deactivate=True, tag=self.alternative[1] ) pieces.extend(pieces_) result = "\n".join(pieces) return result
def _tag_hide(strings): abjad_tags = Tags() return LilyPondFormatManager.tag( strings, deactivate=False, tag=abjad_tags.HIDE_TO_JOIN_BROKEN_SPANNERS, )
def _tag_hide(strings): abjad_tags = Tags() return LilyPondFormatManager.tag( strings, deactivate=False, tag=abjad_tags.HIDE_TO_JOIN_BROKEN_SPANNERS, )
def _get_format_pieces(self, tag=None): result = [] if self.date_time_token is not None: string = f"% {self.date_time_token}" result.append(string) result.extend(self._get_formatted_comments()) includes = [] if self.lilypond_version_token is not None: string = f"{self.lilypond_version_token}" includes.append(string) if self.lilypond_language_token is not None: string = f"{self.lilypond_language_token}" includes.append(string) if self.tag is not None: includes = LilyPondFormatManager.tag(includes, tag=self.tag) includes = "\n".join(includes) if includes: result.append(includes) postincludes = [] if self.use_relative_includes: string = "#(ly:set-option 'relative-includes #t)" postincludes.append(string) postincludes.extend(self._get_formatted_includes()) postincludes.extend(self._get_formatted_scheme_settings()) result.extend(postincludes) result.extend(self._get_formatted_blocks()) return result
def _get_format_pieces(self, tag=None): result = [] if self.date_time_token is not None: string = f'% {self.date_time_token}' result.append(string) result.extend(self._get_formatted_comments()) includes = [] if self.lilypond_version_token is not None: string = f'{self.lilypond_version_token}' includes.append(string) if self.lilypond_language_token is not None: string = f'{self.lilypond_language_token}' includes.append(string) if self.tag is not None: includes = LilyPondFormatManager.tag( includes, tag=self.tag, ) includes = '\n'.join(includes) if includes: result.append(includes) postincludes = [] if self.use_relative_includes: string = "#(ly:set-option 'relative-includes #t)" postincludes.append(string) postincludes.extend(self._get_formatted_includes()) postincludes.extend(self._get_formatted_scheme_settings()) result.extend(postincludes) result.extend(self._get_formatted_blocks()) return result
def _get_format_pieces(self, tag=None): from abjad.core.Leaf import Leaf from abjad.markups import Markup from .ContextBlock import ContextBlock indent = LilyPondFormatManager.indent result = [] if (not self._get_formatted_user_attributes() and not getattr(self, 'contexts', None) and not getattr(self, 'context_blocks', None) and not len(self.items)): if self.name == 'score': return '' string = f'{self._escaped_name} {{}}' result.append(string) return result string = f'{self._escaped_name} {{' if tag is not None: strings = LilyPondFormatManager.tag( [string], tag=tag, ) string = strings[0] result.append(string) for item in self.items: if isinstance(item, ContextBlock): continue if isinstance(item, (Leaf, Markup)): item = [item] result.extend(self._format_item(item)) formatted_attributes = self._get_formatted_user_attributes() formatted_attributes = [indent + _ for _ in formatted_attributes] result.extend(formatted_attributes) formatted_context_blocks = getattr( self, '_formatted_context_blocks', []) formatted_context_blocks = [ indent + _ for _ in formatted_context_blocks] result.extend(formatted_context_blocks) string = '}' if tag is not None: strings = LilyPondFormatManager.tag( [string], tag=tag, ) string = strings[0] result.append(string) return result
def _format_leaf_nucleus(self): strings = self._get_body() if self.tag: tag = Tag(self.tag) strings = LilyPondFormatManager.tag( strings, tag=tag, ) return ['nucleus', strings]
def _get_formatted_scheme_settings(self): result = [] default_paper_size = self.default_paper_size if default_paper_size is not None: dimension, orientation = default_paper_size string = f'#(set-default-paper-size "{dimension}" \'{orientation})' result.append(string) global_staff_size = self.global_staff_size if global_staff_size is not None: string = f"#(set-global-staff-size {global_staff_size})" result.append(string) if result: result = LilyPondFormatManager.tag(result, tag=self.tag) result = ["\n".join(result)] return result
def _get_formatted_scheme_settings(self): result = [] default_paper_size = self.default_paper_size if default_paper_size is not None: dimension, orientation = default_paper_size string = f'#(set-default-paper-size "{dimension}" \'{orientation})' result.append(string) global_staff_size = self.global_staff_size if global_staff_size is not None: string = f"#(set-global-staff-size {global_staff_size})" result.append(string) if result: result = LilyPondFormatManager.tag(result, tag=self.tag) result = ["\n".join(result)] return result
def _format_open_brackets_slot(self, bundle): result = [] if self.simultaneous: if self.identifier: brackets_open = [f"<< {self.identifier}"] else: brackets_open = ["<<"] else: if self.identifier: brackets_open = [f"{{ {self.identifier}"] else: brackets_open = ["{"] if self.tag is not None: brackets_open = LilyPondFormatManager.tag(brackets_open, tag=self.tag) result.append([("open brackets", ""), brackets_open]) return tuple(result)
def _get_lilypond_format(self, context=None): if isinstance(context, Context): assert isinstance(context.lilypond_type, str), repr(context) lilypond_type = context.lilypond_type else: lilypond_type = self.context strings = [] string = LilyPondFormatManager.make_lilypond_override_string( self.grob, self.attribute, self.value, context=lilypond_type, once=False, ) strings.append(string) return strings
def _format_close_brackets_slot(self, bundle): result = [] if self.simultaneous: if self.identifier: brackets_close = [f">> {self.identifier}"] else: brackets_close = [">>"] else: if self.identifier: brackets_close = [f"}} {self.identifier}"] else: brackets_close = ["}"] if self.tag is not None: brackets_close = LilyPondFormatManager.tag(brackets_close, tag=self.tag) result.append([("close brackets", ""), brackets_close]) return tuple(result)
def _format_open_brackets_slot(self, bundle): result = [] if self.is_simultaneous: if self.identifier: brackets_open = [f"<< {self.identifier}"] else: brackets_open = ["<<"] else: if self.identifier: brackets_open = [f"{{ {self.identifier}"] else: brackets_open = ["{"] if self.tag is not None: brackets_open = LilyPondFormatManager.tag( brackets_open, tag=self.tag ) result.append([("open brackets", ""), brackets_open]) return tuple(result)
def _format_close_brackets_slot(self, bundle): result = [] if self.is_simultaneous: if self.identifier: brackets_close = [f">> {self.identifier}"] else: brackets_close = [">>"] else: if self.identifier: brackets_close = [f"}} {self.identifier}"] else: brackets_close = ["}"] if self.tag is not None: brackets_close = LilyPondFormatManager.tag( brackets_close, tag=self.tag ) result.append([("close brackets", ""), brackets_close]) return tuple(result)
def _get_formatted_includes(self): result = [] for include in self.includes: if isinstance(include, str): string = rf'\include "{include}"' result.append(string) elif isinstance(include, pathlib.Path): string = rf'\include "{include!s}"' result.append(string) elif isinstance(include, LilyPondLiteral): string = str(include.argument) result.append(string) else: result.append(format(include)) if result: result = LilyPondFormatManager.tag(result, tag=self.tag) result = ["\n".join(result)] return result
def _get_formatted_includes(self): result = [] for include in self.includes: if isinstance(include, str): string = rf'\include "{include}"' result.append(string) elif isinstance(include, pathlib.Path): string = rf'\include "{include!s}"' result.append(string) else: result.append(format(include)) if result: result = LilyPondFormatManager.tag( result, tag=self.tag, ) result = ['\n'.join(result)] return result
def _format_close_brackets_slot(self, bundle): result = [] if self.is_simultaneous: if self.identifier: brackets_close = [f'>> {self.identifier}'] else: brackets_close = ['>>'] else: if self.identifier: brackets_close = [f'}} {self.identifier}'] else: brackets_close = ['}'] if self.tag is not None: brackets_close = LilyPondFormatManager.tag( brackets_close, tag=self.tag, ) result.append([('close brackets', ''), brackets_close]) return tuple(result)
def _format_component(self, pieces=False): result = [] bundle = LilyPondFormatManager.bundle_format_contributions(self) result.extend(self._format_absolute_before_slot(bundle)) result.extend(self._format_before_slot(bundle)) result.extend(self._format_open_brackets_slot(bundle)) result.extend(self._format_opening_slot(bundle)) result.extend(self._format_contents_slot(bundle)) result.extend(self._format_closing_slot(bundle)) result.extend(self._format_close_brackets_slot(bundle)) result.extend(self._format_after_slot(bundle)) result.extend(self._format_absolute_after_slot(bundle)) contributions = [] for contributor, contribution in result: contributions.extend(contribution) if pieces: return contributions else: return "\n".join(contributions)
def _format_component(self, pieces=False): result = [] bundle = LilyPondFormatManager.bundle_format_contributions(self) result.extend(self._format_absolute_before_slot(bundle)) result.extend(self._format_before_slot(bundle)) result.extend(self._format_open_brackets_slot(bundle)) result.extend(self._format_opening_slot(bundle)) result.extend(self._format_contents_slot(bundle)) result.extend(self._format_closing_slot(bundle)) result.extend(self._format_close_brackets_slot(bundle)) result.extend(self._format_after_slot(bundle)) result.extend(self._format_absolute_after_slot(bundle)) contributions = [] for contributor, contribution in result: contributions.extend(contribution) if pieces: return contributions else: return "\n".join(contributions)
def _format_open_brackets_slot(self, bundle): result = [] if self.is_simultaneous: if self.identifier: brackets_open = [f'<< {self.identifier}'] else: brackets_open = ['<<'] else: if self.identifier: brackets_open = [f'{{ {self.identifier}'] else: brackets_open = ['{'] if self.tag is not None: brackets_open = LilyPondFormatManager.tag( brackets_open, tag=self.tag, ) result.append([('open brackets', ''), brackets_open]) return tuple(result)
def _get_formatted_includes(self): result = [] tag = Tag("abjad.LilyPondFile._get_formatted_includes()") tag = self.get_tag(tag) for include in self.includes: if isinstance(include, str): string = rf'\include "{include}"' result.append(string) elif isinstance(include, pathlib.Path): string = rf'\include "{include!s}"' result.append(string) elif isinstance(include, LilyPondLiteral): string = str(include.argument) result.append(string) else: result.append(format(include)) if result: result = LilyPondFormatManager.tag(result, tag=tag) result = ["\n".join(result)] return result
def _list_format_contributions(self, directed=True): result = [] for attribute_tuple in self._get_attribute_tuples(): if len(attribute_tuple) == 2: grob = None attribute = attribute_tuple[0] value = attribute_tuple[1] elif len(attribute_tuple) == 3: grob = attribute_tuple[0] attribute = attribute_tuple[1] value = attribute_tuple[2] else: message = 'invalid attribute tuple: {attribute_tuple!r}.' raise ValueError(message) string = LilyPondFormatManager.make_lilypond_tweak_string( attribute, value, directed=directed, grob=grob, ) result.append(string) result.sort() return result
def _tag_strings(self, strings): return LilyPondFormatManager.tag(strings, tag=self.tag)
def _tag_show(strings): return LilyPondFormatManager.tag( strings, deactivate=True, tag=abjad_tags.SHOW_TO_JOIN_BROKEN_SPANNERS, )
def _format_leaf_nucleus(self): strings = self._get_body() if self.tag: tag = Tag(self.tag) strings = LilyPondFormatManager.tag(strings, tag=tag) return ["nucleus", strings]
def _tag_strings(self, strings): return LilyPondFormatManager.tag(strings, tag=self.tag)