How to run batch convert / export?

• Apr 11, 2015 - 23:44

Hi,

I have the Batch Convert plugin installed and active, and awant to convert a folder containing a dozen or so tunes from xml to mscz.

The plugin seems to work - I click it, tell it 'from - xml' and 'to - mscz', there are no sub-folders so I leave that blank, tell it where the folder with my xml files are - on my DropBox - click 'Select folder' and then...........

.... nothing seems to happen. I don't get a dialogue box saying which files have been converted and, as far as I can see, no new fmscz files have ben creaed - certainly not where I was expecting them - into the source folder or anywhere else.

I've run it with and without a score open in MuseScore 2, and get the same result both times.

Has anyone any ideas?

Cheers


Comments

In reply to by Jojo-Schmitz

Thanks so much for that exceptionally quick reply!

One PS - I was super-efficient yesterday and, when I realised I had both 1.3 and 2.0 installed I removed 1.3. Drat! Any ideas where I can find a 1.3 download? [When I go to the MuseScore site and click the 'download 1.3' button it looks as if it's downloading 2.0].

Regards

In reply to by Jojo-Schmitz

I did some investigation here, and this is what I found:

  • A plugin cannot save a score. The method writeScore calls MuseScoreCore::saveAs which (as defined in musescoreCore.h line 36) will always fail.
  • A plugin cannot close a score. When converting a lot of scores (i.e. first reading them with readScore), we'd end up with a lot of open score windows.

If these two problems were fixed, I think there should be no more major problems to create a plugin (at least one that does not traverse folders) because, although there's no really nice way of reading directories in qml, it can be done.

In reply to by heuchi

That is pretty bad. A pretty bad regression from 1.x, reg. close score see also #13301: Need means for closing a score from the plugin framework, made available in 1.2. Now reported again in #56221: Can't close a score from within a plugin.

But not being able to save a score is the real killer. Now reported in #56216: Can't save a score from within a plugin.
Why doesn't MuseScoreCore::writeScore() just use MuseScore::saveAs() rather then MuseScoreCore::saveAs()? It uses the same parameters.

And I though getting a decent GUI would have been the biggest (and meanwhile solved) problem.

FWIW, I think a better approach that a plugin is to have a batch file or shell script. There is nothing to conversion that really requires the full MuseScore interface and access to the plugin framework. "mscore foo.mscz -o foo.xml" does the conversion just fine. So a simple script that lets you select a bunch of files in your file manager (eg, Explorer on Windows, or Finder on Mac) and drag & drop them to the conversion program would do the job nicely for much less effort, I think.

#56216: Can't save a score from within a plugin and #56221: Can't close a score from within a plugin beeing fixed, I added back the calls to actually read, write and close the scores. So it seems to work on my Linux machine.
Please do some testing (on other platforms as well), to see if we got the main algorithm correctly.
Note: Testing is only possible using the current development version. It won't work with the v2.0 release.

TODO:

We still lack a dialog window showing we're actually doing something. This might come handy when converting a lot of files, which might take some time. We'd also need an 'abort' button.
I'm also not happy with using the pluginType: "dialog" property, because the dialog window appears somewhere on the screen (not centered) and is not modal. So the user might easily overlook it.

Two more things to be improved in the MuseScore core:

  1. closeScore() will ask the user if they want to save the changes, if a score has been loaded, that was created with v1.x. We'd need a way to tell closeScore() to not ask, but close anyway (since we know we didn't change anything).
  2. readScore() will open a dialog when it detects broken scores. I don't know how to handle this in our case. Just opening the file anyway would be the easiest way, because the user cannot do any editing during batch convert. Or we could show a message ourselves, saying that due to problems opening the score, we don't convert automatically.

We also need some more error checking in the plugin if a score fails to read.

Just found one more thing: Every score the plugin reads, gets listed in the File->Open Recent menu. We probably don't want this.

In reply to by Jojo-Schmitz

I created a new branch with a modified version:

  • It now doesn't use pluginType: "dialog", but uses its own dialog window. This also allows for to set the title of the dialog window.
  • It uses a dialog window to show progress and another timer to give back control to qt, so we get the dialog window updated.

About your remarks:

  • It does overwrite files here.
  • It will process all files, because I first wanted to have the core functionality before trying optimizations. Anyway: It's going to be tricky to implement this feature, because the modified time field of a file can only be retrieved in human readable form in QML...
  • I removed a possible cause for a crash (calling closeScore() with a null pointer). But it didn't crash here, so I'd need some more information on this.

It still has a (major) problem when opening files other than .mscz (e.g. midi), because on closing such a file, a dialog will pop up, asking if one wants to discard the changes made. This basically kills a batch converter, since the user will have to click once for every file processed.

In reply to by Jojo-Schmitz

We now have a version that should work as good as the current plugin API supports.
It only works using the latest MuseScore development version and can be downloaded here.

Known limitations

  1. If there's a file created with MuseScore v1.x or a file of any other type than .mscz or .mscx, then a dialog window will appear when the plugin tries to close the score, asking if you want to discard the changes.
  2. Every score found in the working folder will be loaded and therefore be listed in the "Recent Files" menu entry.
  3. If you export to .wav, the "Abort" button won't work while MuscScore actually writes the wav file.

I hope there are no more crashes or other problems.

If this works well, I'll try to create a pull request to overcome issues number 1 and 2.
I don't know what can be done for number 3.

I couldn't get the conversion plugin to work either, so here is something for Linux which is quick and dirty but it works..... Warning!!! It will overwrite existing files with the target extension!!!

Change the directory and extensions to your preferences, then save it into the directory where your files are as batchconvert.py and make the file's properties executable. Double-click on it and select "Run in terminal".

Attachment Size
batchconvert.txt 821 bytes

In reply to by heuchi

Heuchi
Nothing happens atall. I'm using Linux Ubuntu 15.10 MATE with MuseScore 2.0.2, the plugin is Jojo-Schmitz-batch_export-a71e138 which shows as batch_convert in the Plugin Manager. It was from the Musecore website somewhere, I would check, but I can't find the plugins again - they don't show when you use Search!
Chris

Attachment Size
Screenshot.png 222.61 KB

In reply to by ChrisOfBristol

Looks like you're using the latest plugin version.
Do other plugins, that require graphical dialogs work? (e.g. "Break every X measures")?

Can you invoke musescore in a shell and see if you get anything like this:

   line 2: module "QtQuick.Controls" is not installed
   line 3: module "QtQuick.Layouts" is not installed

There have been some problems reported using the ppa version of musescore and I don't know if these are actually fixed for your distribution.

In reply to by heuchi

"Do other plugins...work?"
The sample plugin called 'helloqml' sort of works. It displays a window which says "Hello Qml" if you define a shortcut and type it, but nothing happens if you click on it.

"Can you invoke musescore in a shell"
chris@HPC:/$ mscore
initScoreFonts 0xb317be0
init Help from:
cannot setup data for help engine: Cannot open collection file: /usr/share/mscore-2.0/manual/doc_en_GB.qhc
chris@HPC:/$

"There have been some problems reported using the ppa version of musescore"
This was directly from the distribution's "App Grid".

I'm afraid I'm unlikely to pursue this topic:
The Editor is terrible! It only allows formatting by typing HTML tags. What is worse is that I keep getting the "You have exceeded the maximum number of posts you can make." I have made about 5 posts!

In reply to by heuchi

"Do other plugins...work?"
The sample plugin called 'helloqml' sort of works. It displays a window which says "Hello Qml" if you define a shortcut and type it, but nothing happens if you double-click on it.

"Can you invoke musescore in a shell"
chris@HPC:/$ mscore
initScoreFonts 0xb317be0
init Help from:
cannot setup data for help engine: Cannot open collection file: /usr/share/mscore-2.0/manual/doc_en_GB.qhc
chris@HPC:/$

"There have been some problems reported using the ppa version of musescore"
MuseScore was installed directly from the distribution's "App Grid".

I'm afraid I'm unlikely to pursue this topic.The Editor is terrible! It only allows formatting by typing HTML tags. What is worse is that I keep getting the "You have exceeded the maximum number of posts you can make." error. I have made about 5 posts! It means my posts error so I have to save them elsewhere, then wait a while before I can make another attempt to post them.

It only took half an hour to write the Python script, which is a lot less bother :)

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