Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Capella parsing. #1342

Merged
merged 1 commit into from
Jul 14, 2022
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
15 changes: 12 additions & 3 deletions music21/capella/fromCapellaXML.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def systemFromSystem(self, systemElement, systemObj=None):
TODO: Handle multiple <voices>
'''
if systemObj is None:
systemObj = stream.System()
systemObj = layout.System()

stavesList = systemElement.findall('staves')
if not stavesList:
Expand Down Expand Up @@ -895,8 +895,17 @@ def slurFromDrawObjSlur(self, drawObj):


class Test(unittest.TestCase):
pass
def testComplete(self):
from music21 import text

ci = CapellaImporter()
capellaDirPath = common.getSourceFilePath() / 'capella'
oswaldPath = capellaDirPath / r'Nu_rue_mit_sorgen.capx'
partScore = ci.scoreFromFile(oswaldPath)
self.assertEqual(len(partScore.parts), 3)
self.assertGreater(len(partScore.recurse().notes), 20)
self.assertIn('mass!', text.assembleLyrics(partScore.parts[0], 1))
self.assertIn('scherz', text.assembleLyrics(partScore.parts[0], 2))

class TestExternal(unittest.TestCase):
show = True
Expand Down Expand Up @@ -930,4 +939,4 @@ def xtestImportSorgen(self):

if __name__ == '__main__':
import music21
music21.mainTest(Test, TestExternal)
music21.mainTest(Test) # , TestExternal)
5 changes: 4 additions & 1 deletion music21/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,10 @@ class System(stream.Score):
'''
Designation that all the music in this Stream
belongs on a single notated system.
'''

Attribute systemNumbering says at what point the numbering of
systems resets. It can be either "Score" (default), "Opus", or "Page".
'''
def __init__(self, *args, **keywords):
super().__init__(*args, **keywords)
self.systemNumber = 0
Expand All @@ -1589,6 +1591,7 @@ def __init__(self, *args, **keywords):
self.pageSystemNumber = 0

self.systemLayout = None
self.systemNumbering = 'Score' # or Page; when do system numbers reset?
self.measureStart = None
self.measureEnd = None

Expand Down
30 changes: 24 additions & 6 deletions music21/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def assembleLyrics(streamIn, lineNumber=1):
Concatenate text from a stream. The Stream is automatically flattened.

The `lineNumber` parameter determines which line of text is assembled,
as an index in the .lyrics array. (To be changed in v7 to go with an
identifier.)

as a ONE-indexed identifier in the .lyrics array.
(To be changed in v8 to go with an identifier.). This means that
`lineNumber=0` will retrieve the last line of text.

>>> s = stream.Stream()
>>> n1 = note.Note()
Expand All @@ -83,6 +83,15 @@ def assembleLyrics(streamIn, lineNumber=1):
>>> n1.lyrics[0] = composite
>>> text.assembleLyrics(s)
"He'_ya there"

To get the lyrics from another line, set the lineNumber attribute.
(see also :func:`~music21.text.assembleAllLyrics` to get all
lyrics).

>>> n1.addLyric('Bye')
>>> n2.addLyric('Now')
>>> text.assembleLyrics(s, lineNumber=2)
'Bye Now'
'''
word = []
words = []
Expand Down Expand Up @@ -120,7 +129,8 @@ def assembleLyrics(streamIn, lineNumber=1):

def assembleAllLyrics(streamIn, maxLyrics=10, lyricSeparation='\n'):
r'''
Concatenate all Lyrics text from a stream. The Stream is automatically flattened.
Concatenate all Lyrics text from a stream separated by lyricSeparation.
The Stream is automatically recursed.

uses assembleLyrics to do the heavy work.

Expand All @@ -130,15 +140,23 @@ def assembleAllLyrics(streamIn, maxLyrics=10, lyricSeparation='\n'):
Here is a demo with one note and five lyrics.

>>> f = corpus.parse('demos/multiple-verses.xml')
>>> text.assembleLyrics(f, 1)
'1. First'
>>> text.assembleLyrics(f, 2)
'2. Second'
>>> l = text.assembleAllLyrics(f)
>>> l
'\n1. First\n2. Second\n3. Third\n4. Fourth\n5. Fifth'
'1. First\n2. Second\n3. Third\n4. Fourth\n5. Fifth'

Changed in v.8: no lyric separator appears at the beginning.
'''
lyrics = ''
for i in range(1, maxLyrics):
lyr = assembleLyrics(streamIn, i)
if lyr != '':
lyrics += lyricSeparation + lyr
if i > 1:
lyrics += lyricSeparation
lyrics += lyr
return lyrics


Expand Down