Tempo

class indicatortools.Tempo(reference_duration=None, units_per_minute=None, textual_indication=None, custom_markup=None)

Tempo.

Example 1. Integer-valued tempo:

>>> score = Score([])
>>> staff = Staff("c'8 d'8 e'8 f'8")
>>> score.append(staff)
>>> tempo = Tempo(Duration(1, 4), 90)
>>> attach(tempo, staff[0])
>>> show(score) 

Example 2. Float-valued tempo:

>>> score = Score([])
>>> staff = Staff("c'8 d'8 e'8 f'8")
>>> score.append(staff)
>>> tempo = Tempo(Duration(1, 4), 90.1)
>>> attach(tempo, staff[0])
>>> show(score) 

Example 3. Rational-valued tempo:

>>> score = Score([])
>>> staff = Staff("c'8 d'8 e'8 f'8")
>>> score.append(staff)
>>> tempo = Tempo(Duration(1, 4), Fraction(181, 2))
>>> attach(tempo, staff[0])
>>> show(score) 

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.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_indicatortools { graph [label=indicatortools]; "abjad.tools.indicatortools.Tempo.Tempo" [color=black, fontcolor=white, group=2, label=<<B>Tempo</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.AbjadValueObject.AbjadValueObject" -> "abjad.tools.indicatortools.Tempo.Tempo"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

custom_markup Gets custom markup of tempo.
default_scope Gets default scope of tempo.
duration_to_milliseconds(duration) Gets millisecond value of duration under a given tempo.
is_imprecise Is true if tempo is entirely textual or if tempo’s units_per_minute is a range.
list_related_tempos([maximum_numerator, ...]) Lists related tempos.
make_tempo_equation_markup(...) Makes tempo equation markup.
quarters_per_minute Gets quarters per minute of tempo.
reference_duration Gets reference duration of tempo.
rewrite_duration(duration, new_tempo) Rewrites duration under new_tempo.
textual_indication Gets optional textual indication of tempo.
units_per_minute Gets units per minute of tempo.
__add__(argument) Adds tempo to argument.
__copy__(*arguments) Copies Abjad value object.
__div__(argument) Divides tempo by argument.
__eq__(argument) Is true when all initialization values of Abjad value object equal the initialization values of argument.
__format__([format_specification]) Formats tempo.
__ge__(other[, NotImplemented]) Return a >= b.
__gt__(other[, NotImplemented]) Return a > b.
__hash__() Hashes Abjad value object.
__le__(other[, NotImplemented]) Return a <= b.
__lt__(argument) Is true when argument is a tempo with quarters per minute greater than that of this tempo.
__mul__(multiplier) Multiplies tempo by multiplier.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.
__rmul__(multiplier) Multiplies multiplier by tempo.
__str__() Gets string representation of tempo.
__sub__(argument) Subtracts argument from tempo.
__truediv__(argument) Divides tempo by argument.

Read-only properties

Tempo.custom_markup

Gets custom markup of tempo.

Example 1. With custom markup:

>>> markup = Tempo.make_tempo_equation_markup(
...     Duration(1, 4),
...     67.5,
...     )
>>> markup = markup.with_color('red')
>>> tempo = Tempo(
...     reference_duration=Duration(1, 4),
...     units_per_minute=67.5,
...     custom_markup=markup,
...     )
>>> staff = Staff("c'4 d'4 e'4 f'4")
>>> score = Score([staff])
>>> attach(tempo, staff)
>>> show(score) 

Set to markup or none.

Defaults to none.

Returns markup or none.

Tempo.default_scope

Gets default scope of tempo.

Example 1. Fifty-two eighth notes per minute:

>>> tempo = Tempo(Duration(1, 8), 52)
>>> tempo.default_scope
<class 'abjad.tools.scoretools.Score.Score'>

Example 2. Ninety quarter notes per minute:

>>> tempo = Tempo(Duration(1, 4), 90)
>>> tempo.default_scope
<class 'abjad.tools.scoretools.Score.Score'>

Returns score.

Tempo.is_imprecise

Is true if tempo is entirely textual or if tempo’s units_per_minute is a range. Otherwise false.

Example 1. Imprecise tempos:

>>> Tempo(Duration(1, 4), 60).is_imprecise
False
>>> Tempo(4, 60, 'Langsam').is_imprecise
False
>>> Tempo(textual_indication='Langsam').is_imprecise
True
>>> Tempo(4, (35, 50), 'Langsam').is_imprecise
True
>>> Tempo(Duration(1, 4), (35, 50)).is_imprecise
True

Example 2. Precise tempo:

>>> Tempo(Duration(1, 4), 60).is_imprecise
False

Returns true or false.

Tempo.quarters_per_minute

Gets quarters per minute of tempo.

Example 1. Fifty-two eighth notes per minute:

>>> tempo = Tempo(Duration(1, 8), 52)
>>> tempo.quarters_per_minute
Fraction(104, 1)

Example 2. Ninety quarter notes per minute:

>>> tempo = Tempo(Duration(1, 4), 90)
>>> tempo.quarters_per_minute
Fraction(90, 1)

Returns tuple when tempo units_per_minute is a range.

Returns none when tempo is imprecise.

Returns fraction otherwise.

Tempo.reference_duration

Gets reference duration of tempo.

Example 1. Fifty-two eighth notes per minute:

>>> tempo = Tempo(Duration(1, 8), 52)
>>> tempo.reference_duration
Duration(1, 8)

Example 2. Ninety quarter notes per minute:

>>> tempo = Tempo(Duration(1, 4), 90)
>>> tempo.reference_duration
Duration(1, 4)

Returns duration.

Tempo.textual_indication

Gets optional textual indication of tempo.

Example 1. Fifty-two eighth notes per minute:

>>> tempo = Tempo(Duration(1, 8), 52)
>>> tempo.textual_indication is None
True

Example 2. Ninety quarter notes per minute:

>>> tempo = Tempo(Duration(1, 4), 90)
>>> tempo.textual_indication is None
True

Returns string or none.

Tempo.units_per_minute

Gets units per minute of tempo.

Example 1. Integer-valued tempo:

>>> tempo = Tempo(Duration(1, 4), 90)
>>> tempo.units_per_minute
90

Example 2. Float-valued tempo:

>>> tempo = Tempo(Duration(1, 4), 90.1)
>>> tempo.units_per_minute
90.1

Example 3. Rational-valued tempo:

>>> tempo = Tempo(Duration(1, 4), Fraction(181, 2))
>>> tempo.units_per_minute
Fraction(181, 2)

Set to number or none.

Defaults to none

Returns number or none.

Methods

Tempo.duration_to_milliseconds(duration)

Gets millisecond value of duration under a given tempo.

Example 1. One quarter lasts 1000 msec at quarter equals 60:

>>> tempo = Tempo((1, 4), 60)
>>> tempo.duration_to_milliseconds(Duration(1, 4))
Duration(1000, 1)

Example 1. Dotted sixteenth lasts 1500 msec at quarter equals 60:

>>> tempo = Tempo((1, 4), 60)
>>> tempo.duration_to_milliseconds(Duration(3, 8))
Duration(1500, 1)

Returns duration.

Lists related tempos.

Example 1. Rewrites tempo 4=58 by ratios n:d such that 1 <= n <= 8 and 1 <= d <= 8.

>>> tempo = Tempo(Duration(1, 4), 58)
>>> pairs = tempo.list_related_tempos(
...     maximum_numerator=8,
...     maximum_denominator=8,
...     )
>>> for tempo, ratio in pairs:
...     string = '{!s}\t{!s}'.format(tempo, ratio)
...     print(string)
... 
4=29	1:2
4=33+1/7	4:7
4=34+4/5	3:5
4=36+1/4	5:8
4=38+2/3	2:3
4=41+3/7	5:7
4=43+1/2	3:4
4=46+2/5	4:5
4=48+1/3	5:6
4=49+5/7	6:7
4=50+3/4	7:8
4=58	1:1
4=66+2/7	8:7
4=67+2/3	7:6
4=69+3/5	6:5
4=72+1/2	5:4
4=77+1/3	4:3
4=81+1/5	7:5
4=87	3:2
4=92+4/5	8:5
4=96+2/3	5:3
4=101+1/2	7:4
4=116	2:1

Example 2. Integer-valued tempos only:

>>> tempo = Tempo(Duration(1, 4), 58)
>>> pairs = tempo.list_related_tempos(
...     maximum_numerator=16,
...     maximum_denominator=16,
...     integer_tempos_only=True,
...     )
>>> for tempo, ratio in pairs:
...     string = '{!s}\t{!s}'.format(tempo, ratio)
...     print(string)
... 
4=29	1:2
4=58	1:1
4=87	3:2
4=116	2:1

Constrains ratios such that 1:2 <= n:d <= 2:1.

Returns list of tempo / ratio pairs.

Tempo.rewrite_duration(duration, new_tempo)

Rewrites duration under new_tempo.

Example 1. Consider the two tempo indicators below.

>>> tempo = Tempo(Duration(1, 4), 60)
>>> new_tempo = Tempo(Duration(1, 4), 90)

tempo specifies quarter equal to 60.

new_tempo indication specifies quarter equal to 90.

new_tempo is 3/2 times as fast as tempo:

>>> new_tempo / tempo
Multiplier(3, 2)

Note that a triplet eighth note under tempo equals a regular eighth note under new_tempo:

>>> tempo.rewrite_duration(Duration(1, 12), new_tempo)
Duration(1, 8)

And note that a regular eighth note under tempo equals a dotted sixteenth under new_tempo:

>>> tempo.rewrite_duration(Duration(1, 8), new_tempo)
Duration(3, 16)

Given duration governed by this tempo returns new duration governed by new_tempo.

Ensures that duration and new duration consume the same amount of time in seconds.

Returns duration.

Class & static methods

static Tempo.make_tempo_equation_markup(reference_duration, units_per_minute)

Makes tempo equation markup.

Example 1. Integer-valued tempo:

>>> markup = Tempo.make_tempo_equation_markup(Duration(1, 4), 90)
>>> show(markup) 

Example 2. Float-valued tempo:

>>> markup = Tempo.make_tempo_equation_markup(Duration(1, 4), 90.1)
>>> show(markup) 

Example 3. Rational-valued tempo:

>>> markup = Tempo.make_tempo_equation_markup(
...     Duration(1, 4),
...     Fraction(181, 2),
...     )
>>> show(markup) 

Example 4. Reference duration expressed with ties:

>>> markup = Tempo.make_tempo_equation_markup(Duration(5, 16), 90)
>>> show(markup) 

Example 5. Reference duration expressed as a tuplet:

>>> markup = Tempo.make_tempo_equation_markup(Duration(1, 6), 90)
>>> show(markup) 

Example 6. Reference duration passed in as explicit rhythm:

>>> durations = [Duration(1, 16), Duration(3, 16), Duration(1, 16)]
>>> selection = scoretools.make_notes([0], durations)
>>> attach(Tie(), selection)
>>> attach(Beam(), selection)
>>> markup = Tempo.make_tempo_equation_markup(selection, 90)
>>> show(markup) 

Pass rhythms like this as Abjad selections.

Returns markup.

Special methods

Tempo.__add__(argument)

Adds tempo to argument.

Example 1. Adds one tempo to another:

>>> Tempo(Duration(1, 4), 60) + Tempo(Duration(1, 4), 90)
Tempo(reference_duration=Duration(1, 4), units_per_minute=150)

Example 2. Returns none when argument is not a tempo:

>>> Tempo(Duration(1, 4), 60) + 90 is None
True

Returns new tempo or none.

(AbjadValueObject).__copy__(*arguments)

Copies Abjad value object.

Returns new Abjad value object.

Tempo.__div__(argument)

Divides tempo by argument.

Example 1. Divides tempo by number:

>>> Tempo(Duration(1, 4), 60) / 2
Tempo(reference_duration=Duration(1, 4), units_per_minute=30)

Example 2. Divides tempo by other tempo:

>>> Tempo(Duration(1, 4), 60) / Tempo(Duration(1, 4), 40)
Multiplier(3, 2)

Returns new tempo or multiplier.

(AbjadValueObject).__eq__(argument)

Is true when all initialization values of Abjad value object equal the initialization values of argument.

Returns true or false.

Tempo.__format__(format_specification='')

Formats tempo.

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

Example 1. Without custom markup:

>>> tempo = Tempo((1, 4), 84, 'Allegro')
>>> print(format(tempo))
indicatortools.Tempo(
    reference_duration=durationtools.Duration(1, 4),
    units_per_minute=84,
    textual_indication='Allegro',
    )

Example 2. With custom markup:

>>> markup = Markup(r'\italic { Allegro }')
>>> tempo = Tempo((1, 4), 84, custom_markup=markup)
>>> print(format(tempo))
indicatortools.Tempo(
    reference_duration=durationtools.Duration(1, 4),
    units_per_minute=84,
    custom_markup=markuptools.Markup(
        contents=[
            markuptools.MarkupCommand(
                'italic',
                ['Allegro']
                ),
            ],
        ),
    )

Returns string.

Tempo.__ge__(other, NotImplemented=NotImplemented)

Return a >= b. Computed by @total_ordering from (not a < b).

Tempo.__gt__(other, NotImplemented=NotImplemented)

Return a > b. Computed by @total_ordering from (not a < b) and (a != b).

(AbjadValueObject).__hash__()

Hashes Abjad value object.

Returns integer.

Tempo.__le__(other, NotImplemented=NotImplemented)

Return a <= b. Computed by @total_ordering from (a < b) or (a == b).

Tempo.__lt__(argument)

Is true when argument is a tempo with quarters per minute greater than that of this tempo. Otherwise false.

Returns true or false.

Tempo.__mul__(multiplier)

Multiplies tempo by multiplier.

Example 1. Doubles tempo:

>>> tempo = Tempo(Duration(1, 4), 84)
>>> 2 * tempo
Tempo(reference_duration=Duration(1, 4), units_per_minute=168)

Example 2. Triples tempo:

>>> tempo = Tempo(Duration(1, 4), 84)
>>> 3 * tempo
Tempo(reference_duration=Duration(1, 4), units_per_minute=252)

Returns new tempo.

(AbjadObject).__ne__(argument)

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

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

Tempo.__rmul__(multiplier)

Multiplies multiplier by tempo.

Returns new tempo.

Tempo.__str__()

Gets string representation of tempo.

Example 1. Integer-valued tempo:

>>> tempo = Tempo(Duration(1, 4), 90)
>>> str(tempo)
'4=90'

Example 2. Float-valued tempo:

>>> tempo = Tempo(Duration(1, 4), 90.1)
>>> str(tempo)
'4=90.1'

Example 3. Rational-valued tempo:

>>> tempo = Tempo(Duration(1, 4), Fraction(181, 2))
>>> str(tempo)
'4=90+1/2'

Example 4. Ranged tempo:

>>> tempo = Tempo(Duration(1, 4), (90, 96))
>>> str(tempo)
'4=90-96'

Returns string.

Tempo.__sub__(argument)

Subtracts argument from tempo.

Example 1. Same reference reference durations:

>>> tempo_1 = Tempo(Duration(1, 4), 90)
>>> tempo_2 = Tempo(Duration(1, 4), 60)
>>> tempo_1 - tempo_2
Tempo(reference_duration=Duration(1, 4), units_per_minute=30)

Example 2. Different reference durations:

>>> tempo_1 = Tempo(Duration(1, 4), 90)
>>> tempo_2 = Tempo(Duration(1, 2), 90)
>>> tempo_1 - tempo_2
Tempo(reference_duration=Duration(1, 4), units_per_minute=45)

Returns new tempo.

Tempo.__truediv__(argument)

Divides tempo by argument. Operator required by Python 3.

Example 1. Divides tempo by number:

>>> Tempo(Duration(1, 4), 60).__truediv__(2)
Tempo(reference_duration=Duration(1, 4), units_per_minute=30)

Example 2. Divides tempo by other tempo:

>>> Tempo(Duration(1, 4), 60).__truediv__(
...     Tempo(Duration(1, 4), 40)
...     )
Multiplier(3, 2)

Returns new tempo.