Beispiel #1
0
    def __add__(self, argument):
        """
        Adds typed tuple to ``argument``.

        Returns new typed tuple.
        """

        if isinstance(argument, type(self)):
            items = argument._collection
            return new(self, items=self._collection[:] + items)
        elif isinstance(argument, type(self._collection)):
            items = argument[:]
            return new(self, items=self._collection[:] + items)
        raise NotImplementedError
Beispiel #2
0
    def rotate(self, n=0):
        """
        Rotates interval segment by index `n`.

        Returns new interval segment.
        """
        return new(self, self[-n:] + self[:-n])
Beispiel #3
0
    def invert(self, axis):
        """
        Inverts pitch set about `axis`.

        Returns new pitch set.
        """
        items = (pitch.invert(axis) for pitch in self)
        return new(self, items=items)
Beispiel #4
0
    def __mul__(self, argument):
        """
        Multiplies typed tuple by ``argument``.

        Returns new typed tuple.
        """
        items = self._collection * argument
        return new(self, items=items)
Beispiel #5
0
 def _get_lilypond_format_bundle(self, component=None):
     bundle = LilyPondFormatBundle()
     if not self.hide:
         markup = self._get_markup()
         markup = new(markup, direction=enums.Up)
         markup_format_pieces = markup._get_format_pieces()
         bundle.after.markup.extend(markup_format_pieces)
     return bundle
Beispiel #6
0
    def transpose(self, n=0):
        """
        Transposes pitch set by index `n`.

        Returns new pitch set.
        """
        items = (pitch.transpose(n=n) for pitch in self)
        return new(self, items=items)
Beispiel #7
0
    def invert(self, axis):
        """
        Inverts pitch set about `axis`.

        Returns new pitch set.
        """
        items = (pitch.invert(axis) for pitch in self)
        return new(self, items=items)
Beispiel #8
0
 def _get_lilypond_format_bundle(self, component=None):
     bundle = LilyPondFormatBundle()
     if not self.hide:
         markup = self._get_markup()
         markup = new(markup, direction=enums.Up)
         markup_format_pieces = markup._get_format_pieces()
         bundle.after.markup.extend(markup_format_pieces)
     return bundle
Beispiel #9
0
    def transpose(self, n=0):
        """
        Transposes pitch set by index `n`.

        Returns new pitch set.
        """
        items = (pitch.transpose(n=n) for pitch in self)
        return new(self, items=items)
Beispiel #10
0
 def _get_lilypond_format_bundle(self, component=None):
     bundle = LilyPondFormatBundle()
     if self.tweaks:
         tweaks = self.tweaks._list_format_contributions()
         bundle.after.markup.extend(tweaks)
     markup = self.markup
     markup = new(markup, direction=enums.Up)
     markup_format_pieces = markup._get_format_pieces()
     bundle.after.markup.extend(markup_format_pieces)
     return bundle
Beispiel #11
0
 def _get_lilypond_format_bundle(self, component=None):
     bundle = LilyPondFormatBundle()
     if self.tweaks:
         tweaks = self.tweaks._list_format_contributions()
         bundle.after.markup.extend(tweaks)
     markup = self.markup
     markup = new(markup, direction=enums.Up)
     markup_format_pieces = markup._get_format_pieces()
     bundle.after.markup.extend(markup_format_pieces)
     return bundle
Beispiel #12
0
    def __copy__(self, *arguments):
        r"""
        Copies rehearsal mark.

        >>> import copy

        ..  container:: example

            Preserves tweaks:

            >>> mark = abjad.RehearsalMark(number=1)
            >>> abjad.tweak(mark).color = 'red'
            >>> staff = abjad.Staff("c'4 d' e' f'")
            >>> abjad.attach(mark, staff[0])
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                {
                    \tweak color #red
                    \mark #1
                    c'4
                    d'4
                    e'4
                    f'4
                }

            >>> mark = copy.copy(mark)
            >>> staff = abjad.Staff("c'4 d' e' f'")
            >>> abjad.attach(mark, staff[0])
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                {
                    \tweak color #red
                    \mark #1
                    c'4
                    d'4
                    e'4
                    f'4
                }

        """
        mark_ = new(self)
        mark_._tweaks = copy.copy(self.tweaks)
        return mark_
Beispiel #13
0
    def __copy__(self, *arguments):
        r"""
        Copies rehearsal mark.

        >>> import copy

        ..  container:: example

            Preserves tweaks:

            >>> mark = abjad.RehearsalMark(number=1)
            >>> abjad.tweak(mark).color = 'red'
            >>> staff = abjad.Staff("c'4 d' e' f'")
            >>> abjad.attach(mark, staff[0])
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                {
                    \tweak color #red
                    \mark #1
                    c'4
                    d'4
                    e'4
                    f'4
                }

            >>> mark = copy.copy(mark)
            >>> staff = abjad.Staff("c'4 d' e' f'")
            >>> abjad.attach(mark, staff[0])
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                {
                    \tweak color #red
                    \mark #1
                    c'4
                    d'4
                    e'4
                    f'4
                }

        """
        mark_ = new(self)
        mark_._tweaks = copy.copy(self.tweaks)
        return mark_
Beispiel #14
0
    def _is_equivalent_under_transposition(self, argument):
        """
        True if pitch set is equivalent to `argument` under transposition.

        Returns true or false.
        """
        import abjad

        if not isinstance(argument, type(self)):
            return False
        if not len(self) == len(argument):
            return False
        difference = -(abjad.NamedPitch(argument[0], 4) - abjad.NamedPitch(self[0], 4))
        new_pitches = (x + difference for x in self)
        new_pitches = new(self, items=new_pitches)
        return argument == new_pitches
Beispiel #15
0
    def _is_equivalent_under_transposition(self, argument):
        """
        True if pitch set is equivalent to `argument` under transposition.

        Returns true or false.
        """
        import abjad

        if not isinstance(argument, type(self)):
            return False
        if not len(self) == len(argument):
            return False
        difference = -(
            abjad.NamedPitch(argument[0], 4) - abjad.NamedPitch(self[0], 4)
        )
        new_pitches = (x + difference for x in self)
        new_pitches = new(self, items=new_pitches)
        return argument == new_pitches
Beispiel #16
0
 def _get_lilypond_format(self, context=None):
     result = []
     markup = self.markup
     if markup.direction is not None:
         markup = new(
             markup,
             direction=None,
         )
     if isinstance(context, str):
         pass
     elif context is not None:
         context = context.lilypond_type
     else:
         context = self._lilypond_type
     pieces = markup._get_format_pieces()
     result.append(rf'\set {context!s}.instrumentName =')
     result.extend(pieces)
     return result
Beispiel #17
0
 def __illustrate__(
     self, default_paper_size=None, global_staff_size=None, includes=None
 ):
     """
     Illustrates score template.
     """
     score: Score = self()
     for voice in iterate(score).components(Voice):
         skip = Skip(1, tag="abjad.ScoreTemplate.__illustrate__")
         voice.append(skip)
     self.attach_defaults(score)
     lilypond_file: LilyPondFile = score.__illustrate__()
     lilypond_file = new(
         lilypond_file,
         default_paper_size=default_paper_size,
         global_staff_size=global_staff_size,
         includes=includes,
     )
     return lilypond_file
Beispiel #18
0
 def __illustrate__(
     self, default_paper_size=None, global_staff_size=None, includes=None
 ):
     """
     Illustrates score template.
     """
     score: Score = self()
     for voice in iterate(score).components(Voice):
         skip = Skip(1, tag="abjad.ScoreTemplate.__illustrate__")
         voice.append(skip)
     self.attach_defaults(score)
     lilypond_file: LilyPondFile = score.__illustrate__()
     lilypond_file = new(
         lilypond_file,
         default_paper_size=default_paper_size,
         global_staff_size=global_staff_size,
         includes=includes,
     )
     return lilypond_file
Beispiel #19
0
 def _get_lilypond_format(self, context=None):
     result = []
     if isinstance(context, str):
         pass
     elif context is not None:
         context = context.lilypond_type
     else:
         context = self._lilypond_type
     if isinstance(self.markup, Markup):
         markup = self.markup
         if markup.direction is not None:
             markup = new(markup, direction=None)
         pieces = markup._get_format_pieces()
         result.append(rf"\set {context!s}.shortInstrumentName =")
         result.extend(pieces)
     else:
         assert isinstance(self.markup, str)
         string = rf"\set {context!s}.shortInstrumentName = {self.markup}"
         result.append(string)
     return result
Beispiel #20
0
 def _get_lilypond_format(self, context=None):
     result = []
     if isinstance(context, str):
         pass
     elif context is not None:
         context = context.lilypond_type
     else:
         context = self._lilypond_type
     if isinstance(self.markup, Markup):
         markup = self.markup
         if markup.direction is not None:
             markup = new(markup, direction=None)
         pieces = markup._get_format_pieces()
         result.append(rf"\set {context!s}.instrumentName =")
         result.extend(pieces)
     else:
         assert isinstance(self.markup, str)
         string = rf"\set {context!s}.instrumentName = {self.markup}"
         result.append(string)
     return result
Beispiel #21
0
    def __div__(self, argument) -> "MetronomeMark":
        """
        Divides metronome mark by ``argument``.

        ..  container:: example

            Divides metronome mark by number:

            >>> abjad.MetronomeMark((1, 4), 60) / 2
            MetronomeMark(reference_duration=Duration(1, 4), units_per_minute=30)

        ..  container:: example

            Divides metronome mark by other metronome mark:

            >>> abjad.MetronomeMark((1, 4), 60) / abjad.MetronomeMark((1, 4), 40)
            Multiplier(3, 2)

        """
        if self.is_imprecise:
            raise exceptions.ImpreciseMetronomeMarkError
        if getattr(argument, "is_imprecise", False):
            raise exceptions.ImpreciseMetronomeMarkError
        assert isinstance(self.quarters_per_minute, Fraction)
        if isinstance(argument, type(self)):
            assert isinstance(argument.quarters_per_minute, Fraction)
            result = self.quarters_per_minute / argument.quarters_per_minute
            return Multiplier(result)
        elif isinstance(argument, (int, Fraction)):
            assert isinstance(self.units_per_minute, (int, Fraction))
            units_per_minute = self.units_per_minute / argument
            if mathtools.is_integer_equivalent_number(units_per_minute):
                units_per_minute = int(units_per_minute)
            else:
                units_per_minute = Fraction(units_per_minute)
            result = new(self, units_per_minute=units_per_minute)
            return result
        else:
            raise TypeError(f"must be number or metronome mark: {argument!r}.")
    def is_tertian(self):
        """
        Is true when all named interval-classes in segment are tertian.

        ..  container:: example

            >>> interval_class_segment = abjad.IntervalClassSegment(
            ...     items=[('major', 3), ('minor', 6), ('major', 6)],
            ...     item_class=abjad.NamedIntervalClass,
            ...     )
            >>> interval_class_segment.is_tertian
            True

        Returns true or false.
        """
        import abjad

        inversion_equivalent_interval_class_segment = new(
            self, item_class=abjad.NamedInversionEquivalentIntervalClass)
        for interval in inversion_equivalent_interval_class_segment:
            if not interval.number == 3:
                return False
        return True
Beispiel #23
0
 def __radd__(self, argument):
     """
     Right-adds ``argument`` to typed tuple.
     """
     items = argument + self._collection
     return new(self, items=items)
Beispiel #24
0
    def invert(self, axis=None):
        r"""
        Inverts row about optional `axis`.

        ..  container:: example

            Example row:

            >>> numbers = [1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8, 0]
            >>> row = abjad.TwelveToneRow(numbers)
            >>> abjad.show(row) # doctest: +SKIP

        ..  container:: example

            Inverts row about first pitch-class when `axis` is none:

            >>> inversion = row.invert()
            >>> abjad.show(inversion) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = inversion.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    cs'8
                    ef'8
                    f'8
                    b'8
                    af'8
                    g'8
                    a'8
                    bf'8
                    e'8
                    c'8
                    fs'8
                    d'8
                    \bar "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

            First pitch-classes are equal:

            >>> row[0] == inversion[0]
            True

        ..  container:: example

            Inverts row about pitch-class 1:

            >>> inversion = row.invert(axis=1)
            >>> abjad.show(inversion) # doctest: +SKIP
            TwelveToneRow([1, 3, 5, 11, 8, 7, 9, 10, 4, 0, 6, 2])

            ..  docs::

                >>> lilypond_file = inversion.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    cs'8
                    ef'8
                    f'8
                    b'8
                    af'8
                    g'8
                    a'8
                    bf'8
                    e'8
                    c'8
                    fs'8
                    d'8
                    \bar "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

            Same result as above.

        ..  container:: example

            Inverts row about pitch-class 0:

            >>> inversion = row.invert(axis=0)
            >>> abjad.show(inversion) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = inversion.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    b'8
                    cs'8
                    ef'8
                    a'8
                    fs'8
                    f'8
                    g'8
                    af'8
                    d'8
                    bf'8
                    e'8
                    c'8
                    \bar "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

        ..  container:: example

            Inverts row about pitch-class 5:

            >>> inversion = row.invert(axis=5)
            >>> abjad.show(inversion) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = inversion.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    a'8
                    b'8
                    cs'8
                    g'8
                    e'8
                    ef'8
                    f'8
                    fs'8
                    c'8
                    af'8
                    d'8
                    bf'8
                    \bar "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

        ..  container:: example

            Returns twelve-tone row:

            >>> inversion
            TwelveToneRow([9, 11, 1, 7, 4, 3, 5, 6, 0, 8, 2, 10])

        """
        if axis is None:
            axis = self[0]
        items = [pc.invert(axis=axis) for pc in self]
        return new(self, items=items)