Пример #1
0
def timespan_2_happens_during_timespan_1(
    timespan_1=None,
    timespan_2=None,
    hold=False,
):
    r'''Makes time relation indicating that `timespan_2` happens
    during `timespan_1`.

    ::

        >>> relation = timespantools.timespan_2_happens_during_timespan_1()
        >>> print(format(relation))
        timespantools.TimespanTimespanTimeRelation(
            inequality=timespantools.CompoundInequality(
                [
                    timespantools.SimpleInequality('timespan_1.start_offset <= timespan_2.start_offset'),
                    timespantools.SimpleInequality('timespan_2.stop_offset <= timespan_1.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    ..  container:: example

        Evaluates whether timespan ``[7/8, 8/8)`` happens
        during timespan ``[1/2, 3/2)``:

        ::

            >>> timespan_1 = timespantools.Timespan(Offset(1, 2), Offset(3, 2))
            >>> timespan_2 = timespantools.Timespan(Offset(7, 8), Offset(8, 8))
            >>> timespantools.timespan_2_happens_during_timespan_1(
            ...     timespan_1=timespan_1,
            ...     timespan_2=timespan_2,
            ...     )
            True

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_1.start_offset <= timespan_2.start_offset',
        'timespan_2.stop_offset <= timespan_1.stop_offset',
    ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
    )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation
def timespan_2_overlaps_only_start_of_timespan_1(
    timespan_1=None,
    timespan_2=None,
    hold=False,
    ):
    r'''Makes time relation indicating that `timespan_2` happens during
    `timespan_1`.

    ..  container:: example

        >>> relation = abjad.timespantools.timespan_2_overlaps_only_start_of_timespan_1()
        >>> abjad.f(relation)
        abjad.timespantools.TimespanTimespanTimeRelation(
            inequality=abjad.timespantools.CompoundInequality(
                [
                    abjad.TimespanInequality('timespan_2.start_offset < timespan_1.start_offset'),
                    abjad.TimespanInequality('timespan_1.start_offset < timespan_2.stop_offset'),
                    abjad.TimespanInequality('timespan_2.stop_offset <= timespan_1.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_2.start_offset < timespan_1.start_offset',
        'timespan_1.start_offset < timespan_2.stop_offset',
        'timespan_2.stop_offset <= timespan_1.stop_offset',
        ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
        )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation
def timespan_2_overlaps_only_stop_of_timespan_1(
    timespan_1=None,
    timespan_2=None,
    hold=False,
    ):
    r'''Makes time relation indicating that `timespan_2` overlaps
    only stop of  `timespan_1`.

    ::

        >>> relation = timespantools.timespan_2_overlaps_only_stop_of_timespan_1()
        >>> print(format(relation))
        timespantools.TimespanTimespanTimeRelation(
            inequality=timespantools.CompoundInequality(
                [
                    timespantools.Inequality('timespan_1.start_offset <= timespan_2.start_offset'),
                    timespantools.Inequality('timespan_2.start_offset < timespan_1.stop_offset'),
                    timespantools.Inequality('timespan_1.stop_offset < timespan_2.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_1.start_offset <= timespan_2.start_offset',
        'timespan_2.start_offset < timespan_1.stop_offset',
        'timespan_1.stop_offset < timespan_2.stop_offset',
        ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
        )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation
Пример #4
0
def timespan_2_starts_when_timespan_1_stops(
    timespan_1=None,
    timespan_2=None,
    hold=False,
):
    r'''Makes time relation indicating that `timespan_2` happens
    during `timespan_1`.

    ::

        >>> relation = timespantools.timespan_2_starts_when_timespan_1_stops()
        >>> print(format(relation))
        timespantools.TimespanTimespanTimeRelation(
            inequality=timespantools.CompoundInequality(
                [
                    timespantools.SimpleInequality('timespan_2.start_offset == timespan_1.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_2.start_offset == timespan_1.stop_offset',
    ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
    )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation
Пример #5
0
def timespan_2_contains_timespan_1_improperly(
    timespan_1=None,
    timespan_2=None,
    hold=False,
    ):
    r'''Makes time relation indicating that `timespan_2` contains
    `timespan_1` improperly.

    ::

        >>> relation = timespantools.timespan_2_contains_timespan_1_improperly()
        >>> print(format(relation))
        timespantools.TimespanTimespanTimeRelation(
            inequality=timespantools.CompoundInequality(
                [
                    timespantools.SimpleInequality('timespan_2.start_offset <= timespan_1.start_offset'),
                    timespantools.SimpleInequality('timespan_1.stop_offset <= timespan_2.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    ..  container:: example

        ::

            >>> staff = Staff(r"c'8. \p \< fs'16 a'4 af'8 \f \> g'8 ~ g'16 f' e' ef' \p")
            >>> timespan_1 = timespantools.Timespan(Offset(1, 4), Offset(3, 8))
            >>> show(staff) # doctest: +SKIP

        ::

            >>> offset_lists = staff[:]._get_offset_lists()
            >>> time_relation = timespantools.timespan_2_contains_timespan_1_improperly(timespan_1=timespan_1)
            >>> start_index, stop_index = time_relation.get_offset_indices(*offset_lists)
            >>> selected_notes = staff[start_index:stop_index]
            >>> selected_notes
            SliceSelection(Note("a'4"),)

        ::

            >>> labeltools.color_leaves_in_expr(selected_notes, 'red')
            >>> show(staff) # doctest: +SKIP

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_2.start_offset <= timespan_1.start_offset',
        'timespan_1.stop_offset <= timespan_2.stop_offset',
        ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
        )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation
Пример #6
0
def timespan_2_starts_during_timespan_1(
    timespan_1=None,
    timespan_2=None,
    hold=False,
):
    r'''Makes time relation indicating that `timespan_2` starts
    during `timespan_1`.

    ::

        >>> relation = timespantools.timespan_2_starts_during_timespan_1()
        >>> print(format(relation))
        timespantools.TimespanTimespanTimeRelation(
            inequality=timespantools.CompoundInequality(
                [
                    timespantools.SimpleInequality('timespan_1.start_offset <= timespan_2.start_offset'),
                    timespantools.SimpleInequality('timespan_2.start_offset < timespan_1.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    ..  container:: example

        ::

            >>> staff_1 = Staff("c'4 d'4 e'4 f'4 g'2 c''2")
            >>> staff_2 = Staff("c'2 b'2 a'2 g'2")
            >>> score = Score([staff_1, staff_2])
            >>> show(score) # doctest: +SKIP

        ::

            >>> start_offsets = [inspect_(note).get_timespan().start_offset for note in staff_1]
            >>> stop_offsets = [inspect_(note).get_timespan().stop_offset for note in staff_1]

        ::

            >>> timespan_1 = timespantools.Timespan(Offset(1, 4), Offset(5, 4))
            >>> time_relation = \
            ...     timespantools.timespan_2_starts_during_timespan_1(
            ...     timespan_1=timespan_1)
            >>> start_index, stop_index = time_relation.get_offset_indices(
            ...     start_offsets, stop_offsets)

        ::

            >>> selected_notes = staff_1[start_index:stop_index]
            >>> selected_notes
            SliceSelection(Note("d'4"), Note("e'4"), Note("f'4"), Note("g'2"))

        ::

            >>> labeltools.color_leaves_in_expr(selected_notes, 'red')

        ::

            >>> show(score) # doctest: +SKIP

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_1.start_offset <= timespan_2.start_offset',
        'timespan_2.start_offset < timespan_1.stop_offset',
    ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
    )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation
def timespan_2_starts_during_timespan_1(
    timespan_1=None,
    timespan_2=None,
    hold=False,
):
    r'''Makes time relation indicating that `timespan_2` starts
    during `timespan_1`.

    ..  container:: example

        >>> relation = abjad.timespantools.timespan_2_starts_during_timespan_1()
        >>> abjad.f(relation)
        abjad.timespantools.TimespanTimespanTimeRelation(
            inequality=abjad.timespantools.CompoundInequality(
                [
                    abjad.TimespanInequality('timespan_1.start_offset <= timespan_2.start_offset'),
                    abjad.TimespanInequality('timespan_2.start_offset < timespan_1.stop_offset'),
                    ],
                logical_operator='and',
                ),
            )

    ..  container:: example

        >>> staff_1 = abjad.Staff("c'4 d'4 e'4 f'4 g'2 c''2")
        >>> staff_2 = abjad.Staff("c'2 b'2 a'2 g'2")
        >>> score = abjad.Score([staff_1, staff_2])
        >>> abjad.show(score) # doctest: +SKIP

        >>> start_offsets = [
        ...     abjad.inspect(note).get_timespan().start_offset
        ...     for note in staff_1
        ...     ]
        >>> stop_offsets = [
        ...     abjad.inspect(note).get_timespan().stop_offset
        ...     for note in staff_1
        ...     ]

        >>> timespan_1 = abjad.Timespan((1, 4), (5, 4))
        >>> time_relation = \
        ...     abjad.timespantools.timespan_2_starts_during_timespan_1(
        ...     timespan_1=timespan_1)
        >>> start_index, stop_index = time_relation.get_offset_indices(
        ...     start_offsets, stop_offsets)

        >>> selected_notes = staff_1[start_index:stop_index]
        >>> selected_notes
        Selection([Note("d'4"), Note("e'4"), Note("f'4"), Note("g'2")])

        >>> abjad.label(selected_notes).color_leaves('red')

        >>> abjad.show(score) # doctest: +SKIP

    Returns time relation or boolean.
    '''
    from abjad.tools import timespantools

    inequality = timespantools.CompoundInequality([
        'timespan_1.start_offset <= timespan_2.start_offset',
        'timespan_2.start_offset < timespan_1.stop_offset',
    ])

    time_relation = timespantools.TimespanTimespanTimeRelation(
        inequality,
        timespan_1=timespan_1,
        timespan_2=timespan_2,
    )

    if time_relation.is_fully_loaded and not hold:
        return time_relation()
    else:
        return time_relation