QuantizedPart

class maelzel.scoring.quant.QuantizedPart(struct, measures, quantProfile, name='', shortName='', groupid='', groupName=None, firstClef='', possibleClefs=(), autoClefChanges=None, showName=True, readonly=False)[source]

Bases: object

A UnquantizedPart which has already been quantized following a ScoreStruct

A QuantizedPart is a part of a QuantizedScore

Attributes Summary

autoClefChanges

If True, add clef changes when rendering this Part; None=use default.

firstClef

The first clef of this part

groupName

groupid

A groupid, if applicable

name

The name of this part, used as staff name

possibleClefs

Clefs to use when auto clef changes is used

readonly

shortName

The abbreviated staff name

showName

If True, show part name when rendered

Methods Summary

addEmptyMeasures(numMeasures)

Add the given number of empty measures at the end

addSpanner(spanner, start, end)

Adds a spanner between two notations at the given locations

averagePitch([maxNotations])

The average pitch of this part

bestClef()

Return the best clef for the notations in this part

breakBeam(location)

Break beams at a given location

breakSyncopationAt(location)

Break a syncopation/beam at the given beat/location

breakSyncopations([level])

Break notes extending over beat boundaries, inplace

check()

coreVoice()

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

Dump this part to a stream or stdout

findClefChanges([apply, removeManualClefs, ...])

Determines the most appropriate clef changes for this part

findLogicalTie(n)

Given a Notation which is part of a logical tie (it is tied or tied to), return the logical tie

flatNotations()

Iterate over all notations in this part

getMeasure(idx[, extend])

Get a measure within this part

logicalTies()

Return a list of logical ties in this part

measureAt(beat)

Returns the measure at the given location

notationAt(beat)

Returns the event at the given beat / location

removeRedundantDynamics([...])

Remove superfluous dynamics in this part, inplace

removeUnnecessaryGracenotes()

Removes unnecessary gracenotes, in place

render([options, backend])

Render this quantized part

repair()

repairLinks([tieSpelling])

Repairs ties and glissandi (in place)

repairSpanners()

Match orfan spanners, optionally removing unmatched spanners (in place)

resolveChordEnharmonics([enharmonicOptions])

Finds the best enharmonic variant for each chord in this part, individually

resolveEnharmonics(options)

Resolve enharmonic spelling, in place

setReadOnly(value)

show([fmt, backend])

Show this quantized part as notation

splitNotationAt(offset[, tie, mergeable])

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

Attributes Documentation

autoClefChanges: bool | None = None

If True, add clef changes when rendering this Part; None=use default. This corresponds to RenderOptions.autoClefChanges. Any part with manual clef changes will not be modified. To modify such a part see QuantizedPart.addClefChanges()

firstClef: str = ''

The first clef of this part

groupName: tuple[str, str] | None = None
groupid: str = ''

A groupid, if applicable

name: str = ''

The name of this part, used as staff name

possibleClefs: tuple[str, ...] = ()

Clefs to use when auto clef changes is used

readonly: bool = False
shortName: str = ''

The abbreviated staff name

showName: bool = True

If True, show part name when rendered

Methods Documentation

addEmptyMeasures(numMeasures)[source]

Add the given number of empty measures at the end

Return type:

None

addSpanner(spanner, start, end)[source]

Adds a spanner between two notations at the given locations

Parameters:
  • spanner (Spanner | str) – the spanner to add. A Spanner or the name of the spanner class (‘slur’, ‘beam’, etc.)

  • start (Union[int, float, Fraction, tuple[int, Union[int, float, Fraction]]]) – the start location.

  • end (Union[int, float, Fraction, tuple[int, Union[int, float, Fraction]]]) – the end location. Notice that to match a notation it must be present at this location. If the notation ends exactly at this location it will not be matched. For example, if a slur is needed across all notes within beat 0 and 1, one would call this method as ``part.addSpanner(‘slur’, 0, 1-F(1, 100000))

Return type:

None

Returns:

averagePitch(maxNotations=0)[source]

The average pitch of this part

Parameters:

maxNotations – if given, only the first maxNotations are considered for calculating the average pitch.

Return type:

float

Returns:

the average pitch of the notations in this part (0 if this part is empty)

bestClef()[source]

Return the best clef for the notations in this part

The returned str if one of ‘treble’, ‘treble8’, ‘bass’ and ‘bass8’

Return type:

str

Returns:

the clef descriptor which best fits this part; one of ‘treble’, ‘treble8’, ‘bass’, ‘bass8’, where the 8 indicates an octave transposition in the direction of the clef (high for treble, low for bass)

breakBeam(location)[source]

Break beams at a given location

Parameters:

location (Union[int, float, Fraction, tuple[int, Union[int, float, Fraction]]]) – the beat or location as tuple (measureindex, relative beat) to break beams at

Return type:

Notation | None

Returns:

the notation at which beams are broken (the notation at the given offset) or None if no break is possible at the given location

breakSyncopationAt(location)[source]

Break a syncopation/beam at the given beat/location

This method works in place at the tree level

Parameters:

location (Fraction | tuple[int, Fraction]) – an absolute offset in quarter notes, or a location as tuple (measure index, relative offset)

Return type:

list[Notation] | None

Returns:

the notations resulting of the split operation, or None if no notation was broken

breakSyncopations(level='weak')[source]

Break notes extending over beat boundaries, inplace

  • ‘all’: break syncopations at any beat boundary

  • ‘weak’: break syncopations at weak accent beats (for example, the 3rd beat in a 4/4 bar)

  • ‘strong’: break syncopations only at strong beats

Parameters:

level (str) – one of ‘all’, ‘weak’, ‘strong’

Return type:

None

check()[source]
coreVoice()[source]
Return type:

Voice

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

Dump this part to a stream or stdout

findClefChanges(apply=True, removeManualClefs=False, window=1, simplificationThreshold=0.0, biasFactor=1.5, propertyKey='', minClef='', maxClef='', possibleClefs=())[source]

Determines the most appropriate clef changes for this part

The clef changes are added as properties to the notations at which the changes are to be made. If called with addClefs=True, these clef changes are materialized as clef attachments

Parameters:
  • apply – if True, clef change directives are actually added to the quantized notations. Otherwise, only hints given as properties are added

  • removeManualClefs – if True, remove any manual clef

  • window – the window size when determining the best clef for a given section

  • simplificationThreshold – a simplification threshold. A value of 0. disables simplification

  • biasFactor – The higher this value, the more weight is given to the previous clef, thus making it more difficult to change clef for minor jumps

  • minClef – if given, only clefs equal or higher to this can be used

  • maxClef – if given, only clefs equal or lower to this can be used

  • possibleClefs (Sequence[str]) – if given, a seq. of allowed clefs

  • propertyKey – the property key to add to the notation to mark a clef change. Setting this property alone will not result in a clef change in the notation (see addClefs)

Return type:

None

findLogicalTie(n)[source]

Given a Notation which is part of a logical tie (it is tied or tied to), return the logical tie

Parameters:

n (Notation) – a Notation which is part of a logical tie

Return type:

LogicalTie | None

Returns:

a list of TreeLocation representing the logical tie the notation n belongs to

flatNotations()[source]

Iterate over all notations in this part

Return type:

Iterator[Notation]

getMeasure(idx, extend=True)[source]

Get a measure within this part

Parameters:
  • idx (int) – the measure index (starts at 0)

  • extend – if True and the index is outside the defined measures, a new empty QuantizedMeasure will be created and added to this part

Return type:

QuantizedMeasure | None

Returns:

The corresponding measure. If outside the defined measures a new empty QuantizedMeasure will be created

logicalTies()[source]

Return a list of logical ties in this part

A logical tie is a sequence of notations that are tied together.

Return type:

list[LogicalTie]

measureAt(beat)[source]

Returns the measure at the given location

Parameters:

beat (Union[int, float, Fraction, tuple[int, Union[int, float, Fraction]]]) – an absolute beat in quarter notes or a location as tuple (measure idx, relative beat)

Returns:

QuantizedMeasure, relative beat: F)

Return type:

a tuple (measure

notationAt(beat)[source]

Returns the event at the given beat / location

If the beat/location given is within the boundaries of this part, this method should always return a notation.

Parameters:

beat (Union[int, float, Fraction, tuple[int, Union[int, float, Fraction]]]) – the beat as absolute offset or location (measureindex, beatinmeasure)

Return type:

tuple[Notation, QuantizedMeasure]

Returns:

a tuple (notation, measure), where measure is the measure to which the returned event belongs. Bear in mind that within a quantized part a notation is always included within the boundaries of the measure. The notation itself might be tied to a previous/next notation.

removeRedundantDynamics(resetAfterEmptyMeasure=True, resetTime=0, resetAfterRest=0, resetAfterCustomBarline=True)[source]

Remove superfluous dynamics in this part, inplace

Parameters:
  • resetAfterEmptyMeasure – dynamics are reset after an empty measure

  • resetTime (int) – if given, dynamics are reset (forgotten) after this number of quarters after last change

Return type:

None

removeUnnecessaryGracenotes()[source]

Removes unnecessary gracenotes, in place

An unnecessary gracenote fullfills one of the following conditions: :rtype: None

  • has the same pitch as the next real note and starts a glissando. Such gracenotes might be created during quantization.

  • has the same pitch as the previous real note and ends a glissando

  • n0/real – gliss – n1/grace n2/real and n1.pitches == n2.pitches

render(options=None, backend='')[source]

Render this quantized part

Parameters:
  • options (Optional[RenderOptions]) – the RenderOptions to use

  • backend – the backend to use. If not given the backend defined in the render options will be used instead

Return type:

Renderer

Returns:

the Renderer

repair()[source]

Repairs ties and glissandi (in place)

Parameters:

tieSpelling – if True, ensures that tied notes share the same spelling

Return type:

None

repairSpanners()[source]

Match orfan spanners, optionally removing unmatched spanners (in place)

Return type:

None

resolveChordEnharmonics(enharmonicOptions=None)[source]

Finds the best enharmonic variant for each chord in this part, individually

As an alternative for finding the best global spelling it is possible to just fix each chord individually

Return type:

None

resolveEnharmonics(options)[source]

Resolve enharmonic spelling, in place

Parameters:

options (EnharmonicOptions) – the enharmonic options to use

Return type:

None

setReadOnly(value)[source]
Return type:

None

show(fmt='png', backend='')[source]

Show this quantized part as notation

Parameters:
  • fmt – the format to show, one of ‘png’, ‘pdf’

  • backend – the backend to use. One of ‘lilypond’, ‘musicxml’

splitNotationAt(offset, tie=True, mergeable=False)[source]

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

Parameters:
  • offset (Union[int, float, Fraction, tuple[int, Union[int, float, Fraction]]]) – the beat offset

  • 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