Container

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_abjad.core" { graph [label="abjad.core"]; node [color=1]; "abjad.core.AcciaccaturaContainer.AcciaccaturaContainer" [URL="../api/abjad/core/AcciaccaturaContainer.html#abjad.core.AcciaccaturaContainer.AcciaccaturaContainer", color=1, label="Acciaccatura\nContainer", target=_top]; "abjad.core.AfterGraceContainer.AfterGraceContainer" [URL="../api/abjad/core/AfterGraceContainer.html#abjad.core.AfterGraceContainer.AfterGraceContainer", color=1, label="After\nGrace\nContainer", target=_top]; "abjad.core.AppoggiaturaContainer.AppoggiaturaContainer" [URL="../api/abjad/core/AppoggiaturaContainer.html#abjad.core.AppoggiaturaContainer.AppoggiaturaContainer", color=1, label="Appoggiatura\nContainer", target=_top]; "abjad.core.Cluster.Cluster" [URL="../api/abjad/core/Cluster.html#abjad.core.Cluster.Cluster", color=1, label=Cluster, target=_top]; "abjad.core.Component.Component" [URL="../api/abjad/core/Component.html#abjad.core.Component.Component", color=1, label=Component, shape=oval, style=bold, target=_top]; "abjad.core.Container.Container" [URL="../api/abjad/core/Container.html#abjad.core.Container.Container", color=black, fontcolor=white, label=Container, target=_top]; "abjad.core.Component.Component" -> "abjad.core.Container.Container"; "abjad.core.Container.Container" -> "abjad.core.AfterGraceContainer.AfterGraceContainer" [minlen=1]; "abjad.core.Container.Container" -> "abjad.core.Cluster.Cluster" [minlen=2]; "abjad.core.Context.Context" [URL="../api/abjad/core/Context.html#abjad.core.Context.Context", color=1, label=Context, target=_top]; "abjad.core.Container.Container" -> "abjad.core.Context.Context"; "abjad.core.GraceContainer.GraceContainer" [URL="../api/abjad/core/GraceContainer.html#abjad.core.GraceContainer.GraceContainer", color=1, label="Grace\nContainer", target=_top]; "abjad.core.Container.Container" -> "abjad.core.GraceContainer.GraceContainer"; "abjad.core.Measure.Measure" [URL="../api/abjad/core/Measure.html#abjad.core.Measure.Measure", color=1, label=Measure, target=_top]; "abjad.core.Container.Container" -> "abjad.core.Measure.Measure" [minlen=1]; "abjad.core.Tuplet.Tuplet" [URL="../api/abjad/core/Tuplet.html#abjad.core.Tuplet.Tuplet", color=1, label=Tuplet, target=_top]; "abjad.core.Container.Container" -> "abjad.core.Tuplet.Tuplet" [minlen=2]; "abjad.core.Score.Score" [URL="../api/abjad/core/Score.html#abjad.core.Score.Score", color=1, label=Score, target=_top]; "abjad.core.Context.Context" -> "abjad.core.Score.Score" [minlen=1]; "abjad.core.Staff.Staff" [URL="../api/abjad/core/Staff.html#abjad.core.Staff.Staff", color=1, label=Staff, target=_top]; "abjad.core.Context.Context" -> "abjad.core.Staff.Staff" [minlen=2]; "abjad.core.StaffGroup.StaffGroup" [URL="../api/abjad/core/StaffGroup.html#abjad.core.StaffGroup.StaffGroup", color=1, label="Staff\nGroup", target=_top]; "abjad.core.Context.Context" -> "abjad.core.StaffGroup.StaffGroup" [minlen=1]; "abjad.core.Voice.Voice" [URL="../api/abjad/core/Voice.html#abjad.core.Voice.Voice", color=1, label=Voice, target=_top]; "abjad.core.Context.Context" -> "abjad.core.Voice.Voice" [minlen=2]; "abjad.core.GraceContainer.GraceContainer" -> "abjad.core.AcciaccaturaContainer.AcciaccaturaContainer" [minlen=1]; "abjad.core.GraceContainer.GraceContainer" -> "abjad.core.AppoggiaturaContainer.AppoggiaturaContainer" [minlen=2]; } subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=2]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/core/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", color=2, label="Abjad\nObject", target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", color=3, label=object, target=_top]; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.core.Component.Component" [minlen=1]; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject" [minlen=1]; }

class abjad.core.Container.Container(components=None, identifier=None, is_simultaneous=None, name=None)

Container.

Intializes from string:

>>> container = abjad.Container("c'4 e'4 d'4 e'8 f'8")
>>> abjad.show(container) 

Intializes from components:

>>> notes = [
...     abjad.Note("c'4"),
...     abjad.Note("e'4"),
...     abjad.Note("d'4"),
...     abjad.Note("e'8"),
...     abjad.Note("f'8"),
...     ]
>>> container = abjad.Container(notes)
>>> abjad.show(container) 

Intializes from selections:

>>> notes = [
...     abjad.Note("c'4"),
...     abjad.Note("e'4"),
...     abjad.Note("d'4"),
...     abjad.Note("e'8"),
...     abjad.Note("f'8"),
...     ]
>>> selection = abjad.select(notes)
>>> container = abjad.Container(selection)
>>> abjad.show(container) 

Intializes from mixed components and selections:

>>> items = [
...     abjad.Note("c'4"),
...     abjad.select(abjad.Note("e'4")),
...     abjad.select(abjad.Note("d'4")),
...     abjad.Note("e'8"),
...     abjad.Note("f'8"),
...     ]
>>> container = abjad.Container(items)
>>> abjad.show(container) 

Containers are iterables:

>>> import collections
>>> container = abjad.Container("c'4 e'4 d'4 e'8 f'8")
>>> isinstance(container, collections.Iterable)
True

Containers are not sequences because containers do not implement reverse:

>>> container = abjad.Container("c'4 e'4 d'4 e'8 f'8")
>>> isinstance(container, collections.Sequence)
False

Formatting positions contributions strictly one-per-line:

>>> staff = abjad.Staff("c'4 d' e' f'")
>>> abjad.attach(abjad.Articulation('^'), staff[0])
>>> abjad.attach(abjad.Markup('Allegro', direction=abjad.Up), staff[0])
>>> abjad.attach(abjad.StemTremolo(), staff[0])
>>> abjad.show(staff) 
>>> abjad.f(staff)
\new Staff
{
    c'4
    :16
    -\marcato
    ^ \markup { Allegro }
    d'4
    e'4
    f'4
}

Attributes Summary

__contains__ Is true when argument appears in container.
__delitem__ Deletes components(s) at index i in container.
__getitem__ Gets item or slice identified by argument.
__graph__ Graphviz graph representation of container.
__iter__ Iterates container.
__len__ Gets number of components in container.
__setitem__ Sets container i equal to argument.
append Appends component to container.
components Gets components in container.
extend Extends container with argument.
identifier Gets and sets bracket comment.
index Returns index of component in container.
insert Inserts component at index i in container.
is_simultaneous Is true when container is simultaneous.
name Gets and sets name of container.
pop Pops component from container at index i.
remove Removes component from container.

Special methods

__contains__(argument)

Is true when argument appears in container.

Return type:bool
(Component).__copy__(*arguments)

Shallow copies component.

Copies indicators.

Does not copy spanners.

Does not copy children.

Returns new component.

__delitem__(i)

Deletes components(s) at index i in container.

Deletes first tuplet in voice:

>>> voice = abjad.Voice()
>>> voice.append(abjad.Tuplet((2, 3), "c'4 d'4 e'4"))
>>> voice.append(abjad.Tuplet((2, 3), "e'4 d'4 c'4"))
>>> leaves = abjad.select(voice).leaves()
>>> abjad.attach(abjad.Slur(), leaves)
>>> abjad.show(voice) 
>>> tuplet_1 = voice[0]
>>> del(voice[0])

First tuplet no longer appears in voice:

>>> abjad.show(voice) 
>>> abjad.inspect(voice).is_well_formed()
True

First tuplet is no longer slurred but is still well-formed:

>>> abjad.show(tuplet_1) 
>>> abjad.inspect(tuplet_1).is_well_formed()
True

Withdraws component(s) from crossing spanners.

Preserves spanners that component(s) cover(s).

Returns none.

(Component).__format__(format_specification='')

Formats component.

Returns string.

__getitem__(argument)

Gets item or slice identified by argument.

Traverses top-level items only.

Return type:Union[Component, Selection]
__graph__(spanner=None, **keywords)

Graphviz graph representation of container.

Returns Graphviz graph.

(Component).__illustrate__()

Illustrates component.

Returns LilyPond file.

__iter__()

Iterates container.

Abjad containers are iterables:

>>> import collections
>>> container = abjad.Container()
>>> isinstance(container, collections.Iterable)
True

Abjad containers are not sequences:

>>> import collections
>>> container = abjad.Container()
>>> isinstance(container, collections.Sequence)
False

Yields container elements.

Returns generator.

__len__()

Gets number of components in container.

Return type:int
(Component).__mul__(n)

Copies component n times and detaches spanners.

Returns list of new components.

(Component).__repr__()

Gets interpreter representation of leaf.

Returns string.

(Component).__rmul__(n)

Copies component n times and detach spanners.

Returns list of new components.

__setitem__(i, argument)

Sets container i equal to argument. Finds spanners that dominate self[i] and children of self[i]. Replaces contents at self[i] with ‘argument’. Reattaches spanners to new contents. Always leaves score tree in tact.

Return type:None

Methods

append(component)

Appends component to container.

Appends note to container:

>>> container = abjad.Container("c'4 ( d'4 f'4 )")
>>> abjad.show(container) 
>>> container.append(abjad.Note("e'4"))
>>> abjad.show(container) 
Return type:None
extend(argument)

Extends container with argument.

Extends container with three notes:

>>> container = abjad.Container("c'4 ( d'4 f'4 )")
>>> abjad.show(container) 
>>> notes = [abjad.Note("e'32"), abjad.Note("d'32"), abjad.Note("e'16")]
>>> container.extend(notes)
>>> abjad.show(container) 
Return type:None
index(component)

Returns index of component in container.

Gets index of last element in container:

>>> container = abjad.Container("c'4 d'4 f'4 e'4")
>>> abjad.show(container) 
>>> note = container[-1]
>>> note
Note("e'4")
>>> container.index(note)
3
Return type:int
insert(i, component, fracture_spanners=False)

Inserts component at index i in container.

Inserts note. Does not fracture spanners:

>>> container = abjad.Container([])
>>> container.extend("fs16 cs' e' a'")
>>> container.extend("cs''16 e'' cs'' a'")
>>> container.extend("fs'16 e' cs' fs")
>>> slur = abjad.Slur(direction=abjad.Down)
>>> abjad.attach(slur, container[:])
>>> abjad.show(container) 
>>> container.insert(-4, abjad.Note("e'4"), fracture_spanners=False)
>>> abjad.show(container) 

Inserts note. Fractures spanners:

>>> container = abjad.Container([])
>>> container.extend("fs16 cs' e' a'")
>>> container.extend("cs''16 e'' cs'' a'")
>>> container.extend("fs'16 e' cs' fs")
>>> slur = abjad.Slur(direction=abjad.Down)
>>> abjad.attach(slur, container[:])
>>> abjad.show(container) 
>>> container.insert(-4, abjad.Note("e'4"), fracture_spanners=True)
>>> abjad.show(container) 
Return type:None
pop(i=-1)

Pops component from container at index i.

Pops last element from container:

>>> container = abjad.Container("c'4 ( d'4 f'4 ) e'4")
>>> abjad.show(container) 
>>> container.pop()
Note("e'4")
>>> abjad.show(container) 

Returns component.

remove(component)

Removes component from container.

Removes note from container:

>>> container = abjad.Container("c'4 ( d'4 f'4 ) e'4")
>>> abjad.show(container) 
>>> note = container[2]
>>> note
Note("f'4")
>>> container.remove(note)
>>> abjad.show(container) 
Return type:None

Read/write properties

identifier

Gets and sets bracket comment.

>>> container = abjad.Container(
...     "c'4 d'4 e'4 f'4",
...     identifier='%*% AB',
...     )
>>> abjad.show(container) 
>>> abjad.f(container)
{   %*% AB
    c'4
    d'4
    e'4
    f'4
}   %*% AB
Return type:Optional[str]
is_simultaneous

Is true when container is simultaneous.

Gets simultaneity status of container:

>>> container = abjad.Container()
>>> container.append(abjad.Voice("c'8 d'8 e'8"))
>>> container.append(abjad.Voice('g4.'))
>>> abjad.show(container) 
>>> container.is_simultaneous is None
True

Sets simultaneity status of container:

>>> container = abjad.Container()
>>> container.append(abjad.Voice("c'8 d'8 e'8"))
>>> container.append(abjad.Voice('g4.'))
>>> abjad.show(container) 
>>> container.is_simultaneous = True
>>> abjad.show(container) 
Return type:Optional[bool]
name

Gets and sets name of container.

Gets container name:

>>> container = abjad.Container("c'4 d'4 e'4 f'4")
>>> abjad.show(container) 
>>> container.name is None
True

Sets container name:

>>> container = abjad.Container(
...     "c'4 d'4 e'4 f'4",
...     name='Special',
...     )
>>> abjad.show(container) 
>>> container.name
'Special'

Container name does not appear in LilyPond output:

>>> abjad.f(container)
{
    c'4
    d'4
    e'4
    f'4
}
Return type:Optional[str]

Read-only properties

components

Gets components in container.

Return type:tuple