QuantizedMeasure

class maelzel.scoring.quant.QuantizedMeasure(timesig, quarterTempo, beats, quantprofile, subdivisions=None, parent=None, readonly=False)[source]

Bases: object

A QuantizedMeasure holds a quantized tree

If given a list of QuantizedBeats, these are merged together in a recursive structure to generate a tree of Nodes. See QuantizedMeasure.asTree()

Parameters:
  • timesig (TimeSignature) – the time signature

  • quarterTempo (Fraction) – the tempo of the quarter note

  • beats (list[QuantizedBeat]) – a list of QuantizedBeats

  • quantprofile (QuantizationProfile) – the quantization profile used to generate this quantized measure. This is necessary to create a tree structure

  • subdivisions (Optional[tuple[int, ...]]) – a list of integers corresponding to the number of units of the denominator of the fused time signature. This can override the subdivision structure defined in the time signature itself. For example, for a 7/8 measure with subdivisions of 2+3+2, this parameter should be (2, 3, 2)

  • parent (Optional[QuantizedPart]) – the QuantizedPart this measure belongs to

Methods Summary

beatAtOffset(offset)

The beat which includes the given offset

beatBoundaries()

The beat offsets, including the end of the measure

beatOffsets()

Returns a list of the offsets of each beat within this measure

beatStructure()

beatWeights()

breakSyncopations([level])

Break notes extended over beat boundaries, in place

check()

dump([numindents, indent, tree, stream])

duration()

Duration of this measure, in quarter notes

empty()

Is this measure empty?

findLogicalTie(n)

logicalTies()

Returns a list of locations for each tie

measureIndex()

Return the measure index of this measure within the QuantizedPart

notationAt(beat)

Returns the notation present at the given beat location relative to this measure

notations()

Returns a flat list of all notations in this measure

previousMeasure()

Returns the previous measure in the part

recurseNotationsWithParent([reverse])

Returns a flat iterator over all notations in this measure, along with their parent nodes

removeUnnecessaryGracenotes()

repair()

setBeamSubdivisions(beat[, minimum, ...])

Customize beam subdivision

setReadOnly(value)

splitNotationAt(offset[, tie, mergeable])

Split any notation present at offset in place, returns the resulting parts

Methods Documentation

beatAtOffset(offset)[source]

The beat which includes the given offset

Parameters:

offset (Fraction) – offset relative to the start of this measure

Returns:

QuantizedBeatDef, beatIndex: int). To access the actual QuantizedBeat, use measure.beats[beatIndex]

Return type:

a tuple (beatdef

Raises:

ValueError – if the given offset is outside the measure

beatBoundaries()[source]

The beat offsets, including the end of the measure

Return type:

list[Fraction]

Returns:

the boundaries of the beats, which is the offsets plus the end of the measure

beatOffsets()[source]

Returns a list of the offsets of each beat within this measure

Return type:

list[Fraction]

Returns:

the offset of each beat. The first offset is always 0

beatStructure()[source]
Return type:

list[QuantizedBeatDef]

beatWeights()[source]
Return type:

list[int]

breakSyncopations(level='')[source]

Break notes extended over beat boundaries, in place

The level indicates which syncopations to break. ‘all’ will split any notations extending over any beat; ‘weak’ will only break syncopations over secondary beats (for example, the 3rd quarter-note in a 4/4 measure); ‘strong’ will only break syncopations over strong beats (the 4th quarternote in a 6/4 measure with the form 3+3, or the 3rd quarternote in a 7/8 measure with the form 2+2+3)

Parameters:

level (str) – one of ‘all’, ‘weak’, ‘strong’. If not given, the level set in the quantization profile is used

Return type:

None

check()[source]
dump(numindents=0, indent='  ', tree=True, stream=None)[source]
Return type:

None

duration()[source]

Duration of this measure, in quarter notes

Return type:

Fraction

Returns:

the duration of the measure in quarter notes

empty()[source]

Is this measure empty?

Return type:

bool

Returns:

True if empty

findLogicalTie(n)[source]
Return type:

LogicalTie | None

logicalTies()[source]

Returns a list of locations for each tie

A tie is a list of tied notations. For each tie, a list of TreeLocations is returned

Return type:

list[LogicalTie]

measureIndex()[source]

Return the measure index of this measure within the QuantizedPart

Return type:

int | None

notationAt(beat)[source]

Returns the notation present at the given beat location relative to this measure

Parameters:

beat (Fraction | float | int) – the relative location

Return type:

Notation | None

Returns:

the Notation at the given beat location, or None if no Notation found

notations()[source]

Returns a flat list of all notations in this measure

The notations returned are the actual notations, so any modification to them will affect the measure.

Return type:

list[Notation]

Returns:

a list of Notations in this measure

previousMeasure()[source]

Returns the previous measure in the part

Return type:

QuantizedMeasure | None

Returns:

the previous measure (a QuantizedMeasure), or None if no previous measure

Raises:

ValueError – if this QuantizedMeasure does not have a parent

recurseNotationsWithParent(reverse=False)[source]

Returns a flat iterator over all notations in this measure, along with their parent nodes

The notations returned are the actual notations, so any modification to them will affect the measure.

Parameters:

reverse – If True, the notations are returned in reverse order

Return type:

Iterator[tuple[Notation, Node]]

Returns:

an iterator over the Notations in this measure

removeUnnecessaryGracenotes()[source]
Return type:

None

repair()[source]
Return type:

bool

setBeamSubdivisions(beat, minimum=Fraction(0, 1), maximum=Fraction(0, 1), once=True)[source]

Customize beam subdivision

The beams of consecutive 16th (or shorter) notes are, by default, not subdivided. That is, the beams of more than two stems stretch unbroken over entire groups of notes. This behavior can be modified to subdivide the beams into sub-groups. Beams will be subdivided at intervals to match the metric value of the subdivision.

Note

At the moment this is only supported by the lilypond backend

Parameters:
  • beat (Fraction | float | int) – the beat to customize

  • minimum (Fraction | int) – minimum limit of beam subdivision. A fraction or simply the denominator. 1/8 indicates an eighth note, 16 indicates a 16th note

  • maximum (Fraction | int) – maximum limit of beam subdivision. Similar to minimum

  • once – if True, only apply this customization to the beat starting at beat

Return type:

None

Example

>>> measure = part.measureAt(...)
# Split any beam shorter than 1/8. This will break a group of 4 16th notes
# into two groups of 2 16th notes
>>> measure.setBeamSubdivisions(0, F(1, 8))
setReadOnly(value)[source]
splitNotationAt(offset, tie=True, mergeable=False)[source]

Split any notation present at offset in place, returns the resulting parts

Parameters:
  • offset (Fraction) – the beat offset within the measure

  • tie – if True, tie the resulting parts

  • mergeable – if False, mark the marks as unmergeable

Return type:

list[Notation] | None

Returns:

the resulting parts or None if no notations present at the given offset. Raises ValueError if the given offset is not within the span of this measure