Ejemplo n.º 1
0
def test_Inspection_timespan_26():
    """
    Offset seconds work with explicit metronome mark.
    """

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    mark = abjad.MetronomeMark(abjad.Duration(1, 8), 48)
    abjad.attach(mark, staff[0], context='Staff')

    assert format(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \tempo 8=48
            c'8
            d'8
            e'8
            f'8
        }
        """)

    start_offset = abjad.inspect(
        staff[0]).timespan(in_seconds=True).start_offset
    assert start_offset == abjad.Offset(0)
    start_offset = abjad.inspect(
        staff[1]).timespan(in_seconds=True).start_offset
    assert start_offset == abjad.Offset(5, 4)
Ejemplo n.º 2
0
def test_scoretools_VerticalMoment_attack_count_01():

    score = abjad.Score(r'''
        \new Staff {
            \times 4/3 {
                d''8
                c''8
                b'8
            }
        }
        \new PianoStaff <<
            \new Staff {
                a'4
                g'4
            }
            \new Staff {
                \clef "bass"
                f'8
                e'8
                d'8
                c'8
            }
        >>
        ''')

    vertical_moment = abjad.inspect(score).get_vertical_moment_at(abjad.Offset(0))
    assert vertical_moment.attack_count == 3

    vertical_moment = abjad.inspect(score).get_vertical_moment_at(abjad.Offset(1, 8))
    assert vertical_moment.attack_count == 1
Ejemplo n.º 3
0
def test_SilentQEvent___init___02():

    q_event = abjadext.nauert.SilentQEvent(abjad.Offset(155, 7),
                                           attachments=["foo", "bar", "baz"])

    assert q_event.offset == abjad.Offset(155, 7)
    assert q_event.attachments == ("foo", "bar", "baz")
Ejemplo n.º 4
0
    def from_millisecond_durations(class_, milliseconds, fuse_silences=False):
        r"""
        Convert a sequence of millisecond durations ``durations`` into
        a ``QEventSequence``:

        >>> durations = [-250, 500, -1000, 1250, -1000]
        >>> sequence = \
        ...     abjadext.nauert.QEventSequence.from_millisecond_durations(
        ...     durations)

        >>> for q_event in sequence:
        ...     print(format(q_event, 'storage'))
        ...
        abjadext.nauert.SilentQEvent(
            offset=abjad.Offset((0, 1)),
            )
        abjadext.nauert.PitchedQEvent(
            offset=abjad.Offset((250, 1)),
            pitches=(
                abjad.NamedPitch("c'"),
                ),
            )
        abjadext.nauert.SilentQEvent(
            offset=abjad.Offset((750, 1)),
            )
        abjadext.nauert.PitchedQEvent(
            offset=abjad.Offset((1750, 1)),
            pitches=(
                abjad.NamedPitch("c'"),
                ),
            )
        abjadext.nauert.SilentQEvent(
            offset=abjad.Offset((3000, 1)),
            )
        abjadext.nauert.TerminalQEvent(
            offset=abjad.Offset((4000, 1)),
            )

        Returns ``QEventSequence`` instance.
        """
        if fuse_silences:
            durations = [
                x for x in abjad.sequence(milliseconds).sum_by_sign(sign=[-1])
                if x
            ]
        else:
            durations = milliseconds
        offsets = abjad.mathx.cumulative_sums([abs(x) for x in durations])
        q_events = []
        for pair in zip(offsets, durations):
            offset = abjad.Offset(pair[0])
            duration = pair[1]
            # negative duration indicates silence
            if duration < 0:
                q_event = SilentQEvent(offset)
            else:
                q_event = PitchedQEvent(offset, [0])
            q_events.append(q_event)
        q_events.append(TerminalQEvent(abjad.Offset(offsets[-1])))
        return class_(q_events)
def test_quantizationtools_SilentQEvent___init___02():

    q_event = quantizationtools.SilentQEvent(abjad.Offset(155, 7),
                                             attachments=['foo', 'bar', 'baz'])

    assert q_event.offset == abjad.Offset(155, 7)
    assert q_event.attachments == ('foo', 'bar', 'baz')
def test_Selection__get_offset_lists_01():

    staff = abjad.Staff("c'4 d'4 e'4 f'4")
    selection = staff[:2]
    start_offsets, stop_offsets = selection._get_offset_lists()

    assert start_offsets == [abjad.Offset(0, 1), abjad.Offset(1, 4)]
    assert stop_offsets == [abjad.Offset(1, 4), abjad.Offset(1, 2)]
Ejemplo n.º 7
0
    def from_millisecond_pitch_pairs(
            class_, pairs: typing.Iterable[tuple]) -> "QEventSequence":
        r"""
        Changes millisecond-duration:pitch pairs ``pairs`` into a ``QEventSequence``:

        >>> durations = [250, 500, 1000, 1250, 1000]
        >>> pitches = [(0,), None, (2, 3), None, (1,)]
        >>> pairs = tuple(zip(durations, pitches))
        >>> sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
        ...     pairs)

        >>> for q_event in sequence:
        ...     q_event
        ...
        PitchedQEvent(offset=Offset((0, 1)), pitches=(NamedPitch("c'"),), index=None, attachments=())
        SilentQEvent(offset=Offset((250, 1)), index=None, attachments=())
        PitchedQEvent(offset=Offset((750, 1)), pitches=(NamedPitch("d'"), NamedPitch("ef'")), index=None, attachments=())
        SilentQEvent(offset=Offset((1750, 1)), index=None, attachments=())
        PitchedQEvent(offset=Offset((3000, 1)), pitches=(NamedPitch("cs'"),), index=None, attachments=())
        TerminalQEvent(offset=Offset((4000, 1)), index=None, attachments=())

        """
        assert isinstance(pairs, collections.abc.Iterable)
        assert all(isinstance(_, collections.abc.Iterable) for _ in pairs)
        assert all(len(_) == 2 for _ in pairs)
        assert all(0 < _[0] for _ in pairs)
        for _, pitches in pairs:
            assert isinstance(
                pitches,
                (numbers.Number, type(None), collections.abc.Sequence))
            if isinstance(pitches, collections.abc.Sequence):
                assert 0 < len(pitches)
                assert all(isinstance(_, numbers.Number) for _ in pitches)
        # fuse silences
        g = itertools.groupby(pairs, lambda x: x[1] is not None)
        groups = []
        for value, group in g:
            if value:
                groups.extend(list(group))
            else:
                duration = sum(x[0] for x in group)
                groups.append((duration, None))
        # find offsets
        offsets = abjad.math.cumulative_sums([abs(x[0]) for x in groups])
        # build QEvents
        q_events: list[QEvent] = []
        for pair in zip(offsets, groups):
            offset = abjad.Offset(pair[0])
            pitches = pair[1][1]
            if isinstance(pitches, collections.abc.Iterable):
                assert all(isinstance(x, numbers.Number) for x in pitches)
                q_events.append(PitchedQEvent(offset, pitches))
            elif isinstance(pitches, type(None)):
                q_events.append(SilentQEvent(offset))
            elif isinstance(pitches, int | float):
                q_events.append(PitchedQEvent(offset, [pitches]))
        q_events.append(TerminalQEvent(abjad.Offset(offsets[-1])))
        return class_(q_events)
Ejemplo n.º 8
0
def test_quantizationtools_PitchedQEvent___init___02():

    q_event = quantizationtools.PitchedQEvent(
        abjad.Offset(133, 5), [abjad.NamedPitch('fss')],
        attachments=['foo', 'bar', 'baz'])

    assert q_event.offset == abjad.Offset(133, 5)
    assert q_event.pitches == (abjad.NamedPitch('fss'), )
    assert q_event.attachments == ('foo', 'bar', 'baz')
Ejemplo n.º 9
0
def test_PitchedQEvent___init___02():
    q_event = abjadext.nauert.PitchedQEvent(
        abjad.Offset(133, 5),
        [abjad.NamedPitch("fss")],
        attachments=["foo", "bar", "baz"],
    )
    assert q_event.offset == abjad.Offset(133, 5)
    assert q_event.pitches == (abjad.NamedPitch("fss"), )
    assert q_event.attachments == ("foo", "bar", "baz")
Ejemplo n.º 10
0
 def __init__(
     self,
     start_offset=abjad.NegativeInfinity(),
     stop_offset=abjad.Infinity(),
     divisions=None,
     forbid_fusing=None,
     forbid_splitting=None,
     layer=None,
     minimum_duration=None,
     music=None,
     music_specifier=None,
     original_start_offset=None,
     original_stop_offset=None,
     voice_name=None,
     handler=None,
 ):
     abjad.Timespan.__init__(
         self,
         start_offset=start_offset,
         stop_offset=stop_offset,
     )
     if divisions is not None:
         divisions = tuple(abjad.Duration(_) for _ in divisions)
         assert sum(divisions) == self.duration
     self._divisions = divisions
     if forbid_fusing is not None:
         forbid_fusing = bool(forbid_fusing)
     self._forbid_fusing = forbid_fusing
     if forbid_splitting is not None:
         forbid_splitting = bool(forbid_splitting)
     self._forbid_splitting = forbid_splitting
     if layer is not None:
         layer = int(layer)
     self._layer = layer
     if minimum_duration is not None:
         minimum_duration = abjad.Duration(minimum_duration)
     self._minimum_duration = minimum_duration
     # if music is not None:
     #    assert inspect(music).get_duration() == self.duration
     self._music = music
     # if music_specifier is not None:
     #    assert isinstance(music_specifier, tsmakers.MusicSpecifier), \
     #        music_specifier
     self._music_specifier = music_specifier
     if original_start_offset is not None:
         original_start_offset = abjad.Offset(original_start_offset)
     else:
         original_start_offset = self.start_offset
     self._original_start_offset = original_start_offset
     if original_stop_offset is not None:
         original_stop_offset = abjad.Offset(original_stop_offset)
     else:
         original_stop_offset = self.stop_offset
     self._original_stop_offset = original_stop_offset
     self._voice_name = voice_name
     self._handler = handler
Ejemplo n.º 11
0
    def __illustrate__(self, range_=None, scale=None):
        r'''Illustrates offset counter.

        ..  container:: example

            >>> timespans = abjad.TimespanList([
            ...     abjad.Timespan(0, 16),
            ...     abjad.Timespan(5, 12),
            ...     abjad.Timespan(-2, 8),
            ...     ])
            >>> timespan_operand = abjad.Timespan(6, 10)
            >>> timespans = timespans - timespan_operand
            >>> offset_counter = abjad.OffsetCounter(timespans)
            >>> abjad.show(offset_counter, scale=0.5) # doctest: +SKIP

        Returns LilyPond file.
        '''
        import abjad
        if not self:
            return markuptools.Markup.null().__illustrate__()
        if isinstance(range_, abjad.Timespan):
            minimum, maximum = range_.start_offset, range_.stop_offset
        elif range_ is not None:
            minimum, maximum = range_
        else:
            minimum, maximum = min(self), max(self)
        minimum = float(abjad.Offset(minimum))
        maximum = float(abjad.Offset(maximum))
        if scale is None:
            scale = 1.
        assert 0 < scale
        postscript_scale = 150. / (maximum - minimum)
        postscript_scale *= float(scale)
        postscript_x_offset = (minimum * postscript_scale) - 1
        ps = markuptools.Postscript()
        ps = ps.setlinewidth(0.2)
        ps = ps.setdash([2, 1])
        for offset, count in sorted(self.items()):
            offset = (float(offset) * postscript_scale)
            offset -= postscript_x_offset
            ps = ps.moveto(offset, -1)
            ps = ps.rlineto(0, (float(count) * -3) + 1)
            ps = ps.stroke()
        markup = markuptools.Markup.postscript(ps)
        pieces = [markup]
        for offset in sorted(self):
            offset = abjad.Multiplier(offset)
            numerator, denominator = offset.numerator, offset.denominator
            fraction = abjad.Markup.fraction(numerator, denominator)
            fraction = fraction.center_align().fontsize(-3).sans()
            x_translation = (float(offset) * postscript_scale)
            x_translation -= postscript_x_offset
            fraction = fraction.translate((x_translation, 1))
            pieces.append(fraction)
        markup = abjad.Markup.overlay(pieces)
        return markup.__illustrate__()
Ejemplo n.º 12
0
def test_get_timespan_21():
    """
    Offsets work on nested tuplets.
    """

    tuplet_1 = abjad.Tuplet((1, 2), "c'8 d'8 e'8 f'8")
    contents = [abjad.Note("c'4"), tuplet_1, abjad.Note("c'4")]
    tuplet = abjad.Tuplet((2, 3), contents)
    assert abjad.get.timespan(tuplet[0]).start_offset == 0 * abjad.Offset(1, 6)
    assert abjad.get.timespan(tuplet[1]).start_offset == 1 * abjad.Offset(1, 6)
    assert abjad.get.timespan(tuplet[2]).start_offset == 2 * abjad.Offset(1, 6)
Ejemplo n.º 13
0
def test_get_timespan_22():
    """
    Offsets work on nested contexts.
    """

    inner_voice = abjad.Voice("c'8 d'8 e'8 f'8")
    outer_voice = abjad.Voice([abjad.Note(0, (1, 8)), inner_voice])
    inner_voice.name = outer_voice.name = "voice"
    abjad.Staff([abjad.Note(1, (1, 8)), outer_voice])
    assert abjad.get.timespan(inner_voice).start_offset == abjad.Offset(2, 8)
    assert abjad.get.timespan(outer_voice).start_offset == abjad.Offset(1, 8)
Ejemplo n.º 14
0
def test_QEventSequence_from_tempo_scaled_leaves_02():

    staff = abjad.Staff([])

    staff.append(abjad.Note(0, (1, 4)))
    staff.append(abjad.Rest((1, 4)))
    staff.append(abjad.Rest((1, 8)))
    staff.append(abjad.Note(1, (1, 8)))
    staff.append(abjad.Note(1, (1, 8)))
    staff.append(abjad.Note(2, (1, 8)))
    staff.append(abjad.Note(2, (1, 8)))
    staff.append(abjad.Note(3, (1, 8)))
    staff.append(abjad.Skip((1, 4)))
    staff.append(abjad.Rest((1, 4)))
    staff.append(abjad.Note(3, (1, 8)))
    staff.append(abjad.Chord([0, 1, 4], (1, 4)))

    abjad.tie(staff[3:5])
    abjad.tie(staff[5:7])

    tempo = abjad.MetronomeMark((1, 4), 58)
    abjad.attach(tempo, staff[0], context="Staff")
    tempo = abjad.MetronomeMark((1, 4), 77)
    abjad.attach(tempo, staff[9], context="Staff")

    leaves = abjad.select.leaves(staff)
    q_events = abjadext.nauert.QEventSequence.from_tempo_scaled_leaves(leaves)

    assert q_events == abjadext.nauert.QEventSequence(
        (
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(0, 1), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.SilentQEvent(abjad.Offset(30000, 29)),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(75000, 29), (abjad.NamedPitch("cs'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(105000, 29), (abjad.NamedPitch("d'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(135000, 29), (abjad.NamedPitch("ef'"),)
            ),
            abjadext.nauert.SilentQEvent(abjad.Offset(150000, 29)),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(15600000, 2233), (abjad.NamedPitch("ef'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(16470000, 2233),
                (
                    abjad.NamedPitch("c'"),
                    abjad.NamedPitch("cs'"),
                    abjad.NamedPitch("e'"),
                ),
            ),
            abjadext.nauert.TerminalQEvent(abjad.Offset(18210000, 2233)),
        )
    )
Ejemplo n.º 15
0
def test_scoretools_Inspection_get_timespan_17():
    r'''Prolated offset does NOT go across sequential staves.
    '''

    container = abjad.Container(
        [abjad.Staff("c'8 d'8 e'8 f'8"),
         abjad.Staff("c'8 d'8 e'8 f'8")])
    container[0].name = container[1].name = 'staff'
    start_offset = abjad.inspect(container[0]).get_timespan().start_offset
    assert start_offset == abjad.Offset(0)
    start_offset = abjad.inspect(container[1]).get_timespan().start_offset
    assert start_offset == abjad.Offset(1, 2)
Ejemplo n.º 16
0
def test_scoretools_Inspection_get_timespan_14():
    r'''Offset on leaves works in nested simultaneous and sequential contexts.
    '''

    voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_3 = abjad.Voice("c'8 d'8 e'8 f'8")
    staff = abjad.Staff([abjad.Container([voice_1, voice_2]), voice_3])
    staff[0].is_simultaneous = True
    for i, leaf in enumerate(voice_3):
        start_offset = abjad.inspect(leaf).get_timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8) + abjad.Offset(1, 2)
Ejemplo n.º 17
0
def test_scoretools_Inspection_get_timespan_22():
    r'''Offsets work on nested contexts.
    '''

    inner_voice = abjad.Voice("c'8 d'8 e'8 f'8")
    outer_voice = abjad.Voice([abjad.Note(0, (1, 8)), inner_voice])
    inner_voice.name = outer_voice.name = 'voice'
    staff = abjad.Staff([abjad.Note(1, (1, 8)), outer_voice])
    assert abjad.inspect(
        inner_voice).get_timespan().start_offset == abjad.Offset(2, 8)
    assert abjad.inspect(
        outer_voice).get_timespan().start_offset == abjad.Offset(1, 8)
Ejemplo n.º 18
0
def test_get_timespan_20():
    """
    Offsets work on tuplets between notes.
    """

    tuplet_1 = abjad.Tuplet((2, 3), "c'8 c'8 c'8")
    voice = abjad.Voice(
        [abjad.Note(0, (1, 8)), tuplet_1,
         abjad.Note(0, (1, 8))])
    assert abjad.get.timespan(voice[0]).start_offset == 0 * abjad.Offset(1, 8)
    assert abjad.get.timespan(voice[1]).start_offset == 1 * abjad.Offset(1, 8)
    assert abjad.get.timespan(voice[2]).start_offset == 3 * abjad.Offset(1, 8)
Ejemplo n.º 19
0
def test_scoretools_Inspection_get_timespan_19():
    r'''Offsets works on sequential tuplets.
    '''

    voice = abjad.Voice(3 *
                        abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8"))
    assert abjad.inspect(
        voice[0]).get_timespan().start_offset == 0 * abjad.Offset(1, 4)
    assert abjad.inspect(
        voice[1]).get_timespan().start_offset == 1 * abjad.Offset(1, 4)
    assert abjad.inspect(
        voice[2]).get_timespan().start_offset == 2 * abjad.Offset(1, 4)
Ejemplo n.º 20
0
def test_Inspection_timespan_19():
    """
    Offsets works on sequential tuplets.
    """

    voice = abjad.Voice(3 *
                        abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8"))
    assert abjad.inspect(
        voice[0]).timespan().start_offset == 0 * abjad.Offset(1, 4)
    assert abjad.inspect(
        voice[1]).timespan().start_offset == 1 * abjad.Offset(1, 4)
    assert abjad.inspect(
        voice[2]).timespan().start_offset == 2 * abjad.Offset(1, 4)
Ejemplo n.º 21
0
def test_Inspection_timespan_17():
    """
    Prolated offset does NOT go across sequential staves.
    """

    container = abjad.Container(
        [abjad.Staff("c'8 d'8 e'8 f'8"),
         abjad.Staff("c'8 d'8 e'8 f'8")])
    container[0].name = container[1].name = "staff"
    start_offset = abjad.inspect(container[0]).timespan().start_offset
    assert start_offset == abjad.Offset(0)
    start_offset = abjad.inspect(container[1]).timespan().start_offset
    assert start_offset == abjad.Offset(1, 2)
Ejemplo n.º 22
0
def test_scoretools_Inspection_get_timespan_21():
    r'''Offsets work on nested tuplets.
    '''

    tuplet_1 = abjad.Tuplet((1, 2), "c'8 d'8 e'8 f'8")
    contents = [abjad.Note("c'4"), tuplet_1, abjad.Note("c'4")]
    tuplet = abjad.Tuplet((2, 3), contents)
    assert abjad.inspect(
        tuplet[0]).get_timespan().start_offset == 0 * abjad.Offset(1, 6)
    assert abjad.inspect(
        tuplet[1]).get_timespan().start_offset == 1 * abjad.Offset(1, 6)
    assert abjad.inspect(
        tuplet[2]).get_timespan().start_offset == 2 * abjad.Offset(1, 6)
Ejemplo n.º 23
0
def test_scoretools_Inspection_get_timespan_12():
    r'''Offset on leaves works in sequential contexts.
    '''

    voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    staff = abjad.Staff([voice_1, voice_2])
    for i, leaf in enumerate(voice_1):
        start_offset = abjad.inspect(leaf).get_timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8)
    for i, leaf in enumerate(voice_2):
        start_offset = abjad.inspect(leaf).get_timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8) + abjad.Offset(1, 2)
Ejemplo n.º 24
0
def test_get_timespan_19():
    """
    Offsets works on sequential tuplets.
    """

    voice = abjad.Voice([
        abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8"),
        abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8"),
        abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8"),
    ])
    assert abjad.get.timespan(voice[0]).start_offset == 0 * abjad.Offset(1, 4)
    assert abjad.get.timespan(voice[1]).start_offset == 1 * abjad.Offset(1, 4)
    assert abjad.get.timespan(voice[2]).start_offset == 2 * abjad.Offset(1, 4)
Ejemplo n.º 25
0
def test_get_timespan_14():
    """
    Offset on leaves works in nested simultaneous and sequential contexts.
    """

    voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_3 = abjad.Voice("c'8 d'8 e'8 f'8")
    staff = abjad.Staff([abjad.Container([voice_1, voice_2]), voice_3])
    staff[0].simultaneous = True
    for i, leaf in enumerate(voice_3):
        start_offset = abjad.get.timespan(leaf).start_offset
        assert start_offset == i * abjad.Offset(1, 8) + abjad.Offset(1, 2)
Ejemplo n.º 26
0
def test_scoretools_VerticalMoment___len___01():

    score = abjad.Score(r'''
        \new Staff {
            \times 4/3 {
                d''8
                c''8
                b'8
            }
        }
        \new PianoStaff <<
            \new Staff {
                a'4
                g'4
            }
            \new Staff {
                \clef "bass"
                f'8
                e'8
                d'8
                c'8
            }
        >>
        ''')

    staff_group = score[1]

    vertical_moment = abjad.inspect(score).get_vertical_moment_at(
        abjad.Offset(1, 8))
    "VerticalMoment(abjad.Score<<2>>, abjad.Staff{1}, {@ 3:4 d''8, c''8, b'8 @}, d''8, PianoStaff<<2>>, abjad.Staff{2}, a'4, abjad.Staff{4}, e'8)"
    assert len(vertical_moment) == 9

    vertical_moment = abjad.inspect(score[0]).get_vertical_moment_at(
        abjad.Offset(1, 8))
    "VerticalMoment(abjad.Staff{1}, {@ 3:4 d''8, c''8, b'8 @}, d''8)"
    assert len(vertical_moment) == 3

    vertical_moment = abjad.inspect(staff_group).get_vertical_moment_at(
        abjad.Offset(1, 8))
    "VerticalMoment(PianoStaff<<2>>, abjad.Staff{2}, a'4, abjad.Staff{4}, e'8)"
    assert len(vertical_moment) == 5

    vertical_moment = abjad.inspect(staff_group[0]).get_vertical_moment_at(
        abjad.Offset(1, 8))
    "VerticalMoment(abjad.Staff{2}, a'4)"
    assert len(vertical_moment) == 2

    vertical_moment = abjad.inspect(staff_group[1]).get_vertical_moment_at(
        abjad.Offset(1, 8))
    "VerticalMoment(abjad.Staff{2}, e'8)"
    assert len(vertical_moment) == 2
Ejemplo n.º 27
0
def test_get_timespan_12():
    """
    Offset on leaves works in sequential contexts.
    """

    voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.Staff([voice_1, voice_2])
    for i, leaf in enumerate(voice_1):
        start_offset = abjad.get.timespan(leaf).start_offset
        assert start_offset == i * abjad.Offset(1, 8)
    for i, leaf in enumerate(voice_2):
        start_offset = abjad.get.timespan(leaf).start_offset
        assert start_offset == i * abjad.Offset(1, 8) + abjad.Offset(1, 2)
Ejemplo n.º 28
0
def test_QEventSequence_from_tempo_scaled_leaves_01():

    staff = abjad.Staff([])

    staff.append(abjad.Note(0, (1, 4)))
    staff.append(abjad.Rest((1, 4)))
    staff.append(abjad.Rest((1, 8)))
    staff.append(abjad.Note(1, (1, 8)))
    staff.append(abjad.Note(1, (1, 8)))
    staff.append(abjad.Note(2, (1, 8)))
    staff.append(abjad.Note(2, (1, 8)))
    staff.append(abjad.Note(3, (1, 8)))
    staff.append(abjad.Skip((1, 4)))
    staff.append(abjad.Rest((1, 4)))
    staff.append(abjad.Note(3, (1, 8)))
    staff.append(abjad.Chord([0, 1, 4], (1, 4)))

    abjad.tie(staff[3:5])
    abjad.tie(staff[5:7])

    tempo = abjad.MetronomeMark((1, 4), 55)

    leaves = abjad.select.leaves(staff)
    q_events = abjadext.nauert.QEventSequence.from_tempo_scaled_leaves(leaves, tempo)

    assert q_events == abjadext.nauert.QEventSequence(
        (
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(0, 1), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.SilentQEvent(abjad.Offset(12000, 11)),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(30000, 11), (abjad.NamedPitch("cs'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(42000, 11), (abjad.NamedPitch("d'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(54000, 11), (abjad.NamedPitch("ef'"),)
            ),
            abjadext.nauert.SilentQEvent(abjad.Offset(60000, 11)),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(84000, 11), (abjad.NamedPitch("ef'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(90000, 11),
                (
                    abjad.NamedPitch("c'"),
                    abjad.NamedPitch("cs'"),
                    abjad.NamedPitch("e'"),
                ),
            ),
            abjadext.nauert.TerminalQEvent(abjad.Offset(102000, 11)),
        )
    )
Ejemplo n.º 29
0
def test_scoretools_Inspection_get_timespan_20():
    r'''Offsets work on tuplets between notes.
    '''

    tuplet_1 = abjad.Tuplet((2, 3), "c'8 c'8 c'8")
    voice = abjad.Voice(
        [abjad.Note(0, (1, 8)), tuplet_1,
         abjad.Note(0, (1, 8))])
    assert abjad.inspect(
        voice[0]).get_timespan().start_offset == 0 * abjad.Offset(1, 8)
    assert abjad.inspect(
        voice[1]).get_timespan().start_offset == 1 * abjad.Offset(1, 8)
    assert abjad.inspect(
        voice[2]).get_timespan().start_offset == 3 * abjad.Offset(1, 8)
Ejemplo n.º 30
0
def test_scoretools_Inspection_get_timespan_10():
    r'''Offset works with simultaneous structures.
    '''

    voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    staff = abjad.Staff([voice_1, voice_2])
    staff.is_simultaneous = True
    for i, leaf in enumerate(voice_1):
        start_offset = abjad.inspect(leaf).get_timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8)
    for i, leaf in enumerate(voice_2):
        start_offset = abjad.inspect(leaf).get_timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8)