TimespanCollection

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph cluster_builtins { graph [label=builtins]; node [color=1]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_supriya.system" { graph [label="supriya.system"]; node [color=2]; "supriya.system.SupriyaObject.SupriyaObject" [URL="../api/supriya/time/../system/SupriyaObject.html#supriya.system.SupriyaObject.SupriyaObject", label="Supriya\nObject", target=_top]; } subgraph "cluster_supriya.time" { graph [label="supriya.time"]; node [color=3]; "supriya.time.TimespanCollection.TimespanCollection" [URL="../api/supriya/time/TimespanCollection.html#supriya.time.TimespanCollection.TimespanCollection", color=black, fontcolor=white, label="Timespan\nCollection", target=_top]; } "builtins.object" -> "supriya.system.SupriyaObject.SupriyaObject"; "supriya.system.SupriyaObject.SupriyaObject" -> "supriya.time.TimespanCollection.TimespanCollection"; }

class supriya.time.TimespanCollection.TimespanCollection(timespans=None, accelerated=True)[source]

A mutable always-sorted collection of timespans.

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

Attributes Summary

__and__
__contains__ Is true if this timespan collection contains timespan.
__getitem__ Gets timespan at index item.
__iter__ Iterates timespans in this timespan collection.
__len__ Gets length of this timespan collection.
__setitem__ Sets timespans at index i to new.
__sub__ Delete material that intersects timespan:
all_offsets
all_start_offsets
all_stop_offsets
earliest_start_offset
earliest_stop_offset
find_intersection Find timespans intersecting a timespan or offset.
find_timespans_starting_at
find_timespans_stopping_at
get_simultaneity_at Gets simultaneity at offset.
get_start_offset_after Gets start offst in this timespan collection after offset.
get_start_offset_before Gets start offst in this timespan collection before offset.
index
insert Inserts timespans into this timespan collection.
iterate_simultaneities Iterates simultaneities in this timespan collection.
iterate_simultaneities_nwise Iterates simultaneities in this timespan collection in groups of n.
latest_start_offset
latest_stop_offset
remove Removes timespans from this timespan collection.
start_offset
stop_offset

Special methods

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

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

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

Returns boolean.

__getitem__(item)[source]

Gets timespan at index item.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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.

__iter__()[source]

Iterates timespans in this timespan collection.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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.

__len__()[source]

Gets length of this timespan collection.

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

Returns integer.

(SupriyaObject).__repr__()

Return repr(self).

__setitem__(i, new)[source]

Sets timespans at index i to new.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.TimespanCollection(timespans)
>>> timespan_collection[:3] = [abjad.timespans.Timespan(100, 200)]

Returns none.

__sub__(timespan)[source]

Delete material that intersects timespan:

>>> import abjad.timespans
>>> timespan_collection = supriya.time.TimespanCollection([
...     abjad.timespans.Timespan(0, 16),
...     abjad.timespans.Timespan(5, 12),
...     abjad.timespans.Timespan(-2, 8),
...     ])
>>> timespan = abjad.timespans.Timespan(5, 10)
>>> result = timespan_collection - timespan
>>> for timespan in timespan_collection:
...     timespan
...
Timespan(start_offset=Offset(-2, 1), stop_offset=Offset(5, 1))
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(5, 1))
Timespan(start_offset=Offset(10, 1), stop_offset=Offset(12, 1))
Timespan(start_offset=Offset(10, 1), stop_offset=Offset(16, 1))

Operates in place and returns timespan collection.


Methods

find_intersection(timespan_or_offset)[source]

Find timespans intersecting a timespan or offset.

Finds timespans overlapping offset.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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 = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.TimespanCollection(timespans)
>>> timespan = abjad.timespans.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))
find_timespans_starting_at(offset)[source]
find_timespans_stopping_at(offset)[source]
get_simultaneity_at(offset)[source]

Gets simultaneity at offset.

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

Gets start offst in this timespan collection after offset.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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
get_start_offset_before(offset)[source]

Gets start offst in this timespan collection before offset.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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
index(timespan)[source]
insert(timespans)[source]

Inserts timespans into this timespan collection.

>>> import abjad.timespans
>>> timespan_collection = supriya.time.TimespanCollection()
>>> timespan_collection.insert(abjad.timespans.Timespan(1, 3))
>>> timespan_collection.insert((
...     abjad.timespans.Timespan(0, 4),
...     abjad.timespans.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.

iterate_simultaneities(reverse=False)[source]

Iterates simultaneities in this timespan collection.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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.

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

Iterates simultaneities in this timespan collection in groups of n.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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.

remove(timespans)[source]

Removes timespans from this timespan collection.

>>> import abjad.timespans
>>> timespans = (
...     abjad.timespans.Timespan(0, 3),
...     abjad.timespans.Timespan(1, 3),
...     abjad.timespans.Timespan(1, 2),
...     abjad.timespans.Timespan(2, 5),
...     abjad.timespans.Timespan(6, 9),
...     )
>>> timespan_collection = supriya.time.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))

Read-only properties

all_offsets
all_start_offsets
all_stop_offsets
earliest_start_offset
earliest_stop_offset
latest_start_offset
latest_stop_offset
start_offset
stop_offset