Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions music21/scale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def getPitchFromNodeDegree(self,
alteredDegrees=self._alteredDegrees,
equateTermini=equateTermini
)
return copy.deepcopy(post)
return post

def realizePitchByDegree(self,
pitchReference: _PitchOrStr,
Expand Down Expand Up @@ -654,7 +654,7 @@ def getNewTonicPitch(self,
maxPitch=maxPitch,
alteredDegrees=self._alteredDegrees
)
return copy.deepcopy(post)
return post

# --------------------------------------------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions music21/scale/intervalNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -2707,15 +2707,16 @@ def getPitchFromNodeDegree(
# environLocal.printDebug(['comparing', realizedNId,
# 'nodeTargetId', nodeTargetId])

# realizedPitch may be a cached realization: hand back a copy
if realizedNId == nodeTargetId.id:
return realizedPitch[i]
return copy.deepcopy(realizedPitch[i])
# NOTE: this condition may be too generous, and was added to solve
# a non-tracked problem.
# only match this generously if we are equating termini
if equateTermini:
if ((realizedNId in (Terminus.HIGH, Terminus.LOW))
and (nodeTargetId.id in (Terminus.HIGH, Terminus.LOW))):
return realizedPitch[i]
return copy.deepcopy(realizedPitch[i])

# environLocal.printDebug(['getPitchFromNodeDegree() on trial', trial, ',
# failed to find node', nodeTargetId])
Expand Down
22 changes: 22 additions & 0 deletions music21/scale/test_intervalNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,28 @@ def test_realize_descending_reversed_cached(self):
self.assertEqual(descending_melodic_minor_reversed[0].nameWithOctave, 'C4') # was B-4
self.assertEqual(descending_melodic_minor_reversed[-1].nameWithOctave, 'B-4') # was C4

def test_get_pitch_from_node_degree_returns_a_new_pitch(self):
'''
A realization may be held in _ascendingCache or _descendingCache, so
the pitch taken out of one has to be the caller's own -- otherwise
writing to it edits the cached scale.
'''
net = IntervalNetwork()
net.fillBiDirectedEdges(['M2', 'M2', 'm2', 'M2', 'M2', 'M2', 'm2'])

first = net.getPitchFromNodeDegree('c4', 1, 1)
self.assertEqual(first.nameWithOctave, 'C4')
first.octave = 1

again = net.getPitchFromNodeDegree('c4', 1, 1)
self.assertEqual(again.nameWithOctave, 'C4')

def test_next_pitch_does_not_move_a_cached_degree(self):
sc = scale.RagAsawari('c4')
self.assertEqual(str(sc.pitchFromDegree(1)), 'C4')
self.assertEqual(str(sc.nextPitch('c1', Direction.ASCENDING)), 'D1')
self.assertEqual(str(sc.pitchFromDegree(1)), 'C4')


# ------------------------------------------------------------------------------
if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion music21/scale/test_scale_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def testRagAsawari(self):
getNeighbor=Direction.DESCENDING)),
'F1')

self.assertEqual(str(sc.pitchFromDegree(1)), 'C1')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from .agents/skills/writing-docs/SKILL.md


Say what is, not what was or what not to do

Describe current behavior. Do not narrate the bug you just fixed, the old
spelling of an API, or when upstream changed something.


more there for the agent to digest... :-)

self.assertEqual(str(sc.pitchFromDegree(1)), 'C4')
# there is no third step in ascending form
self.assertEqual(str(sc.pitchFromDegree(3)), 'None')
self.assertEqual(str(sc.pitchFromDegree(3, direction=Direction.DESCENDING)),
Expand Down
Loading