InstrumentList

class instrumenttools.InstrumentList(items=None, item_class=None, keep_sorted=False)

Instrument list.

>>> instruments = instrumenttools.InstrumentList([
...     instrumenttools.Flute(),
...     instrumenttools.Guitar()
...     ])
>>> f(instruments)
instrumenttools.InstrumentList(
    [
        instrumenttools.Flute(
            instrument_name='flute',
            short_instrument_name='fl.',
            instrument_name_markup=markuptools.Markup(
                contents=['Flute'],
                ),
            short_instrument_name_markup=markuptools.Markup(
                contents=['Fl.'],
                ),
            allowable_clefs=instrumenttools.ClefList(
                [
                    indicatortools.Clef(
                        name='treble',
                        ),
                    ]
                ),
            pitch_range=pitchtools.PitchRange(
                range_string='[C4, D7]',
                ),
            sounding_pitch_of_written_middle_c=pitchtools.NamedPitch("c'"),
            ),
        instrumenttools.Guitar(
            instrument_name='guitar',
            short_instrument_name='gt.',
            instrument_name_markup=markuptools.Markup(
                contents=['Guitar'],
                ),
            short_instrument_name_markup=markuptools.Markup(
                contents=['Gt.'],
                ),
            allowable_clefs=instrumenttools.ClefList(
                [
                    indicatortools.Clef(
                        name='treble',
                        ),
                    ]
                ),
            default_tuning=indicatortools.Tuning(
                pitches=pitchtools.PitchSegment(
                    (
                        pitchtools.NamedPitch('e,'),
                        pitchtools.NamedPitch('a,'),
                        pitchtools.NamedPitch('d'),
                        pitchtools.NamedPitch('g'),
                        pitchtools.NamedPitch('b'),
                        pitchtools.NamedPitch("e'"),
                        ),
                    item_class=pitchtools.NamedPitch,
                    ),
                ),
            pitch_range=pitchtools.PitchRange(
                range_string='[E2, E5]',
                ),
            sounding_pitch_of_written_middle_c=pitchtools.NamedPitch('c'),
            ),
        ]
    )

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_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" [color=3, group=2, label=TypedCollection, shape=oval, style=bold]; "abjad.tools.datastructuretools.TypedList.TypedList" [color=3, group=2, label=TypedList, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedList.TypedList"; } subgraph cluster_instrumenttools { graph [label=instrumenttools]; "abjad.tools.instrumenttools.InstrumentList.InstrumentList" [color=black, fontcolor=white, group=3, label=<<B>InstrumentList</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TypedCollection.TypedCollection"; "abjad.tools.datastructuretools.TypedList.TypedList" -> "abjad.tools.instrumenttools.InstrumentList.InstrumentList"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

append(item) Appends item to typed list.
count(item) Gets count of item in typed list.
extend(items) Extends typed list with items.
index(item) Gets index of item in typed list.
insert(i, item) Insert item into typed list.
item_class Gets item class of collection.
items Gets items in collection.
keep_sorted Is true when typed list keeps items sorted.
pop([i]) Pops item i from typed list.
remove(item) Removes item from typed list.
reverse() Reverses items in typed list.
sort([cmp, key, reverse]) Sorts items in typed list.
__contains__(item) Is true when typed collection contains item.
__delitem__(i) Aliases list.__delitem__().
__eq__(argument) Is true when argument is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats instruments.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes typed collection.
__iadd__(argument) Adds argument in place to typed list.
__iter__() Iterates typed collection.
__len__() Gets length of typed collection.
__ne__(argument) Is true when argument is not a typed collection with items equal to this typed collection.
__repr__() Gets interpreter representation of instrument list.
__reversed__() Aliases list.__reversed__().
__setitem__(i, argument) Sets item i equal to argument.

Read-only properties

(TypedCollection).item_class

Gets item class of collection.

Collection coerces items according to item_class.

Returns class.

(TypedCollection).items

Gets items in collection.

Returns list.

Read/write properties

(TypedList).keep_sorted

Is true when typed list keeps items sorted. Otherwise false.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

Methods

(TypedList).append(item)

Appends item to typed list.

>>> integer_list = datastructuretools.TypedList(item_class=int)
>>> integer_list.append('1')
>>> integer_list.append(2)
>>> integer_list.append(3.4)
>>> integer_list[:]
[1, 2, 3]

Returns none.

(TypedList).count(item)

Gets count of item in typed list.

>>> integer_list = datastructuretools.TypedList(item_class=int)
>>> integer_list.extend([0, 0., '0', 99])
>>> integer_list.count(0)
3
>>> integer_list.count(1)
0
>>> integer_list.count(99)
1

Returns nonnegative integer.

(TypedList).extend(items)

Extends typed list with items.

>>> integer_list = datastructuretools.TypedList(item_class=int)
>>> integer_list.extend(['0', 1.0, 2, 3.14159])
>>> integer_list
TypedList([0, 1, 2, 3], item_class=int)

Returns none.

(TypedList).index(item)

Gets index of item in typed list.

>>> pitch_list = datastructuretools.TypedList(
...     item_class=NamedPitch,
...     )
>>> pitch_list.extend(['cqf', "as'", 'b,', 'dss'])
>>> pitch_list.index(NamedPitch('cqf'))
0
>>> pitch_list.index(NamedPitch("as'"))
1
>>> pitch_list.index('b,')
2
>>> pitch_list.index('dss')
3

Returns nonnegative integer.

(TypedList).insert(i, item)

Insert item into typed list.

Inserts into typed list.

>>> integer_list = datastructuretools.TypedList(item_class=int)
>>> integer_list.extend(['1', 2, 4.3])
>>> integer_list
TypedList([1, 2, 4], item_class=int)
>>> integer_list.insert(0, '0')
>>> integer_list
TypedList([0, 1, 2, 4], item_class=int)
>>> integer_list.insert(1, '9')
>>> integer_list
TypedList([0, 9, 1, 2, 4], item_class=int)

Returns none.

(TypedList).pop(i=-1)

Pops item i from typed list.

Returns item.

(TypedList).remove(item)

Removes item from typed list.

>>> integer_list = datastructuretools.TypedList(item_class=int)
>>> integer_list.extend(('0', 1.0, 2, 3.14159))
>>> integer_list[:]
[0, 1, 2, 3]
>>> integer_list.remove('1')
>>> integer_list[:]
[0, 2, 3]

Returns none.

(TypedList).reverse()

Reverses items in typed list.

(TypedList).sort(cmp=None, key=None, reverse=False)

Sorts items in typed list.

Special methods

(TypedCollection).__contains__(item)

Is true when typed collection contains item. Otherwise false.

Returns true or false.

(TypedList).__delitem__(i)

Aliases list.__delitem__().

Returns none.

(TypedCollection).__eq__(argument)

Is true when argument is a typed collection with items that compare equal to those of this typed collection. Otherwise false.

Returns true or false.

InstrumentList.__format__(format_specification='')

Formats instruments.

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

Returns string.

(TypedList).__getitem__(argument)

Gets item or slice identified by argument.

Returns item or slice.

(TypedCollection).__hash__()

Hashes typed collection.

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

Returns integer.

(TypedList).__iadd__(argument)

Adds argument in place to typed list.

>>> dynamic_list = datastructuretools.TypedList(item_class=Dynamic)
>>> dynamic_list.append('ppp')
>>> dynamic_list += ['p', 'mp', 'mf', 'fff']
>>> f(dynamic_list)
datastructuretools.TypedList(
    [
        indicatortools.Dynamic(
            name='ppp',
            ),
        indicatortools.Dynamic(
            name='p',
            ),
        indicatortools.Dynamic(
            name='mp',
            ),
        indicatortools.Dynamic(
            name='mf',
            ),
        indicatortools.Dynamic(
            name='fff',
            ),
        ],
    item_class=indicatortools.Dynamic,
    )

Returns typed list.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(TypedCollection).__ne__(argument)

Is true when argument is not a typed collection with items equal to this typed collection. Otherwise false.

Returns true or false.

InstrumentList.__repr__()

Gets interpreter representation of instrument list.

>>> instruments
InstrumentList([Flute(), Guitar()])

Returns string.

(TypedList).__reversed__()

Aliases list.__reversed__().

Returns generator.

(TypedList).__setitem__(i, argument)

Sets item i equal to argument.

Sets item:

>>> pitch_list = datastructuretools.TypedList(
...     item_class=NamedPitch,
...     )
>>> pitch_list.append(0)
>>> pitch_list.append("d'")
>>> pitch_list.append(('e', 4))
>>> pitch_list.append(NamedPitch("f'"))
>>> pitch_list[-1] = 'gqs,'
>>> f(pitch_list)
datastructuretools.TypedList(
    [
        pitchtools.NamedPitch("c'"),
        pitchtools.NamedPitch("d'"),
        pitchtools.NamedPitch("e'"),
        pitchtools.NamedPitch('gqs,'),
        ],
    item_class=pitchtools.NamedPitch,
    )

Sets slice:

>>> pitch_list[-1:] = ["f'", "g'", "a'", "b'", "c''"]
>>> f(pitch_list)
datastructuretools.TypedList(
    [
        pitchtools.NamedPitch("c'"),
        pitchtools.NamedPitch("d'"),
        pitchtools.NamedPitch("e'"),
        pitchtools.NamedPitch("f'"),
        pitchtools.NamedPitch("g'"),
        pitchtools.NamedPitch("a'"),
        pitchtools.NamedPitch("b'"),
        pitchtools.NamedPitch("c''"),
        ],
    item_class=pitchtools.NamedPitch,
    )

Returns none.