MakeMusic
SmartMusic Finale Garritan MusicXML

Why I am making a C++ MusicXML Library

Moderator: Michael Good

Why I am making a C++ MusicXML Library

Postby .mjb » Wed Mar 25, 2015 12:51 pm

This is a continuation from here viewtopic.php?p=8791#p8791

Michael asked me why I am not using this https://github.com/dfober/libmusicxml
Instead I am creating this https://github.com/Webern/mxdom/blob/ma ... Elements.h

My reasons should not be construed as criticism of dfober's library. In fact I'm sure he is a far superior software designer than I am. But my issue with using libmusicxml is that it isn't idiot-proof enough for me. Take an example from this sample program https://github.com/dfober/libmusicxml/b ... mMusic.cpp

Here is just one line from it:
Code: Select all
creator->add(newAttribute("type", "Composer"));


So here the user must know that an attribute name "type" that takes a string value is something that can be added. For example what if I replace this line with
Code: Select all
creator->add(newAttribute("badstring", "someotherstring"));


The program will still compile, but will it throw an exception or produce invalid MusicXML? (I'm not sure which, it would take some reading or compiling to figure that out).

So what I wanted instead was OOP classes for everything. Call it "super strong" binding.
My library will look more like this
Code: Select all
CreatorPtr creator = makeCreator();
creator->setValue( XsString("Matthew James Briggs" ) );
creator->getAttributes()->hasType = true;
creator->getAttributes()->type = XsToken( "Composer" );


Thus, in my library you don't need to know that the creator element can have an optional type attribute which has an xs:token value. The IDE knows. And you cannot create a program that will compile and produce MusicXML and that fails XSD validation. Also my library (like libmusicxml) will not use anything out of C++ std and STL. Unlike libmusicxml I will not have any "naked new"'s in my library (i.e. using RAII via std::shared_ptr which is more available in C++11 than it may have been when libmusicxml was authored)

Now there are many options out there for automatically creating classes from xsd documents. I half-heartedly tried a few, but generally found the output to be either extremely difficult to build (I am inexperienced and using Xcode, not a good combo for building things on the first try), or that they did not get me what I wanted (impossible to build a program that violates the XSD, and the IDE knows everything about MusicXML so that I don't have to).

Additionally, as an aspiring programmer I decided to take on the challenge of parsing/crawling the xsd myself and generating my own classes from it. This is far, far harder to do than I ever would have imagined.

I've been able to generate about 50-75% of the classes in a mostly automated meta-programming fashion (i.e. writing programs that spit out C++ code), but for the remaining 25% of the classes, the self-referential permutations are just too much for me so I'm now able to stub out the classes, more-or-less but it takes about 15 minutes per element to write customized code to handle situations that I can't easily parse out of the XSD. (For example the structure of <metronome-tuplet> which used a complexContent declaration including a complex type, which has a sequence in it... I think these are going to get harder as I progress through the final 85 elements I have left to implement).

Why am I doing this at all? Well ultimately I want to write programs that generate musical compositions straight to musicxml (or generate musical material straight to musicxml as part of the composing process). Instead of going for the shortest path to achieve this outcome, I decided to try any make a library that was more-or-less professional in completeness and design, for the experience and because I hope my next day job will involve writing C++ code. We shall see, but I sure have learned a lot!
User avatar
.mjb
 
Posts: 15
Joined: March, 2014
Location: Seattle, WA, USA
Reputation: 0
Software Owned:
Finale 2014, Logic Pro X, Mac 10.9.5, Xcode, Xmplify

Who is online

Users browsing this forum: No registered users and 1 guest

cron