TimespanCollection

class supriya.tools.timetools.TimespanCollection(timespans=None, accelerated=None)[source]

A mutable always-sorted collection of timespans.

>>> from abjad import timespantools
>>> from supriya import timetools
>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)

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_builtins { graph [label=builtins]; "builtins.object" [color=1, group=0, label=object, shape=box]; } subgraph cluster_systemtools { graph [label=systemtools]; "supriya.tools.systemtools.SupriyaObject.AbstractBase" [color=2, group=1, label=AbstractBase, shape=box]; "supriya.tools.systemtools.SupriyaObject.SupriyaObject" [color=2, group=1, label=SupriyaObject, shape=box]; "supriya.tools.systemtools.SupriyaObject.AbstractBase" -> "supriya.tools.systemtools.SupriyaObject.SupriyaObject"; } subgraph cluster_timetools { graph [label=timetools]; "supriya.tools.timetools.TimespanCollection.TimespanCollection" [color=black, fontcolor=white, group=2, label=<<B>TimespanCollection</B>>, shape=box, style="filled, rounded"]; } "builtins.object" -> "supriya.tools.systemtools.SupriyaObject.AbstractBase"; "supriya.tools.systemtools.SupriyaObject.SupriyaObject" -> "supriya.tools.timetools.TimespanCollection.TimespanCollection"; }

Bases

Attribute summary

all_offsets
all_start_offsets
all_stop_offsets
earliest_start_offset
earliest_stop_offset
find_intersection(timespan_or_offset) Find timespans intersecting a timespan or offset.
find_timespans_starting_at(offset)
find_timespans_stopping_at(offset)
get_simultaneity_at(offset) Gets simultaneity at offset.
get_start_offset_after(offset) Gets start offst in this timespan collection after offset.
get_start_offset_before(offset) Gets start offst in this timespan collection before offset.
index(timespan)
insert(timespans) Inserts timespans into this timespan collection.
iterate_simultaneities([reverse]) Iterates simultaneities in this timespan collection.
iterate_simultaneities_nwise([n, reverse]) Iterates simultaneities in this timespan collection in groups of n.
latest_start_offset
latest_stop_offset
remove(timespans) Removes timespans from this timespan collection.
start_offset
stop_offset
__and__(timespan)
__contains__(timespan) Is true if this timespan collection contains timespan.
__eq__(expr) Is true when ID of expr equals ID of Supriya object.
__format__([format_specification]) Formats Supriya object.
__getitem__(item) Gets timespan at index item.
__hash__() Hashes Supriya object.
__iter__() Iterates timespans in this timespan collection.
__len__() Gets length of this timespan collection.
__repr__() Gets interpreter representation of Supriya object.
__setitem__(i, new) Sets timespans at index i to new.
__sub__(timespan) Delete material that intersects timespan:

Read-only properties

TimespanCollection.all_offsets
TimespanCollection.all_start_offsets
TimespanCollection.all_stop_offsets
TimespanCollection.earliest_start_offset
TimespanCollection.earliest_stop_offset
TimespanCollection.latest_start_offset
TimespanCollection.latest_stop_offset
TimespanCollection.start_offset
TimespanCollection.stop_offset

Methods

TimespanCollection.find_intersection(timespan_or_offset)[source]

Find timespans intersecting a timespan or offset.

Finds timespans overlapping offset.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> for x in timespan_collection.find_intersection(1.5):
...     x
...
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(2, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(3, 1))

Finds timespans overlapping timespan.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan = timespantools.Timespan(2, 4)
>>> for x in timespan_collection.find_intersection(timespan):
...     x
...
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(2, 1), stop_offset=Offset(5, 1))
TimespanCollection.find_timespans_starting_at(offset)[source]
TimespanCollection.find_timespans_stopping_at(offset)[source]
TimespanCollection.get_simultaneity_at(offset)[source]

Gets simultaneity at offset.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan_collection.get_simultaneity_at(1)
<TimespanSimultaneity(1 <<3>>)>
>>> timespan_collection.get_simultaneity_at(6.5)
<TimespanSimultaneity(6.5 <<1>>)>
TimespanCollection.get_start_offset_after(offset)[source]

Gets start offst in this timespan collection after offset.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan_collection.get_start_offset_after(-1)
0.0
>>> timespan_collection.get_start_offset_after(0)
1.0
>>> timespan_collection.get_start_offset_after(1)
2.0
>>> timespan_collection.get_start_offset_after(2)
6.0
>>> timespan_collection.get_start_offset_after(6) is None
True
TimespanCollection.get_start_offset_before(offset)[source]

Gets start offst in this timespan collection before offset.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan_collection.get_start_offset_before(7)
6.0
>>> timespan_collection.get_start_offset_before(6)
2.0
>>> timespan_collection.get_start_offset_before(2)
1.0
>>> timespan_collection.get_start_offset_before(1)
0.0
>>> timespan_collection.get_start_offset_before(0) is None
True
TimespanCollection.index(timespan)[source]
TimespanCollection.insert(timespans)[source]

Inserts timespans into this timespan collection.

>>> timespan_collection = timetools.TimespanCollection()
>>> timespan_collection.insert(timespantools.Timespan(1, 3))
>>> timespan_collection.insert((
...     timespantools.Timespan(0, 4),
...     timespantools.Timespan(2, 6),
...     ))
>>> for x in timespan_collection:
...     x
...
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(4, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(2, 1), stop_offset=Offset(6, 1))

timespans may be a single timespan or an iterable of timespans.

Returns none.

TimespanCollection.iterate_simultaneities(reverse=False)[source]

Iterates simultaneities in this timespan collection.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> for x in timespan_collection.iterate_simultaneities():
...     x
...
<TimespanSimultaneity(0.0 <<1>>)>
<TimespanSimultaneity(1.0 <<3>>)>
<TimespanSimultaneity(2.0 <<3>>)>
<TimespanSimultaneity(6.0 <<1>>)>
>>> for x in timespan_collection.iterate_simultaneities(
...     reverse=True):
...     x
...
<TimespanSimultaneity(6.0 <<1>>)>
<TimespanSimultaneity(2.0 <<3>>)>
<TimespanSimultaneity(1.0 <<3>>)>
<TimespanSimultaneity(0.0 <<1>>)>

Returns generator.

TimespanCollection.iterate_simultaneities_nwise(n=3, reverse=False)[source]

Iterates simultaneities in this timespan collection in groups of n.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> for x in timespan_collection.iterate_simultaneities_nwise(n=2):
...     x
...
[<TimespanSimultaneity(0.0 <<1>>)>, <TimespanSimultaneity(1.0 <<3>>)>]
[<TimespanSimultaneity(1.0 <<3>>)>, <TimespanSimultaneity(2.0 <<3>>)>]
[<TimespanSimultaneity(2.0 <<3>>)>, <TimespanSimultaneity(6.0 <<1>>)>]
>>> for x in timespan_collection.iterate_simultaneities_nwise(
...     n=2, reverse=True):
...     x
...
[<TimespanSimultaneity(2.0 <<3>>)>, <TimespanSimultaneity(6.0 <<1>>)>]
[<TimespanSimultaneity(1.0 <<3>>)>, <TimespanSimultaneity(2.0 <<3>>)>]
[<TimespanSimultaneity(0.0 <<1>>)>, <TimespanSimultaneity(1.0 <<3>>)>]

Returns generator.

TimespanCollection.remove(timespans)[source]

Removes timespans from this timespan collection.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan_collection.remove(timespans[1:-1])
>>> for timespan in timespan_collection:
...     timespan
...
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(6, 1), stop_offset=Offset(9, 1))

Special methods

TimespanCollection.__and__(timespan)[source]
TimespanCollection.__contains__(timespan)[source]

Is true if this timespan collection contains timespan. Otherwise false.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespans[0] in timespan_collection
True
>>> timespantools.Timespan(-1, 100) in timespan_collection
False

Returns boolean.

(SupriyaObject).__eq__(expr)

Is true when ID of expr equals ID of Supriya object. Otherwise false.

Returns boolean.

(SupriyaObject).__format__(format_specification='')

Formats Supriya object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

TimespanCollection.__getitem__(item)[source]

Gets timespan at index item.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan_collection[-1]
Timespan(start_offset=Offset(6, 1), stop_offset=Offset(9, 1))
>>> for timespan in timespan_collection[:3]:
...     timespan
...
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(2, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(3, 1))

Returns timespan or timespans.

(SupriyaObject).__hash__()

Hashes Supriya object.

Required to be explicitely re-defined on Python 3 if __eq__ changes.

Returns integer.

TimespanCollection.__iter__()[source]

Iterates timespans in this timespan collection.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> for timespan in timespan_collection:
...     timespan
...
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(2, 1))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(3, 1))
Timespan(start_offset=Offset(2, 1), stop_offset=Offset(5, 1))
Timespan(start_offset=Offset(6, 1), stop_offset=Offset(9, 1))

Returns generator.

TimespanCollection.__len__()[source]

Gets length of this timespan collection.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> len(timespan_collection)
5

Returns integer.

(SupriyaObject).__repr__()

Gets interpreter representation of Supriya object.

Returns string.

TimespanCollection.__setitem__(i, new)[source]

Sets timespans at index i to new.

>>> timespans = (
...     timespantools.Timespan(0, 3),
...     timespantools.Timespan(1, 3),
...     timespantools.Timespan(1, 2),
...     timespantools.Timespan(2, 5),
...     timespantools.Timespan(6, 9),
...     )
>>> timespan_collection = timetools.TimespanCollection(timespans)
>>> timespan_collection[:3] = [timespantools.Timespan(100, 200)]

Returns none.

TimespanCollection.__sub__(timespan)[source]

Delete material that intersects timespan:

>>> timespan_collection = timetools.TimespanCollection([
...     timespantools.Timespan(0, 16),
...     timespantools.Timespan(5, 12),
...     timespantools.Timespan(-2, 8),
...     ])
>>> timespan = timespantools.Timespan(5, 10)
>>> result = timespan_collection - timespan
>>> print(format(timespan_collection))
supriya.tools.timetools.TimespanCollection(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(5, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(5, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(10, 1),
            stop_offset=durationtools.Offset(12, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(10, 1),
            stop_offset=durationtools.Offset(16, 1),
            ),
        ]
    )

Operates in place and returns timespan collection.