brown.models.beat

classes

A beat in a meter whose value is measured in rational numbers.

The beat fraction indicates beat as a fraction of a whole note. The actual written denomination of beat is deduced from the reduced fraction. For instance:

  • Beat(1, 4) indicates a quarter note value
  • Beat(1, 1) indicates a whole note value
  • Beat(3, 8) indicates a dotted quarter note value
Arbitrarily nested tuplets can be created by nesting Beats in each other. To do this, let the numerator of a Beat be a Beat where the denominator indicates the division within the outer Beat. The actual written denomination of the durataion is inferred.

  • Beat(Beat(1, 3), 4) indicates an eighth in a triplet spanning a quarter
  • Beat(Beat(1, 5), 8) indicates a 32nd in a quintuplet spanning an eighth
  • Beat(Beat(2, 10), 8) is equivalent to Beat(Beat(1, 5), 8) seen above, for the same reason that Beat(2, 8) is equivalent to Beat(1, 4)
  • Beat(Beat(3, 10), 8) indicates a dotted 32nd in a quintuplet spanning an eighth.
Nested Beats are not reduced into each other: Beats should be treated as immutable, and will not work correctly if their properties are changed after initialization.

# TODO: How to handle things like duplet over dotted quarter?

__init__ (*args) permalink view source

  • args: numerator (int or Beat): denominator (int):
OR: float_value (float): A floating point number to be approximated into a quantized beat. OR: beat (Beat): An existing Beat

properties

requires_tie: bool If this Beat requires a tie to be written. permalink view source

read-only.

numerator: int or Beat The numerator component of the beat fraction. permalink view source

If this is a Beat, self will represent a tuplet.

read-only.

denominator: int The denominator component of the beat fraction. permalink view source

read-only.

dot_count: int The number of dots this beat has. permalink view source

read-only.

base_division: int The basic division of the beat. permalink view source

read-only.

collapsed_fraction: Fraction The collapsed int / int Fraction of this beat. permalink view source

read-only.

class methods

from_float (value, round_to=None, limit_denominator=1024) permalink view source

Initialize from a float with an optional denominator to round toward.

arguments:

value (float):

round_to (int): A denominator to round toward.

limit_denominator (int): The maximum denominator value. If round_to is specified, this does nothing.

returns:

inherited from Beat

methods

__hash__ () permalink view source

Beats equal to each other share the same hash.

__float__ () permalink view source

Reduce the fractional representation to a float and return it.

__eq__ (other) permalink view source

Beats are equal if their numerators and denominators are.

__add__ (other) permalink view source

Durations are added by adding their reduced fractions.

Adding nested durations results in collapsing them into non-nested Durations

__sub__ (other) permalink view source

Durations are subtracted by subtracting their reduced fractions.

Subtracting nested durations results in collapsing them into non-nested Durations

__gt__ (other) permalink view source

Beats are ordered by their reduced fraction representations.

__ge__ (other) permalink view source

Beats are ordered by their reduced fraction representations.

Because Beat.__gt__ operates on the reduced fraction representation of the Beats being compared, but Beat.__eq__ compares based on exact non-reduced matches, Beats may pass Beat.__ge__, but not Beat.__eq__ if their numerators are nested differently. As such:

>>> Beat(1, 4) >= Beat(Beat(1, 1), 4)
True
>>> Beat(1, 4) == Beat(Beat(1, 1), 4)
False

__lt__ (other) permalink view source

Beats are ordered by their reduced fraction representations.

__le__ (other) permalink view source

Beats are ordered by their reduced fraction representations.

Because Beat.__lt__ operates on the reduced fraction representation of the Beats being compared, but Beat.__eq__ compares based on exact non-reduced matches, Beats may pass Beat.__le__, but not Beat.__eq__ if their numerators are nested differently. As such:

>>> Beat(1, 4) <= Beat(Beat(1, 1), 4)
True
>>> Beat(1, 4) == Beat(Beat(1, 1), 4)
False

to_fraction () permalink view source

Collapse this Beat into a single Fraction and return it.

returns:

Fraction

This recursively collapses any nested Beats and simplifies the returned Fraction.