music21.common.enums

BooleanEnum

class music21.common.enums.BooleanEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enum that replaces a boolean, except the “is” part, and allows specifying multiple values that can specify whether they equate to True or False.

Useful for taking an element that was previously True/False and replacing it in a backwards-compatible way with an Enum.

>>> from music21.common.enums import BooleanEnum
>>> class Maybe(BooleanEnum):
...    YES = True
...    NO = False
...    MAYBE = 0.5
...    NOT_A_CHANCE = (False, 'not a chance')
...    DEFINITELY = (True, 'of course!')
>>> bool(Maybe.YES)
True
>>> bool(Maybe.NO)
False
>>> bool(Maybe.MAYBE)
True
>>> bool(Maybe.NOT_A_CHANCE)
False
>>> bool(Maybe.DEFINITELY)
True
>>> Maybe.MAYBE == 0.5
True
>>> Maybe.NOT_A_CHANCE == 'not a chance'
True
>>> Maybe.NOT_A_CHANCE == False
True
>>> Maybe.NOT_A_CHANCE == True
False
>>> Maybe.NOT_A_CHANCE == 'not any chance'
False
>>> Maybe.DEFINITELY == 'of course!'
True
>>> Maybe.NOT_A_CHANCE == (False, 'not a chance')
True

ElementSearch

class music21.common.enums.ElementSearch(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enum representing the element search directions that can be provided to getContextByClass().

ElementSearch bases

GatherSpanners

class music21.common.enums.GatherSpanners(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enumeration for how to gather missing spanners

>>> from music21.common.enums import GatherSpanners

Indicates all relevant spanners will be gathered:

>>> GatherSpanners.ALL
<GatherSpanners.ALL>
>>> bool(GatherSpanners.ALL)
True

Indicates no relevant spanners will be gathered:

>>> GatherSpanners.NONE
<GatherSpanners.NONE>
>>> bool(GatherSpanners.NONE)
False

Indicates only spanners where all of their members are in the excerpt will be gathered:

>>> GatherSpanners.COMPLETE_ONLY
<GatherSpanners.COMPLETE_ONLY>
>>> bool(GatherSpanners.COMPLETE_ONLY)
True

GatherSpanners bases

MeterDivision

class music21.common.enums.MeterDivision(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Represents an indication of how to divide a TimeSignature

new in v7.

MeterDivision bases

OffsetSpecial

class music21.common.enums.OffsetSpecial(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enum that represents special offsets.

The enum AT_END is equal to the string ‘highestTime’

In version 9, the string comparisons will be removed.

>>> from music21.common.enums import OffsetSpecial
>>> OffsetSpecial.AT_END
<OffsetSpecial.AT_END>
>>> 'highestTime' == OffsetSpecial.AT_END
True
>>> 'crazyOffset' in OffsetSpecial
False
>>> 6.0 in OffsetSpecial
False
>>> 'lowestOffset' in OffsetSpecial
True
>>> str(OffsetSpecial.AT_END)
'highestTime'

New in v7.

OffsetSpecial bases

StrEnum

class music21.common.enums.StrEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enumeration where strings can equal the value.

See music21.common.enums.OffsetSpecial for an example of how these work.

StrEnumMeta

class music21.common.enums.StrEnumMeta(cls, bases, classdict, *, boundary=None, _simple=False, **kwds)