Skip to content

Commit

Permalink
Verticality separate offsetTree from timespanTree
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Apr 2, 2024
1 parent 3f9880c commit 7c26c12
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions music21/tree/verticality.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from music21.tree import spans

if t.TYPE_CHECKING:
from music21.tree.trees import OffsetTree
from music21.voiceLeading import VoiceLeadingQuartet

environLocal = environment.Environment('tree.verticality')
Expand Down Expand Up @@ -131,6 +132,7 @@ class Verticality(prebase.ProtoM21Object):
# CLASS VARIABLES #

__slots__ = (
'offsetTree',
'timespanTree',
'overlapTimespans',
'startTimespans',
Expand All @@ -139,8 +141,11 @@ class Verticality(prebase.ProtoM21Object):
)

_DOC_ATTR: dict[str, str] = {
'offsetTree': r'''
Returns the tree initially set else None
''',
'timespanTree': r'''
Returns the timespanTree initially set.
Returns the tree initially set if it was a TimespanTree, else None
''',
'overlapTimespans': r'''
Gets timespans overlapping the start offset of a verticality.
Expand Down Expand Up @@ -211,17 +216,17 @@ class Verticality(prebase.ProtoM21Object):
def __init__(
self,
offset: OffsetQL = 0.0,
overlapTimespans: tuple[spans.ElementTimespan, ...] =(),
startTimespans: tuple[spans.ElementTimespan, ...] =(),
stopTimespans: tuple[spans.ElementTimespan, ...] =(),
overlapTimespans: tuple[spans.ElementTimespan, ...] = (),
startTimespans: tuple[spans.ElementTimespan, ...] = (),
stopTimespans: tuple[spans.ElementTimespan, ...] = (),
timespanTree=None,
):
from music21.tree.timespanTree import TimespanTree
if timespanTree is not None and not isinstance(timespanTree, TimespanTree):
raise VerticalityException(
f'timespanTree {timespanTree!r} is not a TimespanTree or None')
self.offsetTree: OffsetTree | None = timespanTree
self.timespanTree: TimespanTree | None = None
if isinstance(timespanTree, TimespanTree):
self.timespanTree = timespanTree

self.timespanTree: TimespanTree | None = timespanTree
self.offset: OffsetQL = offset

if not isinstance(startTimespans, tuple):
Expand Down Expand Up @@ -359,7 +364,7 @@ def nextStartOffset(self) -> float|None:
If a verticality has no tree attached, then it will return None
'''
tree = self.timespanTree
tree = self.offsetTree
if tree is None:
return None
offset = tree.getPositionAfter(self.offset)
Expand Down Expand Up @@ -391,7 +396,7 @@ def nextVerticality(self):
>>> verticality.nextVerticality
<music21.tree.verticality.Verticality 3.0 {A3 E4 C#5}>
'''
tree = self.timespanTree
tree = self.offsetTree
if tree is None:
return None
offset = tree.getPositionAfter(self.offset)
Expand Down Expand Up @@ -505,7 +510,7 @@ def previousVerticality(self):
>>> verticality.previousVerticality
<music21.tree.verticality.Verticality 0.0 {A3 E4 C#5}>
'''
tree = self.timespanTree
tree = self.offsetTree
if tree is None:
return None
offset = tree.getPositionBefore(self.offset)
Expand Down Expand Up @@ -753,9 +758,6 @@ def makeElement(
else:
quarterLength = common.opFrac(quarterLength)

if t.TYPE_CHECKING:
assert quarterLength is not None

if not self.pitchSet:
r = note.Rest()
r.duration.quarterLength = quarterLength
Expand Down Expand Up @@ -789,6 +791,9 @@ def newNote(ts, n: note.Note) -> note.Note:
return nNew

offsetDifference = common.opFrac(self.offset - ts.offset)
if t.TYPE_CHECKING:
assert quarterLength is not None

endTimeDifference = common.opFrac(ts.endTime - (self.offset + quarterLength))
if t.TYPE_CHECKING:
assert endTimeDifference is not None
Expand Down

0 comments on commit 7c26c12

Please sign in to comment.