Example #1
0
 def _make_global_context_block(
     font_size=3,
     minimum_distance=10,
     padding=4,
     ):
     assert isinstance(font_size, (int, float))
     assert isinstance(padding, (int, float))
     block = ContextBlock(
         type_='Engraver_group',
         name='GlobalContext',
         )
     block.consists_commands.append('Axis_group_engraver')
     block.consists_commands.append('Time_signature_engraver')
     time_signature_grob = override(block).time_signature
     time_signature_grob.X_extent = (0, 0)
     time_signature_grob.X_offset = Scheme(
         'ly:self-alignment-interface::x-aligned-on-self'
         )
     time_signature_grob.Y_extent = (0, 0)
     time_signature_grob.break_align_symbol = False
     time_signature_grob.break_visibility = Scheme(
         'end-of-line-invisible',
         )
     time_signature_grob.font_size = font_size
     time_signature_grob.self_alignment_X = Scheme('center')
     spacing_vector = SpacingVector(
         0,
         minimum_distance,
         padding,
         0,
         )
     grob = override(block).vertical_axis_group
     grob.default_staff_staff_spacing = spacing_vector
     return block
Example #2
0
    def __str__(self) -> str:
        r"""
        Gets string representation of staff change.

        ..  container:: example

            Default staff change:

            >>> staff_change = abjad.StaffChange()
            >>> print(str(staff_change))
            \change Staff = ##f

        ..  container:: example

            Explicit staff change:

            >>> lh_staff = abjad.Staff("s2", name='LHStaff')
            >>> staff_change = abjad.StaffChange(staff=lh_staff)
            >>> print(str(staff_change))
            \change Staff = LHStaff

        """
        if self.staff is None:
            return r"\change Staff = ##f"
        value = Scheme.format_scheme_value(self.staff.name)
        return rf"\change Staff = {value}"
Example #3
0
 def __call__(self) -> MarkupCommand:
     """
     Calls woodwind fingering.
     """
     key_groups_as_scheme = []
     cc_scheme_pair = SchemePair(("cc", self._center_column))
     key_groups_as_scheme.append(cc_scheme_pair)
     lh_scheme_pair = SchemePair(("lh", self._left_hand))
     key_groups_as_scheme.append(lh_scheme_pair)
     rh_scheme_pair = SchemePair(("rh", self._right_hand))
     key_groups_as_scheme.append(rh_scheme_pair)
     key_groups_as_scheme_ = Scheme(key_groups_as_scheme, quoting="'")
     instrument_as_scheme = Scheme(self._name, quoting="'")
     return MarkupCommand(
         "woodwind-diagram", instrument_as_scheme, key_groups_as_scheme_
     )
Example #4
0
 def _make_bow_contact_point_overrides(
     self,
     bow_contact_point=None,
     lilypond_format_bundle=None,
 ):
     if bow_contact_point is None:
         return
     override_ = LilyPondGrobOverride(
         grob_name='NoteHead',
         once=True,
         property_path='stencil',
         value=Scheme('ly:text-interface::print'),
     )
     string = override_.override_string
     lilypond_format_bundle.grob_overrides.append(string)
     override_ = LilyPondGrobOverride(
         grob_name='NoteHead',
         once=True,
         property_path='text',
         value=bow_contact_point.markup,
     )
     string = override_.override_string
     lilypond_format_bundle.grob_overrides.append(string)
     y_offset = float((4 * bow_contact_point.contact_point) - 2)
     override_ = LilyPondGrobOverride(
         grob_name='NoteHead',
         once=True,
         property_path='Y-offset',
         value=y_offset,
     )
     string = override_.override_string
     lilypond_format_bundle.grob_overrides.append(string)
Example #5
0
    def _get_formatted_user_attributes(self):
        from abjad.markups import Markup
        from abjad.scheme import Scheme
        from .LilyPondDimension import LilyPondDimension

        result = []
        prototype = Scheme
        for value in self.items:
            if isinstance(value, prototype):
                result.append(format(value, "lilypond"))
        prototype = (LilyPondDimension, Scheme)
        for key in self._public_attribute_names:
            assert not key.startswith("_"), repr(key)
            value = getattr(self, key)
            # format subkeys via double underscore
            formatted_key = key.split("__")
            for i, k in enumerate(formatted_key):
                formatted_key[i] = k.replace("_", "-")
                if 0 < i:
                    string = f"#'{formatted_key[i]}"
                    formatted_key[i] = string
            formatted_key = " ".join(formatted_key)
            # format value
            if isinstance(value, Markup):
                formatted_value = value._get_format_pieces()
            elif isinstance(value, prototype):
                formatted_value = [format(value, "lilypond")]
            else:
                formatted_value = Scheme(value)
                formatted_value = format(formatted_value, "lilypond")
                formatted_value = [formatted_value]
            setting = f"{formatted_key!s} = {formatted_value[0]!s}"
            result.append(setting)
            result.extend(formatted_value[1:])
        return result
Example #6
0
    def __str__(self) -> str:
        r"""
        Gets string representation of staff change.

        ..  container:: example

            Default staff change:

            >>> staff_change = abjad.StaffChange()
            >>> print(str(staff_change))
            \change Staff = ##f

        ..  container:: example

            Explicit staff change:

            >>> lh_staff = abjad.Staff("s2", name='LHStaff')
            >>> staff_change = abjad.StaffChange(staff=lh_staff)
            >>> print(str(staff_change))
            \change Staff = LHStaff

        """
        if self.staff is None:
            return r"\change Staff = ##f"
        value = Scheme.format_scheme_value(self.staff.name)
        return rf"\change Staff = {value}"
Example #7
0
    def tweak_string(self, directed=True, grob=False) -> str:
        r"""
        Gets LilyPond grob override \tweak string.

        ..  container:: example

            >>> override = abjad.LilyPondGrobOverride(
            ...     grob_name='Glissando',
            ...     property_path='style',
            ...     value=abjad.SchemeSymbol('zigzag'),
            ...     )
            >>> override.tweak_string()
            "- \\tweak style #'zigzag"

        ..  container:: example

            >>> override = abjad.LilyPondGrobOverride(
            ...     grob_name='RehearsalMark',
            ...     property_path='color',
            ...     value='red',
            ...     )
            >>> override.tweak_string(directed=False)
            '\\tweak color #red'

        ..  container:: example

            LilyPond literals are allowed:

            >>> override = abjad.LilyPondGrobOverride(
            ...     grob_name='TextSpann',
            ...     property_path=('bound-details', 'left-broken', 'text'),
            ...     value=abjad.LilyPondLiteral(r'\markup \upright pont.'),
            ...     )
            >>> override.tweak_string(directed=False)
            '\\tweak bound-details.left-broken.text \\markup \\upright pont.'

        """
        from abjad.indicators.LilyPondLiteral import LilyPondLiteral

        if directed:
            result = [r"- \tweak"]
        else:
            result = [r"\tweak"]
        if grob:
            property_path = (self.grob_name,) + self.property_path
        else:
            property_path = self.property_path
        string = ".".join(property_path)
        result.append(string)
        if isinstance(self.value, LilyPondLiteral):
            assert isinstance(self.value.argument, str)
            string = self.value.argument
        else:
            string = Scheme.format_embedded_scheme_value(self.value)
        result.append(string)
        return " ".join(result)
Example #8
0
 def format_lilypond_value(argument) -> str:
     """
     Formats LilyPond ``argument`` according to Scheme formatting
     conventions.
     """
     if "_get_lilypond_format" in dir(argument) and not isinstance(
         argument, str
     ):
         pass
     elif argument in (True, False):
         argument = Scheme(argument)
     elif argument in (
         enums.Up,
         enums.Down,
         enums.Left,
         enums.Right,
         enums.Center,
     ):
         argument = Scheme(repr(argument).lower())
     elif isinstance(argument, int) or isinstance(argument, float):
         argument = Scheme(argument)
     elif argument in Scheme.lilypond_color_constants:
         argument = Scheme(argument)
     elif isinstance(argument, str) and argument.startswith("#"):
         # argument = Scheme(argument)
         return argument
     elif isinstance(argument, str) and "::" in argument:
         argument = Scheme(argument)
     elif isinstance(argument, tuple) and len(argument) == 2:
         argument = SchemePair(argument)
     elif isinstance(argument, str) and " " not in argument:
         argument = Scheme(argument, quoting="'")
     elif isinstance(argument, str) and " " in argument:
         argument = Scheme(argument)
     else:
         argument = Scheme(argument, quoting="'")
     return format(argument, "lilypond")
Example #9
0
 def _get_lilypond_format(self):
     text, equation = None, None
     if self.textual_indication is not None:
         text = self.textual_indication
         text = Scheme.format_scheme_value(text)
     if self.reference_duration is not None and self.units_per_minute is not None:
         equation = self._equation
     if self.custom_markup is not None:
         return rf"\tempo {self.custom_markup}"
     elif text and equation:
         return rf"\tempo {text} {equation}"
     elif equation:
         return rf"\tempo {equation}"
     elif text:
         return rf"\tempo {text}"
     else:
         return r"\tempo \default"
Example #10
0
 def _get_lilypond_format_bundle(self, leaf):
     bundle = LilyPondFormatBundle()
     if len(self) == 1 and self._left_broken:
         strings = [self._stop_command_string()]
         strings = self._tag_show(strings)
         bundle.after.spanner_stops.extend(strings)
         return bundle
     # important: pitch trill must start AFTER markup
     if leaf is self[0]:
         if self.pitch is not None or self.interval is not None:
             if self.is_harmonic:
                 string = '(lambda (grob) (grob-interpret-markup grob'
                 string += r' #{ \markup \musicglyph #"noteheads.s0harmonic" #}))'
                 scheme = Scheme(string, verbatim=True)
                 override = LilyPondGrobOverride(
                     grob_name='TrillPitchHead',
                     property_path=('stencil', ),
                     value=scheme,
                 )
                 string = override.tweak_string(grob=True)
                 bundle.after.trill_spanner_starts.append(string)
             strings = [r'\pitchedTrill']
             if self._left_broken:
                 strings = self._tag_hide(strings)
             bundle.opening.spanners.extend(strings)
         if self.pitch is not None:
             pitch_string = str(self.pitch)
         elif self.interval is not None:
             pitch = leaf.written_pitch + self.interval
             pitch_string = str(pitch)
         else:
             pitch_string = None
         strings = self._tweaked_start_command_strings()
         if pitch_string:
             strings[-1] += ' ' + pitch_string
         if self._left_broken:
             strings = self._tag_hide(strings)
         bundle.after.trill_spanner_starts.extend(strings)
     if leaf is self[-1]:
         if 1 < len(self):
             strings = [self._stop_command_string()]
             if self._right_broken:
                 strings = self._tag_hide(strings)
             bundle.after.spanner_stops.extend(strings)
     return bundle
Example #11
0
    def override_format_pieces(self) -> typing.Tuple[str, ...]:
        r"""
        Gets LilyPond grob override \override format pieces.

        ..  container:: example

            >>> override = abjad.LilyPondGrobOverride(
            ...    lilypond_type='Staff',
            ...    grob_name='TextSpanner',
            ...    once=True,
            ...    property_path=(
            ...        'bound-details',
            ...        'left',
            ...        'text',
            ...        ),
            ...    value=abjad.Markup(r'\bold { over pressure }'),
            ...    )
            >>> for line in override.override_format_pieces:
            ...     line
            ...
            '\\once \\override Staff.TextSpanner.bound-details.left.text = \\markup {'
            '    \\bold'
            '        {'
            '            over'
            '            pressure'
            '        }'
            '    }'

        """
        result = []
        if self.once:
            result.append(r'\once')
        result.append(r'\override')
        result.append(self._override_property_path_string())
        result.append('=')
        string = Scheme.format_embedded_scheme_value(self.value)
        value_pieces = string.split('\n')
        result.append(value_pieces[0])
        result[:] = [' '.join(result)]
        result.extend(value_pieces[1:])
        return tuple(result)
Example #12
0
 def format_pieces(self) -> typing.Tuple[str, ...]:
     r"""
     Gets LilyPond context setting ``\set`` or ``\unset`` format pieces.
     """
     result = []
     if not self.is_unset:
         result.append(r"\set")
     else:
         result.append(r"\unset")
     if self.lilypond_type is not None:
         string = f"{self.lilypond_type}.{self.context_property}"
         result.append(string)
     else:
         result.append(self.context_property)
     result.append("=")
     string = Scheme.format_embedded_scheme_value(self.value)
     value_pieces = string.split("\n")
     result.append(value_pieces[0])
     result[:] = [" ".join(result)]
     result.extend(value_pieces[1:])
     return tuple(result)
Example #13
0
 def format_pieces(self) -> typing.Tuple[str, ...]:
     r"""
     Gets LilyPond context setting ``\set`` or ``\unset`` format pieces.
     """
     result = []
     if not self.is_unset:
         result.append(r"\set")
     else:
         result.append(r"\unset")
     if self.lilypond_type is not None:
         string = f"{self.lilypond_type}.{self.context_property}"
         result.append(string)
     else:
         result.append(self.context_property)
     result.append("=")
     string = Scheme.format_embedded_scheme_value(self.value)
     value_pieces = string.split("\n")
     result.append(value_pieces[0])
     result[:] = [" ".join(result)]
     result.extend(value_pieces[1:])
     return tuple(result)
Example #14
0
 def format_lilypond_value(argument) -> str:
     """
     Formats LilyPond ``argument`` according to Scheme formatting
     conventions.
     """
     if ('_get_lilypond_format' in dir(argument)
             and not isinstance(argument, str)):
         pass
     elif argument in (True, False):
         argument = Scheme(argument)
     elif argument in (enums.Up, enums.Down, enums.Left, enums.Right,
                       enums.Center):
         argument = Scheme(repr(argument).lower())
     elif isinstance(argument, int) or isinstance(argument, float):
         argument = Scheme(argument)
     elif argument in Scheme.lilypond_color_constants:
         argument = Scheme(argument)
     elif isinstance(argument, str) and argument.startswith('#'):
         argument = Scheme(argument)
     elif isinstance(argument, str) and '::' in argument:
         argument = Scheme(argument)
     elif isinstance(argument, tuple) and len(argument) == 2:
         argument = SchemePair(argument)
     elif isinstance(argument, str) and ' ' not in argument:
         argument = Scheme(argument, quoting="'")
     elif isinstance(argument, str) and ' ' in argument:
         argument = Scheme(argument)
     else:
         argument = Scheme(argument, quoting="'")
     return format(argument, 'lilypond')