Skip to content

Commit

Permalink
Release Version 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
webern committed Aug 22, 2016
1 parent 53fd585 commit 5e1f1cc
Showing 1 changed file with 67 additions and 65 deletions.
132 changes: 67 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ public:
release = 2
};
BendChoice();
/* ... other stuff ... */
BendChoice::Choice getChoice() const;
void setChoice( BendChoice::Choice value );
Expand All @@ -291,69 +291,69 @@ private:
```

When `getChoice() == BendChoice::Choice::preBend` then we will see `<pre-bend/>` in the XML, but when `getChoice() == BendChoice::Choice::postBend` then we will see `<post-bend/>` in the XML.

### XML DOM (mx::xml)

Any XML document can be read and manipulated with the classes in the `mx::xml` namespace. Most notably, look at the following pure virtual interfaces XDoc, XElement, XAttribute. Also look at the STL-compliant iterators XElementIterator and XAttributeIterator.

These interfaces are designed to wrap any underlying XML DOM software so that `mx::core` does not care or know about the XML DOM code. A set of implementation classes wrapping pugixml are provided, but if you need to use, say Xerces or RapidXML, you can look at the PugiElement, PugiDoc, etc classes and wrap whatever library you need.

Here's how you can read a MusicXML document into `mx::core` classes by way of `mx::xml`.

```
#include "mx/core/Document.h"
#include "mx/utility/Utility.h"
#include "functions.h"
#include "mx/xml/XFactory.h"
#include "mx/xml/XDoc.h"
#include <iostream>
#include <string>
#include <sstream>
int main(int argc, const char *argv[])
{
// allocate the objects
mx::core::DocumentPtr mxDoc = makeDocument();
mx::xml::XDocPtr xmlDoc = mx::xml::XFactory::makeXDoc();
// read a MusicXML file into the XML DOM structure
xmlDoc->loadFile( "music.xml" );
// create an ostream to receive any parsing messages
std::stringstream parseMessages;
// convert the XML DOM into MusicXML Classes
bool isSuccess = mxDoc->fromXDoc( parseMessages, *xmlDoc );
if( !isSuccess )
{
std::cout << "Parsing of the MusicXML document failed with the following message(s):" << std::endl;
std::cout << parseMessages.str() << std::endl;
return -1;
}
// maybe the document was timewise document. if so, convert it to partwise
if( mxDoc->getChoice() == mx::core::DocumentChoice::timewise )
{
mxDoc->convertContents();
}
// get the root
auto scorePartwise = mxDoc->getScorePartwise();
// change the title
scorePartwise->getScoreHeaderGroup()->setHasWork( true );
scorePartwise->getScoreHeaderGroup()->getWork()->setHasWorkTitle( true );
scorePartwise->getScoreHeaderGroup()->getWork()->getWorkTitle()->setValue( mx::core::XsString( "New Title" ) );
// write it back out to disk
mxDoc->toXDoc( *xmlDoc );
xmlDoc->write( "newtitle.xml" );
return 0;
}
```

### XML DOM (mx::xml)

Any XML document can be read and manipulated with the classes in the `mx::xml` namespace. Most notably, look at the following pure virtual interfaces XDoc, XElement, XAttribute. Also look at the STL-compliant iterators XElementIterator and XAttributeIterator.

These interfaces are designed to wrap any underlying XML DOM software so that `mx::core` does not care or know about the XML DOM code. A set of implementation classes wrapping pugixml are provided, but if you need to use, say Xerces or RapidXML, you can look at the PugiElement, PugiDoc, etc classes and wrap whatever library you need.

Here's how you can read a MusicXML document into `mx::core` classes by way of `mx::xml`.

```
#include "mx/core/Document.h"
#include "mx/utility/Utility.h"
#include "functions.h"
#include "mx/xml/XFactory.h"
#include "mx/xml/XDoc.h"
#include <iostream>
#include <string>
#include <sstream>
int main(int argc, const char *argv[])
{
// allocate the objects
mx::core::DocumentPtr mxDoc = makeDocument();
mx::xml::XDocPtr xmlDoc = mx::xml::XFactory::makeXDoc();
// read a MusicXML file into the XML DOM structure
xmlDoc->loadFile( "music.xml" );
// create an ostream to receive any parsing messages
std::stringstream parseMessages;
// convert the XML DOM into MusicXML Classes
bool isSuccess = mxDoc->fromXDoc( parseMessages, *xmlDoc );
if( !isSuccess )
{
std::cout << "Parsing of the MusicXML document failed with the following message(s):" << std::endl;
std::cout << parseMessages.str() << std::endl;
return -1;
}
// maybe the document was timewise document. if so, convert it to partwise
if( mxDoc->getChoice() == mx::core::DocumentChoice::timewise )
{
mxDoc->convertContents();
}
// get the root
auto scorePartwise = mxDoc->getScorePartwise();
// change the title
scorePartwise->getScoreHeaderGroup()->setHasWork( true );
scorePartwise->getScoreHeaderGroup()->getWork()->setHasWorkTitle( true );
scorePartwise->getScoreHeaderGroup()->getWork()->getWorkTitle()->setValue( mx::core::XsString( "New Title" ) );
// write it back out to disk
mxDoc->toXDoc( *xmlDoc );
xmlDoc->write( "newtitle.xml" );
return 0;
}
```

### Hello World using mx::core
On the MusicXML home page there is an example of a "Hello World" simple MusicXML file. Here is a main function that would output this "Hello World" MusicXML example to std::cout.
Expand Down Expand Up @@ -429,6 +429,8 @@ The tests are slow to compile, see the *Compiling* section for more info on how

##### Historical Notes

**Release: Version 0.2 August 21, 2016** Adds the ability to import MusicXML documents into MusicXML Classes.

**Update: August 16, 2016:** All tests are passing (core, xml and import). The remaining items to do on the ximport feature are
- search for all `\\TODO's` and fix those that can be fixed
- Standardize the code file copyrights and bump to version 0.2
Expand Down

0 comments on commit 5e1f1cc

Please sign in to comment.