Repository: cuthbertLab/music21 (python)

Issue:
stripTies() exception with chord symbols in v7.3.3
<!-- Version of music21:  print(music21.__version__) -->
**music21 version**

Issue is present on `7.3.3`, but not on `'6.7.1'`. Looks like a regression.

**Problem summary**

When calling `.stripTies()` on a score imported from MusicXML, an exception occurs when a tie over a barline has a chord symbol on the "stop" note. E.g. for this score 

![image](https://user-images.githubusercontent.com/369527/167020306-c826a996-34e7-4052-a36e-5dc054c4b3cb.png)

calling `x.stripTies()` fails with:

```
>>> x.stripTies()
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/Users/xavriley/opt/anaconda3/envs/qparse/lib/python3.9/site-packages/music21/stream/base.py", line 7126, in stripTies
     p.stripTies(inPlace=True, matchByPitch=matchByPitch)
   File "/Users/xavriley/opt/anaconda3/envs/qparse/lib/python3.9/site-packages/music21/stream/base.py", line 7312, in stripTies
     raise StreamException('aggregated ties have a zero duration sum')
 music21.exceptions21.StreamException: aggregated ties have a zero duration sum
```

Removing the chord symbol in the second bar ("Bb7") allows `stripTies()` to succeed.

**Steps to reproduce**

I did try to reproduce this using tiny notation but as far as I can tell, it only happens with a score from a MusicXML source.

A minimal XML example is available here: https://www.dropbox.com/s/xce206n23by2a3m/stripTiesBug.xml?dl=0. Loading it with

```
from music21 import *
x = converter.parse("/path/to/stripTiesBug.xml")
x.stripTies()
```

is enough to reproduce the issue.

Strangely, the following tinyNotation produces the same stream but *does not* raise an exception.

```
myStream1 = m21.converter.parse('tinynotation: 4/4 C.4 C8 F.4 B-8~ | B-8 B-8 D4 G4 F4')
myStream1.measures(0, None)[0].insert(0, m21.harmony.ChordSymbol('C7'))
myStream1.measures(0, None)[0].insert(2, m21.harmony.ChordSymbol('F7'))
myStream1.measures(0, None)[1].insert(0, m21.harmony.ChordSymbol('B-7'))
myStream1.stripTies()
```

**Expected vs. actual behavior**

`stripTies()` should work when chord symbols are present.

**More information**

As a workaround, removing the chord symbols seems to allow `stripTies()` to work e.g.

```
for c in x.recurse().getElementsByClass(m21.harmony.ChordSymbol):
    x.remove(c, recurse=True)

x.stripTies() # succeeds
```


Pull request:
Prevent zero-duration ChordSymbols from matching stripTies algorithm
Fix #1294 

Patch:
diff --git a/music21/stream/base.py b/music21/stream/base.py
index 865ecfdec..9b2427b15 100644
--- a/music21/stream/base.py
+++ b/music21/stream/base.py
@@ -7026,10 +7026,14 @@ class Stream(core.StreamCore, t.Generic[M21ObjType]):
             else:
                 return  # exit
 
-        # need to just get .notesAndRests, as there may be other objects in the Measure
+        # need to just get .notesAndRests with a nonzero duration,
+        # as there may be other objects in the Measure
         # that come before the first Note, such as a SystemLayout object
+        # or there could be ChordSymbols with zero (unrealized) durations
         f = returnObj.flatten()
-        notes_and_rests = f.notesAndRests.stream()
+        notes_and_rests = f.notesAndRests.addFilter(
+            lambda el, iterator: el.quarterLength > 0
+        ).stream()
 
         posConnected = []  # temporary storage for index of tied notes
         posDelete = []  # store deletions to be processed later


Test patch:
diff --git a/music21/stream/tests.py b/music21/stream/tests.py
index 33cff5850..a55b0b66a 100644
--- a/music21/stream/tests.py
+++ b/music21/stream/tests.py
@@ -1549,6 +1549,29 @@ class Test(unittest.TestCase):
             + '<music21.chord.Chord G4 C5>, <music21.chord.Chord C4 F4>)'
         )  # previously was 1 element
 
+    def testStripTiesIgnoresUnrealizedChordSymbol(self):
+        from music21 import harmony
+
+        n0 = note.Note('C')
+        n0.tie = tie.Tie('start')
+        n1 = note.Note('C')
+        n1.tie = tie.Tie('stop')
+
+        # Create ChordSymbol having one pitch only
+        cs0 = harmony.ChordSymbol()
+        cs0.bass('C', allow_add=True)
+        s = Stream()
+        s.insert(0.0, n0)
+        s.insert(1.0, cs0)
+        s.insert(1.0, n1)
+        s.makeNotation(inPlace=True)
+        stripped = s.stripTies(matchByPitch=True)
+
+        self.assertEqual(len(stripped[note.Note]), 1)
+        self.assertEqual(stripped[note.Note].first().quarterLength, 2)
+        self.assertEqual(len(stripped[harmony.ChordSymbol]), 1)
+        self.assertEqual(stripped[harmony.ChordSymbol].first().quarterLength, 0)
+
     def testTwoStreamMethods(self):
         from music21.note import Note