Skip to content

Commit

Permalink
v0.6.12
Browse files Browse the repository at this point in the history
- New additions to class `meico.xml.XmlBase`: Methods `removeAllElements(String localName)` and `removeAllAttributes(String attributeName)` can be used for processing of all XML based formats.
  • Loading branch information
axelberndt committed Jul 23, 2019
1 parent b63a95e commit 0ad89b3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Made several classes in package `meico.app.gui` package-private as they will never be accessed from outside the package and are not intended to.
- Made class `meico.msm.MsmBase` abstract and renamed it to `AbstractMsm`.
- Removed MSM's global header element `pulsesPerQuarter`. Instead an eponimous Attribute has been added to the root note of the MSM.
- New additions to class `meico.xml.XmlBase`: Methods `removeAllElements(String localName)` and `removeAllAttributes(String attributeName)` can be used for processing of all XML based formats.


#### v0.6.11
Expand Down
44 changes: 43 additions & 1 deletion src/meico/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

import meico.Meico;
import meico.audio.Audio;
import meico.mpm.Mpm;
import meico.mpm.elements.Header;
import meico.mpm.elements.Part;
import meico.mpm.elements.Performance;
import meico.mpm.elements.styles.MetricalAccentuationStyle;
import meico.mpm.elements.styles.defs.AccentuationPatternDef;
import meico.mpm.elements.styles.defs.RubatoDef;
import meico.mpm.elements.styles.RubatoStyle;
import meico.pitches.Pitches;
import meico.mei.Helper;
import meico.mei.Mei;
import meico.msm.Msm;

import nu.xom.Attribute;
import nu.xom.Element;
import nu.xom.ParsingException;
import org.xml.sax.SAXException;

Expand All @@ -28,6 +37,39 @@ public class Main {
* @param args command line arguments
*/
public static void main(String[] args) {

////// mpm test ////////////////////////////////////////
Mpm mpm = new Mpm();
Performance performance1 = Performance.createPerformance("test1");
Element p2Elt = new Element("performance");

p2Elt.addAttribute(new Attribute("name", "test2"));
Performance performance2 = Performance.createPerformance(p2Elt);

mpm.addPerformance(performance1);
mpm.addPerformance(performance2);

performance1.addPart(Part.createPart("test part", 0, 0, 0));

performance1.getPart("test part").getHeader().addStyleDef("testStyles", "testStyle1");
performance1.getPart("test part").getHeader().addStyleDef("testStyles", "testStyle2");
performance1.getPart("test part").getHeader().addStyleType("anotherTestTypeStyles");

performance1.getPart(0).getHeader().addStyleDef(Mpm.RUBATO_STYLE, RubatoStyle.createRubatoStyle("rubaStyle"));
Header header = mpm.getPerformance("test1").getPart("test part").getHeader();
((RubatoStyle)header.getStyleDef(Mpm.RUBATO_STYLE, "rubaStyle")).addRubatoDef(RubatoDef.createRubatoDef("rubi", 20.5, 0.6, 0.1, 0.9));

header.addStyleDef(Mpm.METRICAL_ACCENTUATION_STYLE, MetricalAccentuationStyle.createMetricalAccentuationStyle("my accentuation style"));
MetricalAccentuationStyle mas = (MetricalAccentuationStyle) header.getStyleDef(Mpm.METRICAL_ACCENTUATION_STYLE, "my accentuation style");
AccentuationPatternDef pattern = AccentuationPatternDef.createAccentuationPatternDef("pattern 1", 4.0);
pattern.addAccentuation(1.0, 1.0, -0.5, 0.0);
pattern.addAccentuation(3.0, 0.5, -0.5, 0.5);
pattern.addAccentuation(2.0, 0.25, -1.0, 0.25);
mas.addAccentuationPatternDef(pattern);

System.out.println(((MetricalAccentuationStyle)performance1.getPart("test part").getHeader().getStyleDef(Mpm.METRICAL_ACCENTUATION_STYLE, "my accentuation style")).getAccentuationPatternDef("pattern 1").toXml());
///////////////////////////////////////////////////////////

if (args.length == 0) { // if meico.jar is called without command line arguments
// Meico.launch("Meico: MEI Converter v" + Meico.version); // 1st string is the window title (is optional, MeicoApp generates a default title if none is given here)
Meico.launch(); // this is the minimal call to launch meico's gui
Expand Down
36 changes: 36 additions & 0 deletions src/meico/xml/XmlBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,42 @@ public Element getRootElement() {
return this.data.getRootElement();
}

/**
* remove all elements with the specified local name from the xml tree
* @param localName the elements to be removed
* @return the number of elements removed
*/
public int removeAllElements(String localName) {
int deletions = 0; // count the deletions
Nodes ns = this.getRootElement().query("descendant::*[local-name()='" + localName + "']"); // get all elements with the local name

for (int i = 0; i < ns.size(); ++i) { // for all nodes found
Element parent = (Element)ns.get(i).getParent(); // get its parent element
if (parent != null) { // if it has a parent (does not apply to the root node)
parent.removeChild(ns.get(i)); // remove its child
deletions++; // increase the deletions counter
}
}
return deletions; // return the deletions count
}

/**
* remove all attributes with the specified name from the xml tree
* @param attributeName the attribute name
* @return the number of deletions
*/
public int removeAllAttributes(String attributeName) {
Nodes ns = this.getRootElement().query("descendant::*[@" + attributeName + "]"); // get all nodes with an attribute of the specified name

for (int i = 0; i < ns.size(); ++i) { // for all nodes found
Element e = (Element)ns.get(i); // get the node as element
Attribute a = e.getAttribute(attributeName); // get the attribute
e.removeAttribute(a); // delete the attribute from the element
}

return ns.size();
}

/**
* transform the data via the given xsl file
* @param xslt
Expand Down

0 comments on commit 0ad89b3

Please sign in to comment.