generating mscx file
Dear all,
For some projects I'm doing algorithmic composition and I need to generate scores.
In previous projects I've worked it out by generating MIDI files and importing them into Musescore. But now I have a more complex outcome, and in my tests the imported files are missing some very basic info in the resulting score (e.g. correct time placement). I guess this is intrinsically related to the way MIDI encodes time.
So, before switching to lilypond, I was trying to understand if I can generate mscx file.
Is there a specification anywhere? I can't find it.
Has anyone tried to generated mscx files from code?
Thanks
-a-
Comments
You could use the Batch Convert plugin, or the
-j files.json
commandline option any a suitable json fileOt the
-o mscxfile.mscx midifile.mid
commandline optionIn reply to You could use the Batch… by Jojo-Schmitz
thanks, I think I've not been clear.
I'm not satisfied with midi import. I'd like to understand mscx in order to write it.
Or, if there are other solution to automatic generate musescore, I'll be happy to here
Best
In reply to thanks, I think I've not… by Andrea Valle
I looked for a format spec for ms3 mscx files a while back but couldn't find one. However, you can reverse engineer them by using a score of increasing complexity and inspecting the results. Depending on how complex your needs are this may be a viable solution for programmed composition.
In reply to I looked for a format spec… by yonah_ag
The only spec for mscx files is in the source code, and this is on purpose, and that 'spec' is subject to change
In reply to The only spec for mscx files… by Jojo-Schmitz
But presumably there is a (large) core of the format that doesn't change?
I'll inspect some of my scores and see what I can come up with.
Without knowing more about your project, it's difficult for me to imagine why you wouldn't use the standardized MusicXML format. It's well-documented, supported by MuseScore and most other notation programs, can be directly exported by music21 and probably other programming toolkits for music, and it doesn't tend to change radically.
In reply to Without knowing more about… by Marc Sabatella
I've written composing-like programs that generate MusicXML. It's quite easy, and the clear way to go.
In reply to I've written composing-like… by [DELETED] 1831606
I'm wondering whether the direct mscx approach would yield cleaner imported results. For example, when I import a MusicXML TAB from GP6 it ends up in MS3 with the word TAB at the start of every bar, which I then have to select and delete.
Why do programs such as MuseScore, Guitar Pro etc. use their own formats rather than use MusicXML as a native format?
In reply to I'm wondering whether the… by yonah_ag
Programs such as MuseScore use their own formats because they can do many more things than music XML can express, and do not want to be limited its definition. And they want to be able to grow and add new capabilities, which would be ruled out by that constraint. I assure you there is nothing in the definition of musicxml that puts the word "TAB" where you saw it. See https://www.musicxml.com/ for the definition of the standard.
In reply to Programs such as MuseScore… by [DELETED] 1831606
It does appear to be the GP export. Within every measure tag there is clef tag with the code: < sign >TAB< /sign >
In reply to It does appear to be the GP… by yonah_ag
One can write python programs that take the output of one program, say GP, and massage it the way you want (e.g., delete such elements, and write a new (XML, MIDI, or whatever)) file. The whole point of music xml is to be easily-processable.
In reply to One can write python… by [DELETED] 1831606
Yes, that will be a good option.
In reply to One can write python… by [DELETED] 1831606
If you're using Python, then music21 makes MusicXML processing a no-brainer.
In reply to If you're using Python, then… by Marc Sabatella
I will use Python so thanks for the heads up. Is MS written in Python? If so, is there a plugin hook in the open MusicXML code where I could call my GPTABCleanup function?
In reply to I will use Python so thanks… by yonah_ag
No, MuseScore is written in C++
In reply to No, in C++ by Jojo-Schmitz
(To yonah and OP) Nothing of the sort proposed should require familiarity with, let alone modification of, the code or internal logic of MS. The discussion is about a transaction in the coinage of music, not a change to the way MuseScore operates.
In reply to (To yonah and OP) Nothing of… by [DELETED] 1831606
I will write a standalone program but I just wondered if MS provided any hooks for including external user code. Calibre, a well known eBook manager/converter written in Python, provides many opportunities for user plugin code without having to mod the main program. So if MS had been similar then I could've called my external code automatically on opening a MusicXML file.
In reply to I will write a standalone… by yonah_ag
You can certainly write plugins for MuseScore, that's kind of a separate topic though, doesn't seem to relate to what is actually being proposed here.
In reply to You can certainly write… by Marc Sabatella
And plugins for MuseScore are written in a specialization of Javascript.
In reply to And plugins for MuseScore… by [DELETED] 1831606
I am familiar with JavaScript so could I write a plugin for MS which would process my MusicXML file from GP before opening it with MS? This would be a user interface plugin.
In reply to I am familiar with… by yonah_ag
Being "familiar with javascript" is not enough. You have to learn the QML interface language, which is expressed in Javascript, and the Musescore plugin API, which is expressed in that. It's nontrivial. What you propose really doesn't make architectural sense. You can write a plugin which runs after the XML has been opened, and simply deletes any staff text element whose content is "TAB". But, as I said, you still have to learn all those levels. It is much easier to read the XML with a language of your choice, delete elements you don't like and write it back. Involving MuseScore seems wrong.
In reply to Being "familiar with… by [DELETED] 1831606
If I had my druthers, you'd be able to say, as in Emacs, "Begin define keystroke macro. Search for 'TAB' (can't even do that now). Delete. End keystroke macro. Save as 'deltab'" and put in a menu and call it as many times as necessary, including a one-keystroke way to repeat. Emacs can do this.
In reply to Being "familiar with… by [DELETED] 1831606
Involving MS would provide an integrated and automated solution but it is probably OTT in this situation. With calibre it's easy and practical because it's Python all the way so this would make more sense.
In reply to I am familiar with… by yonah_ag
And as I said, using music21 will simplify this immensely - it already knows MusicXML and can build you a complete representation of your score in nicely organized musically aware data structures in like two lines of code. trying to write almighty. To todo the same would be hundreds if not thousands of lines of code, not to mention the work learning the format, designing your own data structures, etc.
In reply to And as I said, using music21… by Marc Sabatella
That's overbroad. It would be as trivial, if not more, to read the MusicXML with any general xml-reading tool (e.g, elementTree), find all the whatevers son of whatevers whose whatever is whatever with exactly one CSS-directed call, and remove them from their parents in two more lines (without learning music21's representation formalism).
In reply to That's overbroad. It would… by [DELETED] 1831606
Please post one of the GP tab-troubled music xml's so I can prove it.
In reply to That's overbroad. It would… by [DELETED] 1831606
The current situation of removing the TAB element is indeed very simple and can be done with any decent text editor which I have already done. I was just thinking about a completely automated solution.
In reply to That's overbroad. It would… by [DELETED] 1831606
If it's literally only doing one operation fiddling with all elements of a given type, OK, sure. But the original thread here is about algorithmic composition. And it's not all clear what the perceived problem with GP's output really is and whether fixing it would really be as simple as that. So music21 is still going to be a huge benefit in the general case, even if there is the occasional task for which a "sed" script is sufficient.
In reply to If it's literally only doing… by Marc Sabatella
Oh, yes, for algorithmic composition music21 is absolutely right. The problem here is that there are two threads on his page.
In reply to Oh, yes, for algorithmic… by [DELETED] 1831606
Sorry, my fault. I got excited at the prospect of using MS (on Windows) and GP, (on Windows and Android), together and not having to wait any longer for the display of TAB in the MS Android app to be fixed.
In reply to Oh, yes, for algorithmic… by [DELETED] 1831606
Right, and a huge middle ground between, with many people likely to be reading this in the future with an interest somewhere between those extremes, so I wanted to address that whole range.
In reply to And as I said, using music21… by Marc Sabatella
I have had a look at the documentation for music21 and it certainly looks powerful.
In reply to I've written composing-like… by [DELETED] 1831606
thanks to all, I understand the point of not documenting core format on purpose and rather consider MusicXML. I thought that it could have been easier to directly address Musescore format.
BSG. have you got some example? I find MusicXML quite messy, but maybe i just need to look at it again
In reply to thanks to all, I understand… by Andrea Valle
Do you want my python code, or examples of music xml it has created, or just a score that I generated that way (admittedly, not a visually complex one), or all? https://musescore.com/bsg/scores/5320392 is a score generated by code of mine via MusicXML.
In reply to Do you want my python code,… by [DELETED] 1831606
I'll probably have a play with music xml from Python and VB. How can I tell if the artifacts produced by using MusicXML between GP and MS are caused by GP or MS. I don't mean to hijack this thread but I am very interested in import/export with MS as the MS Android App is dreadful with TAB and I want a viable alternative.
Your example score certainly looks clean enough.
In reply to I'll probably have a play… by yonah_ag
You learn the basics of MusicXML (which is intended to be understandable) from http://musicxml.com and study and maybe modify the music xml files you have.
In reply to You learn the basics of… by [DELETED] 1831606
👍 (Sorry for interrupting the flow of this thread.)
In reply to Do you want my python code,… by [DELETED] 1831606
Wow! Well, if it's possible I'd like to see Python and the output in MusicXML, so to be able to reimplement (oh, well, maybe cannibalize :) )
Thanks a lot
In reply to Wow! Well, if it's possible… by Andrea Valle
Sure, send me a pm with an email. My code doesn't cover the whole music xml language, just what I needed, but you can build on it. I assume you know how to use xml.etree in Python (the ElementTree system)?
In reply to Sure, send me a pm with an… by [DELETED] 1831606
.
In reply to Without knowing more about… by Marc Sabatella
This does sound like a good solution and could well suit the OP.
Hola Andrea,
Did you solve your problem? I do not know if we have the same idea. I would like to generate a mscx outside musescore. For instance from Python, R, Mathematica or other similar computation environment. Environments where I can develop programs for automatic composition. Do we have the same situation? Did you solve your doubts? Thanks for your time. Eduardo Uresti
In reply to Hola Andrea, Did you solve… by eduardo.uresti
You can certainly generate MSCX files programmatically, at least for MS3.6.2 since the format is now fixed. I use Excel with VBA to inspect and modify MSCX scores as an alternative to plugins, which can be useful when an element is not available via the plugin API.
MS4 should be possible too but I'm not familiar with the format.
In reply to You can certainly generate… by yonah_ag
Can you help me to do my first step in such direction? Please!
In reply to Can you help me to do my… by eduardo.uresti
First step is to understand the mscx format. Do you have Excel? It's not needed but my Excel tool will let you explore mscx files easily. If not then any XML viewer will work, or Notepad++. What OS are you using?
https://github.com/yonah-ag/musescore-mscx-explorer