QuantizedPart¶
- class maelzel.scoring.quant.QuantizedPart(struct, measures, quantprofile, name='', shortname='', groupid='', groupname=None, firstclef='', autoClefChanges=None, showName=True)[source]¶
Bases:
object
A UnquantizedPart which has already been quantized following a ScoreStruct
A QuantizedPart is a part of a
QuantizedScore
Attributes Summary
If True, add clef changes when rendering this Part; None=use default.
The first clef of this part
A groupid, if applicable
The name of this part, used as staff name
The abbreviated staff name
If True, show part name when rendered
Methods Summary
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
()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
Given a Notation which is part of a logical tie (it is tied or tied to), return the logical tie
Iterate over all notations in this part
getMeasure
(idx[, extend])Get a measure within this part
- rtype:
list
[list
[TreeLocation
]]
measureAt
(beat)Returns the measure at the given location
notationAt
(beat)Returns the event at the given beat / location
pad
(numMeasures)Add the given number of empty measures at the end
removeUnnecessaryDynamics
([...])Remove superfluous dynamics in this part, inplace
Removes unnecessary gracenotes, in place
render
([options, backend])Render this quantized part
repair
()repairSpanners
([removeUnnecessary])Match orfan spanners, optionally removing unmatched spanners (in place)
resolveChordEnharmonics
([enharmonicOptions])Finds the best enharmonic variant for each chord individually
resolveEnharmonics
(options)- rtype:
None
show
([fmt, backend])Show this quantized part as notation
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
-
groupid:
str
= ''¶ A groupid, if applicable
-
groupname:
tuple
[str
,str
] |None
= None¶
-
name:
str
= ''¶ The name of this part, used as staff name
-
shortname:
str
= ''¶ The abbreviated staff name
-
showName:
bool
= True¶ If True, show part name when rendered
Methods Documentation
- 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 (
Fraction
|tuple
[int
,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:
Notation
|None
- 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
- dump(numindents=0, indent=' ', tree=True, stream=None)[source]¶
Dump this part to a stream or stdout
- findClefChanges(apply=False, removeManualClefs=False, window=1, threshold=0.0, biasFactor=1.5, property='clef')[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
threshold – 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
property – 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:
list
[TreeLocation
] |None
- Returns:
a list of TreeLocation representing the logical tie the notation n belongs to
- 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
- measureAt(beat)[source]¶
Returns the measure at the given location
- Parameters:
beat (
Fraction
|tuple
[int
,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 (
Fraction
|tuple
[int
,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.
- removeUnnecessaryDynamics(resetAfterEmptyMeasure=True)[source]¶
Remove superfluous dynamics in this part, inplace
- Return type:
None
- removeUnnecessaryGracenotes()[source]¶
Removes unnecessary gracenotes, in place
An unnecessary gracenote are: :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 usebackend – the backend to use. If not given the backend defined in the render options will be used instead
- Return type:
- Returns:
the Renderer
- repairSpanners(removeUnnecessary=True)[source]¶
Match orfan spanners, optionally removing unmatched spanners (in place)
- Parameters:
removeUnnecessary – if True, remove any spanner with no matching start/end spanner
- Return type:
None