- class maelzel.scoring.node.Node(ratio=(1, 1), items=None, parent=None, properties=None)[source]¶
A Node is a recursive container, grouping Notations and other Nodes under one time modifier
Notations within a Node are quantized. When a measure is quantized, its contents are grouped in a tree structure made out of Nodes (see
QuantizedMeasure.tree
)A Node consists of a sequence of Notations or Nodes, allowing to define nested tuplets or beats. The notations inside a Node already hold the real beat-duration. The durRatio is a ratio by which to multiply a given duration to obtain the notated duration.
A Node is used to represent the result of quantization.
Quantization happens first at the beat level and after that all quantized beats within a measure are merged together to create a tree structure spanning along the entire measure
See also
QuantizedMeasure.tree
- durRatio¶
a tuple ``(num, den)` indication the ratio by which to multiply the duration of the items to obtain the notated items: the items inside this tree For example, a quarternote triplet would have a durRatio (3, 2) and the items inside it would have a duration of 1/3. When multiplied by the durRatio each item would have a duration of 1/2
- items¶
the items in this tree (an item can be a Notation or a Node)
In the case of a simple triplet, the items would hold something like:
>>> from maelzel.scoring import * >>> notations = [makeNote(60, duration=F(1, 3)), ... makeNote(61, duration=F(2, 3))] >>> Node(ratio=(3, 2), items=notations)
- static asTree(nodes)[source]¶
Transform a list of Nodes into a tree structure
A tree has a root and leaves, where each leave can be the root of a subtree
- breakBeamsAt(offset)[source]¶
Breaks beams at the given offset
This method will not split a notation if the given offset is placed inside a syncopation
- Parameters:
offset (
Fraction
) – the offset to break beams at- Return type:
Notation
|None
- Returns:
the notation at the right of the split, or None if no split was performed
- property end: Fraction¶
The end of the last item within this Node
- findRoot()[source]¶
Find the root of this node
Nodes are organized in tree structures. This method will climb the tree structure until the root of the tree (the node without a parent) is found
- Return type:
- fixEnharmonics(options, prevTree=None)[source]¶
Find the best enharmonic spelling for the notations within this tree, inplace
- Parameters:
options (
EnharmonicOptions
) – the enharmonic options usedprevTree (
Optional
[Node
]) – the previous tree (the tree corrsponding to the previous measure)
- Return type:
None
- glissMarkTiedNotesAsHidden()[source]¶
Within a glissando, notes tied to previous and next notes can be hidden
- Return type:
None
- logicalTieLocations(measureIndex=None)[source]¶
Like logicalTies, but for each notation returns a TreeLocation
- Parameters:
measureIndex (
Optional
[int
]) – if given, it is used to fill the .measureIndex attribute in the returned TreeLocation- Return type:
list
[list
[TreeLocation
]]- Returns:
a list of ties, where each tie is a list of TreeLocations
- logicalTies()[source]¶
Iterate over all logical ties within self (recursively)
- Return type:
list
[list
[Notation
]]- Returns:
an iterator over the logical ties within self (recursively), where a logical tie is a list of Notations which are tied together
- mergedNotations(flatten=True)[source]¶
Returns a new tree with all items merged (recursively)
- Parameters:
flatten – if True, superfluous children are flattened
- Return type:
- Returns:
a new Node with merged items (whenever possible)
- property offset: Fraction¶
The offset of this Node within the measure
- recurse(reverse=False)[source]¶
Iterate over the items in self, recursively
- Parameters:
reverse – if True, iterate backwards
- Return type:
Iterator
[Notation
]- Returns:
an iterator over all Notations within this Node
- recurseWithNode(reverse=False)[source]¶
Iterate over the items if self, recursively
The same as
Node.recurse()
but for each item yields a tuple (notation, node) where node is the node to which the notation belongs. This is useful in order to modify the tree in the case one needs to, for example, remove a notation from its tree
- removeUnnecessaryGracenotes()[source]¶
Removes unnecessary gracenotes
- Return type:
int
- Returns:
the number of modifications
An unnecessary gracenote:
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
has the same pitch as the previous real note and has no attribute itself
- repairLinks()[source]¶
Repair ties and glissandi inplace
- Return type:
int
- Returns:
the number of modifications
- splitNotationAtBoundary(offset, callback=None)[source]¶
Split any notation which crosses the given offset, inplace
A notation will be split if it crosses the given offset. Raises SplitError if it cannot split at the given offset
- Parameters:
offset (
Fraction
) – the offset of the desired split. It should be a beat boundarycallback – if given, a function which returns True if the note should be split
- Return type:
Notation
|None
- Returns:
the notation next to the split offset, or None if no split operation was performed