This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Manuscript fixes #125
Open
th-we
wants to merge
11
commits into
DDMAL:develop
Choose a base branch
from
notengrafik:manuscript-fixes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Manuscript fixes #125
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e44fe2
Manuscript: meiDocumentToFile() would return true even if file creati…
th-we 347d6f0
ManuScript: Fix comment creation
th-we e6ba75d
ManuScript SetId() fix to not break getElementById() or getElementsBy…
th-we 2acdff2
Add RemoveChild() for ManuScript
th-we baf0dc6
ManuScript: Make AddChildAtPosition() simpler and more efficient
th-we 81946d9
Manuscript: Write "tail" after element
th-we b3d960c
Change ManuScript serialization to avoid added whitespace around text…
th-we 642710d
Add Thomas Weber to authors in ManuScript
th-we 712bd44
Remove surplus closing brace from ManuScript generation
th-we 3250888
Revert to re-generating MEIFlattened when removing elements in ManuSc…
th-we 040acea
Fix ManuScript variable names
th-we File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ | |
}" | ||
|
||
XMLComment "(comment) { | ||
commentObj = Create('<!--', null); | ||
commentObj = CreateElement('<!--', null); | ||
commentObj.text = comment; | ||
return commentObj; | ||
}" | ||
|
@@ -86,24 +86,37 @@ | |
element.children = childarr; | ||
}" | ||
AddChildAtPosition "(element, child, position) { | ||
AddChild(element, child); | ||
c = element.children; | ||
r = CreateSparseArray(); | ||
// copy the children to the new array. Add two | ||
// beyond the length since we'll be adding a new element. | ||
for i = c.Length + 2 { | ||
if (i = position) { | ||
r[i] = child; | ||
i = i + 1; | ||
} else { | ||
r[i] = c[i]; | ||
} | ||
// shift all children that are at a higher index than `position` | ||
for i = c.Length - 1 to position step -1 { | ||
c[i] = c[i - 1]; | ||
} | ||
element.children = r; | ||
element.children[position] = child._id; | ||
}" | ||
AddChild "(element, child) { | ||
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; | ||
UnregisterId(child._id); | ||
|
||
newarr = CreateSparseArray(); | ||
|
||
for each elid in element.children | ||
{ | ||
if (elid != child._id) | ||
{ | ||
newarr.Push(elid); | ||
} | ||
} | ||
|
||
element.children = newarr; | ||
}" | ||
GetAttributes "(element) { | ||
return element.attrs; | ||
|
@@ -156,8 +169,15 @@ | |
GetId "(element) { | ||
return element._id; | ||
}" | ||
SetId "(element, value) { | ||
element._id = value; | ||
SetId "(element, newId) { | ||
UnregisterId(element._id); | ||
element._id = value; | ||
Self.MEIFlattened[value] = element; | ||
}" | ||
UnregisterId "(id) { | ||
olddict = Self._property:MEIFlattened; | ||
newdict = removeKeyFromDictionary(olddict, oldid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. I made sure I unloaded/reloaded the proper files in Sibelius and ran the tests successfully. |
||
Self._property:MEIFlattened = newdict; | ||
}" | ||
RemoveAttribute "(element, attrname) { | ||
// since there are no delete functions | ||
|
@@ -221,7 +241,7 @@ | |
} | ||
res = CreateSparseArray(); | ||
for each e in Self.MEIFlattened { | ||
if (getName(e) = name) { | ||
if (IsObject(e) and getName(e) = name) { | ||
res.Push(e); | ||
} | ||
} | ||
|
@@ -292,12 +312,22 @@ | |
{ | ||
return '<' & name & spacer & attrstring & '>'; | ||
} | ||
}" | ||
childHasTail "(children) { | ||
for each child in children | ||
{ | ||
if (Length(GetTail(child)) > 0) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}" | ||
convertDictToXml "(meiel, indent) { | ||
// The indent parameter includes the leading line break | ||
|
||
xmlout = ''; | ||
terminalTag = true; | ||
trace('convert: '); | ||
trace(meiel); | ||
|
||
nm = libmei.GetName(meiel); | ||
at = libmei.GetAttributes(meiel); | ||
|
@@ -306,63 +336,45 @@ | |
tl = libmei.GetTail(meiel); | ||
id = libmei.GetId(meiel); | ||
|
||
tabs = ''; | ||
if (indent > 0) | ||
{ | ||
// add four spaces for every indent level. | ||
arr = utils.CreateArrayBlanket(' ', indent); | ||
tabs = JoinStrings(arr, ''); | ||
} | ||
|
||
// comments are simple so they're handled specially. | ||
if (nm = '<!--') | ||
{ | ||
xmlout = nm & ' ' & tx & ' --> | ||
'; | ||
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; | ||
} | ||
else | ||
{ | ||
xmlout = xmlout & ' | ||
'; | ||
// Do not add indentation whitespace as it might mess up text content | ||
indent = ''; | ||
} | ||
|
||
trace(ch); | ||
|
||
if (ch.Length > 0) | ||
{ | ||
indent = indent + 1; | ||
for each child in ch | ||
if (indent != '') | ||
{ | ||
if (child = null) | ||
{ | ||
trace('child is null!'); | ||
} | ||
else | ||
{ | ||
trace(child); | ||
} | ||
xmlout = xmlout & tabs & convertDictToXml(child, indent); | ||
innerIndent = indent & ' '; | ||
} | ||
else | ||
{ | ||
innerIndent = ''; | ||
} | ||
indent = indent - 1; | ||
} | ||
|
||
if (Length(tl) > 0) | ||
{ | ||
xmlout = xmlout & tl; | ||
for each child in ch | ||
{ | ||
xmlout = xmlout & convertDictToXml(child, innerIndent); | ||
} | ||
} | ||
|
||
// convertDictToXml takes care of adding the /> | ||
|
@@ -371,37 +383,31 @@ | |
// that do. | ||
if (not terminalTag) | ||
{ | ||
if (Length(tx) > 0) | ||
{ | ||
xmlout = xmlout & '</' & nm & '> | ||
'; | ||
} | ||
else | ||
{ | ||
tabs = Substring(tabs, 0, Length(tabs) - 4); | ||
xmlout = xmlout & tabs & '</' & nm & '> | ||
'; | ||
} | ||
xmlout = xmlout & indent & '</' & nm & '>'; | ||
} | ||
|
||
if (Length(tl) > 0) | ||
{ | ||
xmlout = xmlout & tl; | ||
} | ||
|
||
return xmlout; | ||
}" | ||
|
||
_exportMeiDocument "(meidoc) { | ||
xdecl = '<?xml version=' & Chr(34) & '1.0' & Chr(34) & ' encoding=' & Chr(34) & 'UTF-16' & Chr(34) & ' ?> | ||
'; | ||
indent = 0; | ||
meiout = xdecl & convertDictToXml(meidoc[0], indent); | ||
xdecl = '<?xml version=' & Chr(34) & '1.0' & Chr(34) & ' encoding=' & Chr(34) & 'UTF-16' & Chr(34) & ' ?>'; | ||
meiout = xdecl & convertDictToXml(meidoc[0], Chr(10)); | ||
|
||
return meiout; | ||
}" | ||
|
||
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) { | ||
|
@@ -839,10 +845,9 @@ | |
id = 'm-' & id; | ||
return id; | ||
}" | ||
} | ||
""" | ||
|
||
AUTHORS = "Andrew Hankinson, Alastair Porter, and Others" | ||
AUTHORS = "Andrew Hankinson, Alastair Porter, Thomas Weber and Others" | ||
|
||
FILE_TEMPLATE = """ | ||
{{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem here as in the sibmei repo -- I think
value
is supposed to benewId
?