def offset_happens_when_timespan_stops(timespan=None, offset=None, hold=False): r'''Makes time relation indicating that `offset` happens when `timespan` stops. :: >>> relation = timespantools.offset_happens_when_timespan_stops() >>> print(format(relation)) timespantools.OffsetTimespanTimeRelation( inequality=timespantools.CompoundInequality( [ timespantools.SimpleInequality('offset == timespan.stop'), ], logical_operator='and', ), ) Returns time relation or boolean. ''' from abjad.tools import timespantools inequality = timespantools.CompoundInequality([ 'offset == timespan.stop', ]) time_relation = timespantools.OffsetTimespanTimeRelation(inequality, timespan=timespan, offset=offset) if time_relation.is_fully_loaded and not hold: return time_relation() else: return time_relation
def offset_happens_during_timespan(timespan=None, offset=None, hold=False): r'''Makes time relation indicating that `offset` happens during `timespan`. .. container:: example >>> relation = abjad.timespantools.offset_happens_during_timespan() >>> abjad.f(relation) abjad.timespantools.OffsetTimespanTimeRelation( inequality=abjad.timespantools.CompoundInequality( [ abjad.TimespanInequality('timespan.start <= offset'), abjad.TimespanInequality('offset < timespan.stop'), ], logical_operator='and', ), ) Returns time relation or boolean. ''' from abjad.tools import timespantools inequality = timespantools.CompoundInequality([ 'timespan.start <= offset', 'offset < timespan.stop', ]) time_relation = timespantools.OffsetTimespanTimeRelation( inequality, timespan=timespan, offset=offset) if time_relation.is_fully_loaded and not hold: return time_relation() else: return time_relation
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. .. container:: example >>> relation = abjad.timespantools.timespan_2_contains_timespan_1_improperly() >>> abjad.f(relation) abjad.timespantools.TimespanTimespanTimeRelation( inequality=abjad.timespantools.CompoundInequality( [ abjad.TimespanInequality('timespan_2.start_offset <= timespan_1.start_offset'), abjad.TimespanInequality('timespan_1.stop_offset <= timespan_2.stop_offset'), ], logical_operator='and', ), ) .. container:: example >>> staff = abjad.Staff( ... r"c'8. \p \< fs'16 a'4 af'8 \f \> g'8 ~ g'16 f' e' ef' \p", ... ) >>> timespan_1 = abjad.Timespan((1, 4), (3, 8)) >>> abjad.show(staff) # doctest: +SKIP >>> offset_lists = staff[:]._get_offset_lists() >>> time_relation = abjad.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 Selection([Note("a'4")]) >>> abjad.label(selected_notes).color_leaves('red') >>> abjad.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
def __init__(self, inequality=None): from abjad.tools import timespantools default_inequality = timespantools.CompoundInequality([ 'timespan_1.start_offset < timespan_2.start_offset', ]) inequality = inequality or default_inequality assert isinstance( inequality, timespantools.CompoundInequality), repr(inequality) self._inequality = inequality
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
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
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
def offset_happens_before_timespan_starts( timespan=None, offset=None, hold=False, ): r'''Makes time relation indicating that `offset` happens before `timespan` starts. .. container:: example **Example 1.** Makes time relation indicating that `offset` happens before `timespan` starts: :: >>> relation = timespantools.offset_happens_before_timespan_starts() >>> print(format(relation)) timespantools.OffsetTimespanTimeRelation( inequality=timespantools.CompoundInequality( [ timespantools.Inequality('offset < timespan.start'), ], logical_operator='and', ), ) .. container:: example **Example 2.** Makes time relation indicating that offset ``1/2`` happens before `timespan` starts: :: >>> offset = durationtools.Offset(1, 2) :: >>> relation = \ ... timespantools.offset_happens_before_timespan_starts( ... offset=offset) :: >>> print(format(relation)) timespantools.OffsetTimespanTimeRelation( inequality=timespantools.CompoundInequality( [ timespantools.Inequality('offset < timespan.start'), ], logical_operator='and', ), offset=durationtools.Offset(1, 2), ) .. container:: example **Example 3.** Makes time relation indicating that `offset` happens before timespan ``[2, 8)`` starts: :: >>> timespan = timespantools.Timespan(2, 8) :: >>> relation = \ ... timespantools.offset_happens_before_timespan_starts( ... timespan=timespan) :: >>> print(format(relation)) timespantools.OffsetTimespanTimeRelation( inequality=timespantools.CompoundInequality( [ timespantools.Inequality('offset < timespan.start'), ], logical_operator='and', ), timespan=timespantools.Timespan( start_offset=durationtools.Offset(2, 1), stop_offset=durationtools.Offset(8, 1), ), ) .. container:: example **Example 4.** Makes time relation indicating that offset ``1/2`` happens before timespan ``[2, 8)`` starts: :: >>> relation = timespantools.offset_happens_before_timespan_starts( ... timespan=timespan, ... offset=offset, ... hold=True, ... ) :: >>> print(format(relation)) timespantools.OffsetTimespanTimeRelation( inequality=timespantools.CompoundInequality( [ timespantools.Inequality('offset < timespan.start'), ], logical_operator='and', ), timespan=timespantools.Timespan( start_offset=durationtools.Offset(2, 1), stop_offset=durationtools.Offset(8, 1), ), offset=durationtools.Offset(1, 2), ) .. container:: example **Example 5.** Evaluates time relation indicating that offset ``1/2`` happens before timespan ``[2, 8)`` starts: :: >>> timespantools.offset_happens_before_timespan_starts( ... timespan=timespan, ... offset=offset, ... hold=False, ... ) True Returns time relation or boolean. ''' from abjad.tools import timespantools inequality = timespantools.CompoundInequality([ 'offset < timespan.start', ]) time_relation = timespantools.OffsetTimespanTimeRelation(inequality, timespan=timespan, offset=offset) 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`. :: >>> 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