Skip to content

Commit

Permalink
fixed: 'index out of range' if lemma <staff> is empty
Browse files Browse the repository at this point in the history
- extended whole-measure test case to test this behaviour.
- commented out the last measure of this test case, because it’s
currently makes the test fail due to
DuChemin#11
  • Loading branch information
zolaemil committed Mar 8, 2014
1 parent fc6ab86 commit 8bb3a3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 14 additions & 1 deletion massage/test/dat/TC.Variants.02.WholeMeasure.mei
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@
</staff>
</measure>
<measure n="4">
<staff n="1"/>
<staff n="2">
<layer n="1">
<note dur="2" oct="4" pname="f" color="rgba(255,0,0,1)"/>
<note dur="2" oct="4" pname="f" color="rgba(255,0,0,1)"/>
<note dur="1" oct="4" pname="f" color="rgba(255,0,0,1)"/>
</layer>
</staff>
<staff n="3">
<layer/>
</staff>
</measure>
<!-- <measure n="5">
<staff n="1">
<layer n="1">
<mRest/>
Expand All @@ -113,7 +126,7 @@
<mRest/>
</layer>
</staff>
</measure>
</measure> -->
</section>
</score>
</mdiv>
Expand Down
14 changes: 10 additions & 4 deletions massage/transform/alt.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,19 @@ def wrap_whole_measure(staff, ALT_TYPE):
if ALT_TYPE == EMENDATION:
rich_wrapper_name = 'choice'
rich_default_name = 'sic'
old_layer = staff.getChildrenByName('layer')[0]
notelist = get_descendants(old_layer, 'note rest space')
old_layers = staff.getChildrenByName('layer')
notelist = []
if len(old_layers) > 0:
old_layer = staff.getChildrenByName('layer')[0]
notelist.extend(get_descendants(old_layer, 'note rest space'))
staff.removeChild(old_layer)
new_layer = MeiElement('layer')
rich_wrapper = MeiElement(rich_wrapper_name)
rich_default_elem = MeiElement(rich_default_name)
for note in notelist:
rich_default_elem.addChild(note)
rich_wrapper.addChild(rich_default_elem)
new_layer.addChild(rich_wrapper)
staff.removeChild(old_layer)
staff.addChild(new_layer)
return rich_wrapper

Expand All @@ -327,7 +330,10 @@ def legal_with_lemma(staff, skip, dur):
"""
print "legal_with_lemma(" + str(staff) + ", " + str(skip) + ", " + str(dur) +")"
# print('legal_with_lemma(): ' + staff.getAttribute('n').value + ', s' + str(skip) + 'd' + str(dur))
old_layer = staff.getChildrenByName('layer')[0]
old_layers = staff.getChildrenByName('layer')
if len(old_layers) == 0:
return False
old_layer = old_layers[0]
notelist = get_descendants(old_layer, 'note rest space')
for note in notelist:
dur_attr = note.getAttribute('dur').getValue()
Expand Down

0 comments on commit 8bb3a3b

Please sign in to comment.