TimespanTimespanTimeRelation

class timespantools.TimespanTimespanTimeRelation(inequality=None, timespan_1=None, timespan_2=None)

A timespan vs. timespan time relation.

Score for examples:

>>> staff_1 = Staff(
...     r"\times 2/3 { c'4 d'4 e'4 } \times 2/3 { f'4 g'4 a'4 }")
>>> staff_2 = Staff("c'2. d'4")
>>> score = Score([staff_1, staff_2])
>>> last_tuplet = staff_1[-1]
>>> long_note = staff_2[0]
>>> show(score) 

Example 1:

>>> timespantools.timespan_2_happens_during_timespan_1(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
False

Example 2:

>>> timespantools.timespan_2_intersects_timespan_1(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
True

Example 3:

>>> timespantools.timespan_2_is_congruent_to_timespan_1(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
False

Example 4:

>>> timespantools.timespan_2_overlaps_all_of_timespan_1(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
False

Example 5:

>>> timespantools.timespan_2_overlaps_start_of_timespan_1(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
True

Example 6:

>>> timespantools.timespan_2_overlaps_stop_of_timespan_1(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
False

Example 7:

>>> timespantools.timespan_2_starts_after_timespan_1_starts(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
False

Example 8:

>>> timespantools.timespan_2_starts_after_timespan_1_stops(
...     timespan_1=last_tuplet,
...     timespan_2=long_note,
...     )
False

Timespan / timespan time relations are immutable.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_timespantools { graph [label=timespantools]; "abjad.tools.timespantools.TimeRelation.TimeRelation" [color=3, group=2, label=TimeRelation, shape=oval, style=bold]; "abjad.tools.timespantools.TimespanTimespanTimeRelation.TimespanTimespanTimeRelation" [color=black, fontcolor=white, group=2, label=<<B>TimespanTimespanTimeRelation</B>>, shape=box, style="filled, rounded"]; "abjad.tools.timespantools.TimeRelation.TimeRelation" -> "abjad.tools.timespantools.TimespanTimespanTimeRelation.TimespanTimespanTimeRelation"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.timespantools.TimeRelation.TimeRelation"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

get_counttime_components(counttime_components) Get counttime_components that satisfy time_relation:
get_offset_indices(timespan_2_start_offsets, ...) Get offset indices that satisfy time relation:
inequality Time relation inequality.
is_fully_loaded Is true when timespan_1 and timespan_2 are both not none.
is_fully_unloaded Is true when timespan_1 and timespan_2 are both none.
timespan_1 Time relation timespan 1:
timespan_2 Time relation timespan 2:
__call__([timespan_1, timespan_2]) Evaluate time relation.
__eq__(expr) Is true when expr equals time relation.
__format__([format_specification]) Formats time relation.
__hash__() Hashes time relation.
__ne__(expr) Is true when Abjad object does not equal expr.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

(TimeRelation).inequality

Time relation inequality.

Return ineqality.

TimespanTimespanTimeRelation.is_fully_loaded

Is true when timespan_1 and timespan_2 are both not none. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> time_relation = \
...     timespantools.timespan_2_starts_during_timespan_1(
...     timespan_1=timespan_1,
...     timespan_2=timespan_2,
...     hold=True,
...     )
>>> time_relation.is_fully_loaded
True

Returns true or false.

TimespanTimespanTimeRelation.is_fully_unloaded

Is true when timespan_1 and timespan_2 are both none. Otherwise false.

>>> time_relation.is_fully_unloaded
False

Returns true or false.

TimespanTimespanTimeRelation.timespan_1

Time relation timespan 1:

>>> time_relation.timespan_1
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(10, 1))

Returns timespan.

TimespanTimespanTimeRelation.timespan_2

Time relation timespan 2:

>>> time_relation.timespan_2
Timespan(start_offset=Offset(5, 1), stop_offset=Offset(15, 1))

Returns timespan.

Methods

TimespanTimespanTimeRelation.get_counttime_components(counttime_components)

Get counttime_components that satisfy time_relation:

>>> voice = Voice(
...     [Note(i % 36, Duration(1, 4)) for i in range(200)])
>>> timespan_1 = timespantools.Timespan(20, 22)
>>> time_relation = \
...     timespantools.timespan_2_starts_during_timespan_1(
...     timespan_1=timespan_1)
>>> result = time_relation.get_counttime_components(voice[:])
>>> for counttime_component in result:
...     counttime_component
... 
Note("af'4")
Note("a'4")
Note("bf'4")
Note("b'4")
Note("c''4")
Note("cs''4")
Note("d''4")
Note("ef''4")
>>> result.get_timespan()
Timespan(start_offset=Offset(20, 1), stop_offset=Offset(22, 1))

counttime_components must belong to a single voice.

counttime_components must be time-contiguous.

The call shown here takes 78355 function calls under r9686.

Returns selection.

TimespanTimespanTimeRelation.get_offset_indices(timespan_2_start_offsets, timespan_2_stop_offsets)

Get offset indices that satisfy time relation:

>>> staff = Staff("c'8 d'8 e'8 f'8 g'8 a'8 b'8 c''8")
>>> start_offsets = [inspect_(note).get_timespan().start_offset for note in staff]
>>> stop_offsets = [inspect_(note).get_timespan().stop_offset for note in staff]

Example 1. Notes equal to staff[0:2] start during timespan [0, 3/16):

>>> timespan_1 = timespantools.Timespan(Offset(0), Offset(3, 16))
>>> time_relation = \
...     timespantools.timespan_2_starts_during_timespan_1(
...     timespan_1=timespan_1)
>>> time_relation.get_offset_indices(start_offsets, stop_offsets)
(0, 2)

Example 2. Notes equal to staff[2:8] start after timespan [0, 3/16) stops:

>>> timespan_1 = timespantools.Timespan(Offset(0), Offset(3, 16))
>>> time_relation = \
...     timespantools.timespan_2_starts_after_timespan_1_stops(
...     timespan_1=timespan_1)
>>> time_relation.get_offset_indices(start_offsets, stop_offsets)
(2, 8)

Returns nonnegative integer pair.

Special methods

TimespanTimespanTimeRelation.__call__(timespan_1=None, timespan_2=None)

Evaluate time relation.

Example 1. Evaluate time relation without substitution:

>>> timespan_1 = timespantools.Timespan(5, 15)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> time_relation = timespantools.timespan_2_starts_during_timespan_1(
...     timespan_1=timespan_1,
...     timespan_2=timespan_2,
...     hold=True,
...     )
>>> print(format(time_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'),
            ],
        logical_operator='and',
        ),
    timespan_1=timespantools.Timespan(
        start_offset=durationtools.Offset(5, 1),
        stop_offset=durationtools.Offset(15, 1),
        ),
    timespan_2=timespantools.Timespan(
        start_offset=durationtools.Offset(10, 1),
        stop_offset=durationtools.Offset(20, 1),
        ),
    )
>>> time_relation()
True

Example 2. Substitute timespan_1 during evaluation:

>>> new_timespan_1 = timespantools.Timespan(0, 10)
>>> new_timespan_1
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(10, 1))
>>> time_relation(timespan_1=new_timespan_1)
False

Example 3. Substitute timespan_2 during evaluation:

>>> new_timespan_2 = timespantools.Timespan(2, 12)
>>> new_timespan_2
Timespan(start_offset=Offset(2, 1), stop_offset=Offset(12, 1))
>>> time_relation(timespan_2=new_timespan_2)
False

Example 4. Substitute both timespan_1 and timespan_2 during evaluation:

>>> time_relation(
...     timespan_1=new_timespan_1,
...     timespan_2=new_timespan_2,
...     )
True

Raise value error if either timespan_1 or timespan_2 is none.

Otherwise return boolean.

TimespanTimespanTimeRelation.__eq__(expr)

Is true when expr equals time relation. Otherwise false:

>>> timespan = timespantools.Timespan(0, 10)
>>> time_relation_1 = \
...     timespantools.timespan_2_starts_during_timespan_1()
>>> time_relation_2 = \
...     timespantools.timespan_2_starts_during_timespan_1(
...     timespan_1=timespan)
>>> time_relation_1 == time_relation_1
True
>>> time_relation_1 == time_relation_2
False
>>> time_relation_2 == time_relation_2
True

Returns true or false.

(TimeRelation).__format__(format_specification='')

Formats time relation.

Returns string.

TimespanTimespanTimeRelation.__hash__()

Hashes time relation.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(expr)

Is true when Abjad object does not equal expr. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.