Measure

class scoretools.Measure(time_signature=None, music=None, implicit_scaling=False)

A measure.

>>> measure = Measure((4, 8), "c'8 d'8 e'8 f'8")
>>> show(measure) 

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_scoretools { graph [label=scoretools]; "abjad.tools.scoretools.Component.Component" [color=3, group=2, label=Component, shape=oval, style=bold]; "abjad.tools.scoretools.Container.Container" [color=3, group=2, label=Container, shape=box]; "abjad.tools.scoretools.FixedDurationContainer.FixedDurationContainer" [color=3, group=2, label=FixedDurationContainer, shape=box]; "abjad.tools.scoretools.Measure.Measure" [color=black, fontcolor=white, group=2, label=<<B>Measure</B>>, shape=box, style="filled, rounded"]; "abjad.tools.scoretools.Component.Component" -> "abjad.tools.scoretools.Container.Container"; "abjad.tools.scoretools.Container.Container" -> "abjad.tools.scoretools.FixedDurationContainer.FixedDurationContainer"; "abjad.tools.scoretools.FixedDurationContainer.FixedDurationContainer" -> "abjad.tools.scoretools.Measure.Measure"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.scoretools.Component.Component"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

always_format_time_signature Gets and sets flag to indicate whether time signature should appear in LilyPond format even when not expected.
append(component) Appends component to container.
automatically_adjust_time_signature Gets and sets flag to indicate whether time signature should update automatically following mutation.
extend(expr) Extends container with expr.
from_selections(class_, selections[, ...]) Makes a selection of measures from selections.
has_non_power_of_two_denominator Is true when measure time signature denominator is not an integer power of 2.
has_power_of_two_denominator Is true when measure time signature denominator is an integer power of 2.
implicit_scaling Is true when measure should scale contents.
implied_prolation Implied prolation of measure.
index(component) Returns index of component in container.
insert(i, component[, fracture_spanners]) Inserts component at index i in container.
is_full Is true when measure duration equals time signature duration.
is_misfilled Is true when measure is either underfull or overfull.
is_overfull Is true when measure duration is greater than time signature duration.
is_simultaneous Is true when container is simultaneous.
is_underfull Is true when measure duration is less than time signature duration.
measure_number Gets 1-indexed measure number.
name Gets and sets name of container.
pop([i]) Pops component from container at index i.
remove(component) Removes component from container.
reverse() Reverses contents of container.
scale_and_adjust_time_signature([multiplier]) Scales measure by multiplier and adjusts time signature.
target_duration Gets target duration of measure.
time_signature Gets effective time signature of measure.
__contains__(expr) Is true when expr appears in container.
__copy__(\*args) Copies component with indicators but without children of component or spanners attached to component.
__delitem__(i) Deletes measure item i.
__eq__(expr) Is true when ID of expr equals ID of Abjad object.
__format__([format_specification]) Formats component.
__getitem__(i) Gets container i.
__graph__([spanner]) Graphviz graph representation of container.
__hash__() Hashes Abjad object.
__illustrate__() Illustrates component.
__iter__() Iterates container.
__len__() Gets number of items in container.
__mul__(n) Copies component n times and detaches spanners.
__ne__(expr) Is true when Abjad object does not equal expr.
__repr__() Gets interpreter representation of measure.
__rmul__(n) Copies component n times and detach spanners.
__setitem__(i, expr) Sets measure item i to expr.

Read-only properties

Measure.has_non_power_of_two_denominator

Is true when measure time signature denominator is not an integer power of 2.

>>> measure = Measure((5, 9), "c'8 d' e' f' g'")
>>> measure.implicit_scaling = True
>>> show(measure) 
>>> measure.has_non_power_of_two_denominator
True

Otherwise false:

>>> measure = Measure((5, 8), "c'8 d' e' f' g'")
>>> show(measure) 
>>> measure.has_non_power_of_two_denominator
False

Returns true or false.

Measure.has_power_of_two_denominator

Is true when measure time signature denominator is an integer power of 2.

>>> measure = Measure((5, 8), "c'8 d' e' f' g'")
>>> show(measure) 
>>> measure.has_power_of_two_denominator
True

Otherwise false:

>>> measure = Measure((5, 9), "c'8 d' e' f' g'")
>>> measure.implicit_scaling = True
>>> show(measure) 
>>> measure.has_power_of_two_denominator
False

Returns true or false.

Measure.implied_prolation

Implied prolation of measure.

Measures with implicit scaling scale the duration of their contents:

>>> measure = Measure((5, 12), "c'8 d'8 e'8 f'8 g'8")
>>> measure.implicit_scaling = True
>>> show(measure) 
>>> measure.implied_prolation
Multiplier(2, 3)
>>> for note in measure:
...     note, inspect_(note).get_duration()
... 
(Note("c'8"), Duration(1, 12))
(Note("d'8"), Duration(1, 12))
(Note("e'8"), Duration(1, 12))
(Note("f'8"), Duration(1, 12))
(Note("g'8"), Duration(1, 12))

Measures without implicit scaling turned on do not scale the duration of their contents:

>>> measure = Measure((5, 12), [])
>>> measure.implicit_scaling = False
>>> measure.implied_prolation
Multiplier(1, 1)

Returns positive multiplier.

Measure.is_full

Is true when measure duration equals time signature duration.

>>> measure = Measure((4, 8), "c'8 d'8 e'8 f'8")
>>> show(measure) 
>>> measure.is_full
True

Otherwise false.

Returns true or false.

Measure.is_misfilled

Is true when measure is either underfull or overfull.

>>> measure = Measure((3, 4), "c'4 d'4 e'4 f'4")
>>> measure.is_misfilled
True

Otherwise false:

>>> measure = Measure((3, 4), "c' d' e'")
>>> show(measure) 
>>> measure.is_misfilled
False

Returns true or false.

Measure.is_overfull

Is true when measure duration is greater than time signature duration.

>>> measure = Measure((3, 4), "c'4 d' e' f'")
>>> measure.is_overfull
True

Otherwise false.

Returns true or false.

Measure.is_underfull

Is true when measure duration is less than time signature duration.

>>> measure = Measure((3, 4), "c'4 d'")
>>> measure.is_underfull
True

Otherwise false.

Returns true or false.

Measure.measure_number

Gets 1-indexed measure number.

>>> staff = Staff()
>>> staff.append(Measure((3, 4), "c' d' e'"))
>>> staff.append(Measure((2, 4), "f' g'"))
>>> show(staff) 
>>> staff[0].measure_number
1
>>> staff[1].measure_number
2

Returns positive integer.

Measure.target_duration

Gets target duration of measure.

Target duration of measure is always equal to duration of effective time signature.

>>> measure = Measure((3, 4), "c'4 d'4 e'4")
>>> measure.target_duration
Duration(3, 4)

Returns duration.

Measure.time_signature

Gets effective time signature of measure.

>>> measure.time_signature
TimeSignature((3, 4))

Returns time signature or none.

Read/write properties

Measure.always_format_time_signature

Gets and sets flag to indicate whether time signature should appear in LilyPond format even when not expected.

>>> measure.always_format_time_signature
False

Set to true when necessary to print the same signature repeatedly.

Defaults to false.

Returns true or false.

Measure.automatically_adjust_time_signature

Gets and sets flag to indicate whether time signature should update automatically following mutation.

>>> measure = Measure((3, 4), "c' d' e'")
>>> show(measure) 
>>> measure.automatically_adjust_time_signature = True
>>> measure.append('r')
>>> show(measure) 

Defaults to false.

Returns true or false.

Measure.implicit_scaling

Is true when measure should scale contents. Otherwise false.

Returns true or false.

(Container).is_simultaneous

Is true when container is simultaneous. Otherwise false.

Example 1. Gets simultaneity status of container:

>>> container = Container()
>>> container.append(Voice("c'8 d'8 e'8"))
>>> container.append(Voice('g4.'))
>>> show(container) 
>>> container.is_simultaneous
False

Example 2. Sets simultaneity status of container:

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

Defaults to false.

Set to true or false.

Returns true or false.

(Container).name

Gets and sets name of container.

Example 1. Gets container name:

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

Example 2. Sets container name:

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

Container name does not appear in LilyPond output:

>>> f(container)
{
    c'4
    d'4
    e'4
    f'4
}

Defaults to none.

Set to string or none.

Returns string or none.

Methods

(Container).append(component)

Appends component to container.

Example 1. Appends note to container:

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

Returns none.

(Container).extend(expr)

Extends container with expr.

Example 1. Extends container with three notes:

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

Returns none.

(Container).index(component)

Returns index of component in container.

Example 1. Gets index of last element in container:

>>> container = Container("c'4 d'4 f'4 e'4")
>>> show(container) 
>>> note = container[-1]
>>> note
Note("e'4")
>>> container.index(note)
3

Returns nonnegative integer.

(Container).insert(i, component, fracture_spanners=False)

Inserts component at index i in container.

Example 1. Inserts note. Does not fracture spanners:

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

Example 2. Inserts note. Fractures spanners:

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

Returns none.

(Container).pop(i=-1)

Pops component from container at index i.

Example 1. Pops last element from container:

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

Returns component.

(Container).remove(component)

Removes component from container.

Example 1. Removes note from container:

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

Returns none.

(Container).reverse()

Reverses contents of container.

Example 1. Reverses staff:

>>> staff = Staff("c'8 [ d'8 ] e'8 ( f'8 )")
>>> show(staff) 
>>> staff.reverse()
>>> show(staff) 

Returns none.

Measure.scale_and_adjust_time_signature(multiplier=None)

Scales measure by multiplier and adjusts time signature.

Scales measure by non-power-of-two multiplier:

>>> measure = Measure((3, 8), "c'8 d'8 e'8")
>>> measure.implicit_scaling = True
>>> show(measure) 
>>> measure.scale_and_adjust_time_signature(Multiplier(2, 3))
>>> show(measure) 

Returns none.

Class & static methods

classmethod Measure.from_selections(class_, selections, time_signatures=None)

Makes a selection of measures from selections.

Returns selections.

Special methods

(Container).__contains__(expr)

Is true when expr appears in container. Otherwise false.

Returns true or false.

(Component).__copy__(*args)

Copies component with indicators but without children of component or spanners attached to component.

Returns new component.

Measure.__delitem__(i)

Deletes measure item i.

>>> measure = Measure((4, 8), "c'8 d'8 e'8 f'8")
>>> measure.automatically_adjust_time_signature = True
>>> show(measure) 
>>> del(measure[1])
>>> show(measure) 

Returns none.

(AbjadObject).__eq__(expr)

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

Returns true or false.

(Component).__format__(format_specification='')

Formats component.

Set format_specification to ‘’, ‘lilypond’ or ‘storage’.

Returns string.

(Container).__getitem__(i)

Gets container i.

Traverses top-level items only.

Returns component.

(Container).__graph__(spanner=None, **kwargs)

Graphviz graph representation of container.

Returns Graphviz graph.

(AbjadObject).__hash__()

Hashes Abjad object.

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

Returns integer.

(Component).__illustrate__()

Illustrates component.

Returns LilyPond file.

(Container).__iter__()

Iterates container.

Example 1. Abjad containers are iterables:

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

Example 2. Abjad containers are not sequences:

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

Yields container elements.

Returns generator.

(Container).__len__()

Gets number of items in container.

Returns nonnegative integer.

(Component).__mul__(n)

Copies component n times and detaches spanners.

Returns list of new components.

(AbjadObject).__ne__(expr)

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

Returns true or false.

Measure.__repr__()

Gets interpreter representation of measure.

>>> measure = Measure((3, 8), "c'8 d'8 e'8")
>>> show(measure) 
>>> measure
Measure((3, 8), "c'8 d'8 e'8")

Returns string.

(Component).__rmul__(n)

Copies component n times and detach spanners.

Returns list of new components.

Measure.__setitem__(i, expr)

Sets measure item i to expr.

>>> measure = Measure((4, 8), "c'8 d'8 e'8 f'8")
>>> measure.automatically_adjust_time_signature = True
>>> show(measure) 
>>> measure[1] = Note("ds'8.")
>>> show(measure) 

Returns none.