From 8bb3a3b3e6c7c68508413300a80ea80bbfce84aa Mon Sep 17 00:00:00 2001 From: Zoltan Komives Date: Sat, 8 Mar 2014 22:03:11 +0000 Subject: [PATCH] fixed: 'index out of range' if lemma is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 https://github.com/DuChemin/MEIMassaging/issues/11 --- massage/test/dat/TC.Variants.02.WholeMeasure.mei | 15 ++++++++++++++- massage/transform/alt.py | 14 ++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/massage/test/dat/TC.Variants.02.WholeMeasure.mei b/massage/test/dat/TC.Variants.02.WholeMeasure.mei index a453761..a1ab866 100644 --- a/massage/test/dat/TC.Variants.02.WholeMeasure.mei +++ b/massage/test/dat/TC.Variants.02.WholeMeasure.mei @@ -96,6 +96,19 @@ + + + + + + + + + + + + + diff --git a/massage/transform/alt.py b/massage/transform/alt.py index 8404ff2..dcae4c7 100644 --- a/massage/transform/alt.py +++ b/massage/transform/alt.py @@ -291,8 +291,12 @@ 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) @@ -300,7 +304,6 @@ def wrap_whole_measure(staff, ALT_TYPE): 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 @@ -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()