예제 #1
0
파일: NoteHead.py 프로젝트: Abjad/abjad
 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
예제 #2
0
 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
예제 #3
0
 def _tag_hide(strings):
     abjad_tags = Tags()
     return LilyPondFormatManager.tag(
         strings,
         deactivate=False,
         tag=abjad_tags.HIDE_TO_JOIN_BROKEN_SPANNERS,
     )
예제 #4
0
파일: LilyPondFile.py 프로젝트: Abjad/abjad
 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
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
 def _tag_hide(strings):
     abjad_tags = Tags()
     return LilyPondFormatManager.tag(
         strings,
         deactivate=False,
         tag=abjad_tags.HIDE_TO_JOIN_BROKEN_SPANNERS,
     )
예제 #9
0
파일: Block.py 프로젝트: aarongrisez/abjad
    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
예제 #10
0
파일: Leaf.py 프로젝트: aarongrisez/abjad
 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]
예제 #11
0
 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
예제 #12
0
파일: LilyPondFile.py 프로젝트: Abjad/abjad
 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
예제 #13
0
파일: Container.py 프로젝트: tuchang/abjad
 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)
예제 #14
0
파일: Container.py 프로젝트: tuchang/abjad
 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)
예제 #15
0
파일: Container.py 프로젝트: Abjad/abjad
 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)
예제 #16
0
파일: LilyPondFile.py 프로젝트: Abjad/abjad
 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
예제 #17
0
파일: Container.py 프로젝트: Abjad/abjad
 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)
예제 #18
0
 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
예제 #19
0
 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)
예제 #20
0
 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)
예제 #21
0
 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
예제 #22
0
파일: Leaf.py 프로젝트: Abjad/abjad
 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]
예제 #23
0
 def _tag_strings(self, strings):
     return LilyPondFormatManager.tag(strings, tag=self.tag)
예제 #24
0
 def _tag_show(strings):
     return LilyPondFormatManager.tag(
         strings,
         deactivate=True,
         tag=abjad_tags.SHOW_TO_JOIN_BROKEN_SPANNERS,
     )
예제 #25
0
파일: Component.py 프로젝트: Abjad/abjad
 def _tag_strings(self, strings):
     return LilyPondFormatManager.tag(strings, tag=self.tag)