From 1e44fe24b39bc371c2ad20b3338412392a2d4603 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Thu, 13 Jun 2019 10:15:23 +0200 Subject: [PATCH 01/11] Manuscript: meiDocumentToFile() would return true even if file creation and writing failed --- tools/langs/manuscript.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/langs/manuscript.py b/tools/langs/manuscript.py index 073421a8..b72309bd 100644 --- a/tools/langs/manuscript.py +++ b/tools/langs/manuscript.py @@ -398,10 +398,11 @@ meiDocumentToFile "(meidoc, filename) { meiout = _exportMeiDocument(meidoc); - Sibelius.CreateTextFile(filename); - Sibelius.AppendTextFile(filename, meiout, 1); - - return true; + if (Sibelius.CreateTextFile(filename)) { + return Sibelius.AppendTextFile(filename, meiout, true); + } else { + return false; + } }" meiDocumentToString "(meidoc) { From 347d6f019869da6d988ed13e1aa30b4b3df68527 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 16 May 2021 12:05:45 +0200 Subject: [PATCH 02/11] ManuScript: Fix comment creation --- tools/langs/manuscript.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/langs/manuscript.py b/tools/langs/manuscript.py index b72309bd..bde832c3 100644 --- a/tools/langs/manuscript.py +++ b/tools/langs/manuscript.py @@ -46,7 +46,7 @@ }" XMLComment "(comment) { - commentObj = Create(' -'; + xmlout = indent & nm & ' ' & tx & ' -->'; return xmlout; } - if (ch or Length(tx) > 0) + if (ch.Length > 0 or Length(tx) > 0) { terminalTag = false; } - xmlout = createXmlTag(nm, id, at, terminalTag); + xmlout = indent & createXmlTag(nm, id, at, terminalTag); + + hasTextChild = Length(tx) > 0 or childHasTail(ch); - if (Length(tx) > 0) + if (hasTextChild) { - endchar = ''; xmlout = xmlout & tx; + // Do not add indentation whitespace as it might mess up text content + indent = ''; } - else - { - xmlout = xmlout & ' -'; - } - - trace(ch); if (ch.Length > 0) { - indent = indent + 1; + if (indent != '') + { + innerIndent = indent & ' '; + } + else + { + innerIndent = ''; + } + for each child in ch { - if (child = null) - { - trace('child is null!'); - } - else - { - trace(child); - } - xmlout = xmlout & tabs & convertDictToXml(child, indent); + xmlout = xmlout & convertDictToXml(child, innerIndent); } - indent = indent - 1; } // convertDictToXml takes care of adding the /> @@ -386,17 +383,7 @@ // that do. if (not terminalTag) { - if (Length(tx) > 0) - { - xmlout = xmlout & ' -'; - } - else - { - tabs = Substring(tabs, 0, Length(tabs) - 4); - xmlout = xmlout & tabs & ' -'; - } + xmlout = xmlout & indent & ''; } if (Length(tl) > 0) @@ -408,10 +395,8 @@ }" _exportMeiDocument "(meidoc) { - xdecl = ' -'; - indent = 0; - meiout = xdecl & convertDictToXml(meidoc[0], indent); + xdecl = ''; + meiout = xdecl & convertDictToXml(meidoc[0], Chr(10)); return meiout; }" From 642710ddd5c6e805c40b37f087ae9cee1500e21b Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 16 May 2021 15:11:18 +0200 Subject: [PATCH 08/11] Add Thomas Weber to authors in ManuScript --- tools/langs/manuscript.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/langs/manuscript.py b/tools/langs/manuscript.py index 54967c29..77d45bdf 100644 --- a/tools/langs/manuscript.py +++ b/tools/langs/manuscript.py @@ -848,7 +848,7 @@ } """ -AUTHORS = "Andrew Hankinson, Alastair Porter, and Others" +AUTHORS = "Andrew Hankinson, Alastair Porter, Thomas Weber and Others" FILE_TEMPLATE = """ {{ From 712bd448611e6768e51dfb31d5f9cc124622dcb1 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 16 May 2021 19:24:39 +0200 Subject: [PATCH 09/11] Remove surplus closing brace from ManuScript generation --- tools/langs/manuscript.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/langs/manuscript.py b/tools/langs/manuscript.py index 77d45bdf..ce18960c 100644 --- a/tools/langs/manuscript.py +++ b/tools/langs/manuscript.py @@ -845,7 +845,6 @@ id = 'm-' & id; return id; }" -} """ AUTHORS = "Andrew Hankinson, Alastair Porter, Thomas Weber and Others" From 3250888d1161a73a24828e24681eee60ecff1009 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Mon, 23 Aug 2021 20:15:41 +0200 Subject: [PATCH 10/11] Revert to re-generating MEIFlattened when removing elements in ManuScript --- tools/langs/manuscript.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/langs/manuscript.py b/tools/langs/manuscript.py index ce18960c..49ed06cf 100644 --- a/tools/langs/manuscript.py +++ b/tools/langs/manuscript.py @@ -98,6 +98,9 @@ cid = child._id; child._parent = element._id; element.children.Push(cid); + // The following might be redundant, but in case a child is removed from + // one parent and added to another, it's safer to re-register the ID. + Self.MEIFlattened[cid] = child; }" RemoveChild "(element, child) { child._parent = null; @@ -167,17 +170,14 @@ return element._id; }" SetId "(element, newId) { - oldId = element._id; - UnregisterId(oldId); - Self.MEIFlattened[newId] = element; - element._id = newId; + UnregisterId(element._id); + element._id = value; + Self.MEIFlattened[value] = element; }" UnregisterId "(id) { - // ManuScript dictionaries will return the empty string if an entry does - // not exists, so the most sensible way to cancel an element is to put the - // empty string in its place as ManuScript does not allow us to remove an - // entry entirely from a Dictionary - Self.MEIFlattened[id] = ''; + olddict = Self._property:MEIFlattened; + newdict = removeKeyFromDictionary(olddict, oldid); + Self._property:MEIFlattened = newdict; }" RemoveAttribute "(element, attrname) { // since there are no delete functions From 040acea75f1fd84dd3d5dc48bb8c352fe4277fdc Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Tue, 24 Aug 2021 08:24:56 +0200 Subject: [PATCH 11/11] Fix ManuScript variable names --- tools/langs/manuscript.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/langs/manuscript.py b/tools/langs/manuscript.py index 49ed06cf..87886903 100644 --- a/tools/langs/manuscript.py +++ b/tools/langs/manuscript.py @@ -171,12 +171,12 @@ }" SetId "(element, newId) { UnregisterId(element._id); - element._id = value; - Self.MEIFlattened[value] = element; + element._id = newId; + Self.MEIFlattened[newId] = element; }" UnregisterId "(id) { olddict = Self._property:MEIFlattened; - newdict = removeKeyFromDictionary(olddict, oldid); + newdict = removeKeyFromDictionary(olddict, id); Self._property:MEIFlattened = newdict; }" RemoveAttribute "(element, attrname) {