XML Exporter For OSME Practice Generator

With the exercise generator developed within the framework of OpenSheetMusicEducation (OSME), you can create musical exercises for dexterity on the instrument or for sight reading, etc. The desired musical parameters: for example the clef, the time signature, the range, the number of bars, can be set in the interface to generate an exercise at the click of a button and display it on the screen with OpenSheetMusicDisplay (OSMD).

In order to share the generated exercise with other people or to simply archive it, it must be saved in a suitable format. The musicXML format, which is also supported by OSMD, has established itself in the field of music notes.

What does the technical process look like behind the scenes?

The OSME Practice Generator uses the OSMD object model to create the necessary musical objects such as bar, clef and individual notes. I.e. depending on the parameter settings of the generator and the algorithm inside it, which works with a certain random component, the necessary musical objects are calculated and then generated using the definitions in the OSMD object model. The following figure shows a part of the objects listed on the left and the corresponding source code (here for a note in a bar) on the right. The complete list of all objects can be found in the OSMD class documentation, which is automatically generated from the source code: https://opensheetmusicdisplay.github.io/classdoc/globals.html

Now let’s consider the following exercise which could be created with the generator:

Possible Practice Measures for OSME

Four measures are needed here. In the first measure there is an indication of the clef and the time signature followed by the individual notes.

What does this look like in relation to the object model – here a list of the necessary instructions:

1)create measure 1 (= Measure)

  • create clefs (=ClefInstruction) and add to measure
  • create time signature (=RhythmInstruction) and add to measure
  • create note D and add to measure
  • create note H and add to measure
  • create note A and add to measure

2) create measure 2 (= Measure)

3) …

The finished object model can now be displayed with OSMD and would then generate the image above on the screen.

To save the object model, it is necessary to use a generally readable standard like musicXML. The object model must therefore be written or converted into a musicXML.

Therefore the object model has to be run through hierarchically (iterated) – starting with measure 1, then all objects within measure 1, then measure 2, and so on. – to generate the necessary textual XML instructions parallel to each object.

For example, the clef is translated into the following instructions:

<clef>
      <sign>G</sign>
      <line>2</line>
</clef>

After the complete translation of the object model and the addition of further necessary parameters such as XML header and possibly title etc., the following text file corresponding to the musicXML standard is generated:

This musicXML file can now be split and opened by a variety of music programs and OSMD.

If you’re wondering why the musicXML isn’t just created directly by the Practice Generator: That would be possible, of course. But you also need your own object model – so you have to define a second object model – and in addition the described solution offers further advantages: you now have all necessary components to edit a read musicXML graphically in OSMD. An example would be:

  • import and display musicXML
  • click on a note and move it vertically
  • save the modified musicXML with the XML exporter

The editing functionality would be very welcome in the OSMD community and has already been requested several times.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.