Internal representation of scores and perhaps export/import modes

• Oct 19, 2021 - 20:57

I know very little about the internal workings of MuseScore. It seems to function as a kind of WYSIWYG piece of software, but it may have some internal intermediate coding. If it does have an intermediate data representation, then perhaps it could be used to generate a command line style of representation, which could be used for some applications.

Nowadays the fashion for much software is very much WYSIWYG but often a batch processing or command line method of operation is in fact more effective - just that so few people realise this now.

There would perhaps be only a limited benefit for many applications, but for eome operations something like a command line edit process could be helpful. For example, it would possible to write command line instructions like:

bars 21-43: map d4 ->c3
bars 52-72: map c* ->g?


The example here would replace all instances of note/pitch d4 by instances of c3.
The second example would replace any instance of C by a G in the same range.

I don't know whether this idea would have any benefits for anyone here. It might perhaps be good for very precise final corrections.


MuseScore does have an internal representation of the score, all programs have to represent data somehow. In principle someone could probably build a command parser as a plugin. The main problem to solve would be defining the language - what should the syntax look like? Assuming the commands themselves are just representing basic MuseScore functionality, then it should be pretty straightforward to invoke them from the plugin once it has parsed your input.

But depending on the specific goals, another approach might end up being more viable: export your score to MusicXML, import it into music21, and write your commands there. music21 already has a sophisticated set of primitives for operating on music.

In reply to by Marc Sabatella

That's interesting. I didn't know about music21. It might help.

Currently I just have a very simple operation to do - I want to change all instances of C to B.
Clearly this isn't going to be just a one off operation - if I know how to do that I'll learn how to do more.

The reason for the choice of this specific task is that I'm trying to reduce an existing piece to conform to a pentatonic scale in which C does not exist. I can do it manually, but it would be much easier to do it with computer support.

If you ever used the vi text editor, I'm looking for a MuseScore (and music equivalent) 1,$: s/C/B/ - which as you can see is very concise for text.

In reply to by dave2020X

But, for the record, you don't need any of this to change all C's to B. Just select all C's normally (right-click on C, Select / More, Same note name, OK), then hit the down arrow to transpose them down :-).

As for doing it programmatically, a plugin (*written in QML) can also do this quite simply. If you wish to export to MusicXML and work with that, languages like music21 make this simple.

So, I'm not crazy about the idea of inventing yet another language to something already handled in a variety of ways. But again, if you wish to design your own command line, presumably a plugin could be written to parse that. Although I rather doubt that would be simpler than just writing the plugin to do the thing you were otherwise going to invent a new language to do!

In reply to by yonah_ag

I think the issue with using XML is that while it is useful for computer programs, it is mostly not so useful for humans. We don't always consider such things. The representation does make a difference.

For example - I can represent Mozart's G minor symphony K550 by:

  1. A score.
  2. A CD of the piece
  3. Rather ephemerally by a "live performance"
  4. An audio file containing many zeros and ones.
  5. A graphical representation of the sounds of the symphony.

While you may think they are all equivalent - and they may be either approximately or even exactly equivalent [exact as in the CD and the file representation] most humans can only gain enjoyment from the representations shown by 2 and 3. A few can also read scores - point 1.

There may be many representations of an object, but not all are useful to most people.

In reply to by dave2020X

You can process this XML however you want. I first parse the XML and turn into a score map which is then easy for programmed edits. You could similarly process it into any format which suited you.

For batch processing you could process the XML directly by usin XPath and XSLT.

In reply to by dave2020X

You wrote:
I can do it manually, but it would be much easier to do it with computer support.
There may be many representations of an object, but not all are useful to most people.

That's why higher level human/computer interfaces like XML exist.
After all, we're not talking about low-level machine code here.

Do you still have an unanswered question? Please log in first to post your question.