Skip to content

Commit

Permalink
Adjust tests to v7 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Apr 30, 2021
1 parent 8c9b5c8 commit 0742d59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 17 additions & 13 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6288,32 +6288,36 @@ def stripInnerSpaces(txt):

def testVoiceNumbers(self):
n = note.Note()
v1 = stream.Voice([n])
m = stream.Measure([v1])
v1 = stream.Voice(n)
m = stream.Measure(v1)

# Unnecessary voice is removed by makeNotation
xmlOut = self.getXml(m)
self.assertNotIn('<voice>1</voice>', xmlOut)
n2 = note.Note()
v2 = stream.Voice([n2])
v2 = stream.Voice(n2)
m.insert(0, v2)
xmlOut = self.getXml(m)
self.assertIn('<voice>1</voice>', xmlOut)
self.assertIn('<voice>2</voice>', xmlOut)
v1.number = 234
# won't work, because it will makeNotation and renumber
# Number set by user will not be written, because makeNotation renumbers
xmlOut = self.getXml(m)
self.assertNotIn('<voice>234</voice>', xmlOut)
self.assertIn('<voice>1</voice>', xmlOut)
self.assertIn('<voice>2</voice>', xmlOut)
# should work, because it won't makeNotation and won't renumber
# TODO: replace with makeNotation=False when option exists
newScore = stream.Score([stream.Part()])
newScore.parts.first().append(m)
root = self.getET(newScore)
xmlOut = helpers.dumpString(root)
self.assertIn('<voice>234</voice>', xmlOut)
self.assertIn('<voice>-1</voice>', xmlOut) # this voice was never given a .number
v2.id = 'hello' # won't work, only reads from number!

# Number set by user WILL be written, because makeNotation=False
# TODO: implement makeNotation=False
# newScore = stream.Score([stream.Part()])
# newScore.parts.first().append(m)
# root = self.getET(newScore)
# xmlOut = helpers.dumpString(root)
# self.assertIn('<voice>234</voice>', xmlOut)
# self.assertIn('<voice>-1</voice>', xmlOut) # this voice was never given a .number

# Other fields such as .id will not be written to <voice>
v2.id = 'hello'
xmlOut = self.getXml(m)
self.assertNotIn('<voice>hello</voice>', xmlOut)

Expand Down
6 changes: 4 additions & 2 deletions music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10965,7 +10965,8 @@ def flattenUnnecessaryVoices(self, *, force=False, inPlace=False, recurse=False)
>>> len(voicesFlattened.voices)
0

>>> s = stream.Stream([note.Note(), note.Note(), note.Note()]) # simultaneous
>>> s = stream.Stream()
>>> s.repeatInsert(note.Note(), [0, 0, 0]) # simultaneous
>>> s.makeVoices(inPlace=True)
>>> s.voices[0].number = -1
>>> s.voices[1].number = 5
Expand All @@ -10974,7 +10975,8 @@ def flattenUnnecessaryVoices(self, *, force=False, inPlace=False, recurse=False)
>>> [v for v in s.voices]
[<music21.stream.Voice 1>, <music21.stream.Voice 2>, <music21.stream.Voice 3>]

>>> m = stream.Measure([note.Note(), note.Note(), note.Note()]) # simultaneous
>>> m = stream.Measure()
>>> m.repeatInsert(note.Note(), [0, 0, 0]) # simultaneous
>>> m.makeVoices(inPlace=True)
>>> p = stream.Part([m])
>>> p.insert(0, stream.Voice()) # extra unnecessary voice
Expand Down

0 comments on commit 0742d59

Please sign in to comment.