Main Page | Modules | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | Related Pages

LibMusicXML Overview

0.92

Introduction

The MusicXML library provides a set of classes that covers the elements defined by the MusicXML 0.8 dtds. The library has been developped in C++, with a great care of preserving platform independence.

Connection between the classes and the xml elements is not a one-to-one relation: for simplification, a class may contain several MusicXML elements, provided that these elements are not reused anywhere else. For example, MusicXML defines dynamics as separate elements (see common.dtd): using a single object to represent them clarifies the representation. Apart a few exceptions detailled below, all of the MusicXML elements have their counterpart in the library representation.

A good knowledge of MusicXML is required for a good comprehension of the library.

Conventions

Memory management

Each class that describes a MusicXML element is handled using smart pointers . A smart pointer maintains a reference count for an object and takes in charge the automatic deletion of this object when its reference count drops to zero.

Objects that are handled using smart pointers derive from the smartable class. Their implementation prevents direct call to the constructor. Instead of constructor call, they provide a function to create a new object directly embedded within a smart pointer.

Smart pointers don't work when a loop in the reference occurs. However, it doesn't matter in our case since MusicXML is strictly hierarchical.

Class and type names.

All the classes that corresponds to a MusicXML element have a name in the form of Txxx where xxx relates to the MusicXML element name.

For each smartable class, a typedef defines the corresponding smart pointer as follow:
typedef Txxx Sxxx where xxx is the class name.

More generally:

Constructors.

As mentioned above, smartable classes prevent direct call to their constructor but a new function is provided which conforms to the following rule:

for a class named Txxx where xxx is the class name, the new function name is newxxx .

A new function interface is similar to the class constructor. Each MusicXML object provides a unique constructor. Arguments of a class constructor are limited to the required MusicXML element attributes.

Fields access.

Fields of the defined objects are generally private or at least protected. Semantic of a field may be deduced from the field name and from the object corresponding MusicXML description, which is provided as the class documentation. Access methods are designed according to the following rules:
Warning:
Read/write methods are always used with embedded smart pointers. These pointers are initialized by default and therefore points to null. This design is intended to denote undefined elements.

Files organization.

The files organization is similar to the MusicXML dtd files organization: for example, most of the elements or entities defined in common.dtd are handled by common.h. Elements described within MusicXML attributes.dtd or direction.dtd are respectively located in TAttributes.h or TDirection.h. When no correspondence exists between a header file and a MusicXML dtd, the header file name relates to a MusicXML element and declares this element and possibly other related elements. Except for common.h, all the files concerned by the above rules have a name starting with T.

Common entities representation

MusicXML defines entities that are common across multiple component DTDs. Many of them are intended to describe graphic layout like position, placement or orientation.

<!ENTITY % position
	"default-x     %tenths;    #IMPLIED
	 default-y     %tenths;    #IMPLIED
	 relative-x    %tenths;    #IMPLIED
	 relative-y    %tenths;    #IMPLIED">

<!ENTITY % placement
	"placement (above | below) #IMPLIED">

<!ENTITY % orientation
	"orientation (over | under) #IMPLIED">

These entities are defined as separate objects. A class is defined to aggregate the corresponding properties to objects that require them. For example, a TOrientation class is defined to describe the orientation entity; next an Orientable class is intended to provide the corresponding properties to derived classes. MusicXML elements that carry the orientation entity have to derive the Orientable class.

MusicXML also makes use of entities to enumerate values like the orientation defined above or the start-stop or yes-no examples below.

<!ENTITY % start-stop "(start | stop)">

<!ENTITY % yes-no "(yes | no)">

For all these entities, the library provides conversion classes (like the YesNo class) that:

class EXP YesNo {
    public:
    enum type { undefined, yes, no, last=no };

    static const string	xml (type d);
    static       type	xml (const string str);
};

Common types definition

Many of the MusicXML elements are defined as an alternative bewteen a set of elements. These alternative may be viewed as an inheritance relationship. Each time it has been convenient to do so, this relationship has been made explicit using a specific type, defined to cover the corresponding elements:

class TMusicData : public virtual visitable, public virtual smartable {
     protected:
        TMusicData () {}
        virtual ~TMusicData() {}
};

Similarly:

Browsing the music tree

The music representation is a tree which root is a timewise or partwise score. All the elements of the score support the visitor design pattern and accept a TScoreVisitor as the base class of the visitor design.

To preserve the choice of different strategies for the traversing the music representation structure, traversing has not been implemented in the tree components: it is assumed that it's the visitor responsability. A visitor that implements a basic traversing of the music structure is included in the library: the TRoutedVisitor.

A TRoutedVisitor provides a path for traversing of a score tree. Each implemented visite method calls accept() for its subclasses. Order of these calls is the following:

Reading and writing MusicXML files

The TMusicXMLFile object provides a simple API to read and write MusicXML files.

class EXP TMusicXMLFile {
    public:
                 TMusicXMLFile() {}
        virtual ~TMusicXMLFile() {}
		
        SScore	read (const string& file);
		
        bool	write (SScore score, const string& file);
        bool	write (SScore score, ostream& os);
};

It provides a read method that takes a file name as argument and returns smart pointer to a music score as result. The returned pointer is null in case of failure.

It provides write methods that take a music score and a file name or an ostream as arguments and returns a boolean value as result. The returned value is false in case of failure.

MusicXML Library specific elements

The library design is very close to the MusicXML definition. A music score memory representation tree matches the corresponding MusicXML tree with just a few exceptions:

MusicXML Elements to be implemented

The main part of the MusicXML elements is already covered by the current library. A small set of elements and attributes are however not yet supported. Below is the list of the to be implemented elements.

From attributes.dtd:

From direction.dtd: From identity.dtd: From note.dtd: From link.dtd: From opus.dtd: Some common attributes are also ignored by the current implementation. They are represented by entities in common.dtd.
Generated on Tue Mar 23 09:49:43 2004 for LibMusicXML by doxygen 1.3.3