Esempio n. 1
0
    def lilypond_format(self):
        r"""LilyPond input format of note head:

        ::

            >>> note_head = notetools.NoteHead("cs''")
            >>> note_head.lilypond_format
            "cs''"

        Returns string.
        """
        from abjad.tools import formattools
        from abjad.tools import scoretools

        # make sure note head has pitch
        assert self.written_pitch
        result = []
        # format chord note head with optional tweaks
        if isinstance(self._client, scoretools.Chord):
            for key, value in vars(self.tweak).iteritems():
                if not key.startswith("_"):
                    result.append(
                        r"\tweak %s %s"
                        % (formattools.format_lilypond_attribute(key), formattools.format_lilypond_value(value))
                    )
        # format note head pitch
        kernel = self.written_pitch.lilypond_format
        if self.is_forced:
            kernel += "!"
        if self.is_cautionary:
            kernel += "?"
        result.append(kernel)
        result = "\n".join(result)
        # return formatted note head
        return result
def _format_lilypond_context_setting_in_with_block(name, value):
    from abjad.tools import formattools

    name = name.split('_')
    first = name[0:1]
    rest = name[1:]
    rest = [x.title() for x in rest]
    name = first + rest
    name = ''.join(name)
    value = formattools.format_lilypond_value(value)
    result = r'{} = {}'.format(name, value)
    return result
def _format_lilypond_context_setting_inline(name, value, context=None):
    from abjad.tools import formattools

    name = name.split('_')
    first = name[0:1]
    rest = name[1:]
    rest = [x.title() for x in rest]
    name = first + rest
    name = ''.join(name)
    value = formattools.format_lilypond_value(value)
    if context is not None:
        context_string = context[1:]
        context_string = context_string.split('_')
        context_string = [x.title() for x in context_string]
        context_string = ''.join(context_string)
        context_string += '.'
    else:
        context_string = ''

    result = r'\set {}{} = {}'
    result = result.format(context_string, name, value)

    return result