From 773d9cf56d3f12a4276eacf248032127eb202756 Mon Sep 17 00:00:00 2001 From: Axel Berndt Date: Mon, 19 Aug 2024 16:04:55 +0200 Subject: [PATCH] v0.10.0 - Conversion of MEI to MusicXML implemented. Thanks to [Matthias Nowakowski](https://github.com/mnowakow). - `meiHead` nearly completely. - `music` most of the note-related data. - See `MEI2MusixXml_Coverage_Documentation.md` for more detail. --- README.md | 2 +- history.md | 7 ++++++ src/meico/mei/Helper.java | 32 ++++++++---------------- src/meico/mei/Mei2MusicXmlConverter.java | 6 ++--- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 7bc16a9b..4431f90b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Author: [Axel Berndt](https://github.com/axelberndt) ([Paderborn University](https://www.muwi-detmold-paderborn.de/personen/professorinnen-und-professoren/prof-dr-ing-axel-berndt), Detmold)
MEI support: [Benjamin W. Bohl](https://github.com/bwbohl), [Johannes Kepper](https://github.com/kepper)
-Contributor: [Simon Waloschek](https://github.com/sonovice)
+Contributor: [Matthias Nowakowski](https://github.com/mnowakow), [Simon Waloschek](https://github.com/sonovice)
#### Java Compatibility - meico ![Java compatibility 1.8+](https://img.shields.io/badge/java-1.8%2B-blue.svg) diff --git a/history.md b/history.md index f3c3463e..87bb3a1f 100644 --- a/history.md +++ b/history.md @@ -1,6 +1,13 @@ ### Version History +#### v0.10.0 +- Conversion of MEI to MusicXML implemented. Thanks to [Matthias Nowakowski](https://github.com/mnowakow). + - `meiHead` nearly completely. + - `music` most of the note-related data. + - See `MEI2MusixXml_Coverage_Documentation.md` for more detail. + + #### v0.9.4 - Conversion of MEI to MusicXML has been added to the commandline interface of meicoApp. diff --git a/src/meico/mei/Helper.java b/src/meico/mei/Helper.java index e5cb39b2..c79b66f8 100644 --- a/src/meico/mei/Helper.java +++ b/src/meico/mei/Helper.java @@ -8,25 +8,12 @@ import java.util.regex.Pattern; import com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory; -import meico.mpm.Mpm; -import meico.mpm.elements.Part; -import meico.mpm.elements.Performance; import meico.mpm.elements.maps.GenericMap; -import meico.mpm.elements.maps.data.TempoData; -import meico.mpm.elements.styles.TempoStyle; -import meico.mpm.elements.styles.defs.TempoDef; -import meico.msm.Msm; -import meico.supplementary.KeyValue; import net.sf.saxon.s9api.*; import net.sf.saxon.s9api.Serializer; import nu.xom.*; -import org.audiveris.proxymusic.Attributes; -import org.w3c.dom.Attr; import org.xml.sax.SAXException; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; @@ -125,14 +112,14 @@ public static LinkedList getAllChildElements(String name, Element ofThi * @param ofThis * @return */ - public static LinkedList getAllDescendants(String name, Element ofThis) { + public static LinkedList getAllDescendantsByName(String name, Element ofThis) { if ((ofThis == null) || name.isEmpty()) return null; LinkedList children = new LinkedList<>(); - for(Element ch : Helper.getAllChildElements(ofThis)){ - children.addAll(Helper.getAllDescendants(name, ch)); + for(Element ch : Helper.getAllChildElements(ofThis)) { + if(ch.getLocalName().equals(name)) + children.add(ch); + children.addAll(Helper.getAllDescendantsByName(name, ch)); } - List c = getAllChildElements(name, ofThis); - if(c != null) children.addAll(c); return children; } @@ -142,12 +129,13 @@ public static LinkedList getAllDescendants(String name, Element ofThis) * @param ofThis * @return */ - public static LinkedList getAllDescendantsByAttribute(String attrName, Element ofThis) { + public static LinkedList getAllDescendantsWithAttribute(String attrName, Element ofThis) { if ((ofThis == null) || attrName.isEmpty()) return null; LinkedList children = new LinkedList<>(); - for(Element ch : Helper.getAllChildElements(ofThis)){ - children.addAll(Helper.getAllDescendantsByAttribute(attrName, ch)); - if(ch.getAttribute(attrName) != null) children.add(ch); + for(Element ch : Helper.getAllChildElements(ofThis)) { + if(ch.getAttribute(attrName) != null) + children.add(ch); + children.addAll(Helper.getAllDescendantsWithAttribute(attrName, ch)); } return children; } diff --git a/src/meico/mei/Mei2MusicXmlConverter.java b/src/meico/mei/Mei2MusicXmlConverter.java index 48046d9a..b8208ff4 100644 --- a/src/meico/mei/Mei2MusicXmlConverter.java +++ b/src/meico/mei/Mei2MusicXmlConverter.java @@ -2220,7 +2220,7 @@ private boolean isPrevAttributeDifferent(Element e){ Element prevSection = Helper.getPreviousSiblingElement("section", section); // find previous section if(prevSection != null){ List measureChildren = Helper.getAllChildElements("measure", prevSection); - measureChildren = measureChildren == null || measureChildren.isEmpty() ? Helper.getAllDescendants("measure", prevSection) : measureChildren; // measures can be hidden in endings + measureChildren = measureChildren == null || measureChildren.isEmpty() ? Helper.getAllDescendantsByName("measure", prevSection) : measureChildren; // measures can be hidden in endings if(measureChildren != null && !measureChildren.isEmpty()) prevMeasure = measureChildren.get(measureChildren.size() - 1); // get last measure in measure list } } @@ -3193,7 +3193,7 @@ private void processTuplet(Note note, Element e){ if(num == null || num.isEmpty()) return; // tuplet parent may be present but cannot process ratios int numInt = Integer.parseInt(num); numbase = (numbase == null || numbase.isEmpty()) && (numInt & (numInt - 1)) == 0 ? "" + numInt : "" + (Integer.highestOneBit(numInt) ); - List descendants = Helper.getAllDescendantsByAttribute("dur", parentTuplet); + List descendants = Helper.getAllDescendantsWithAttribute("dur", parentTuplet); isFirst = descendants.indexOf(e) == 0; Collections.reverse(descendants); // reverse list to find last element isLast = descendants.indexOf(e) == 0; @@ -3203,7 +3203,7 @@ private void processTuplet(Note note, Element e){ for(String tVal : tupletVals) { Element parentLayer = Helper.getClosest("layer", e); // search beginning with layer, since e may be e.g. in a beam. // all tuplet elements have to be in same descendant tree; tuplets can't cross measure boundaries - List tupletElements = Helper.getAllDescendantsByAttribute("tuplet", parentLayer); + List tupletElements = Helper.getAllDescendantsWithAttribute("tuplet", parentLayer); if (tupletElements == null || tupletElements.isEmpty()) break; num = "" + tupletElements.size(); int numInt = Integer.parseInt(num);