convert a group of mscz to pdf

• Sep 7, 2011 - 15:36

hello,

is there a way to batch convert to .pdf? i have a whole bunch of .mscz files that i want to turn into pdf files. i don't want to have to go to each file and convert individually.

thanks,
ryan


Comments

You could post them on MuseScore.com. I can write a batch importer if needed.
Or you could do on the command line, for one mscz file, mscore file.mscz -o file.pdf. Depending on your operating system, you can do it for more with a script.

In reply to by [DELETED] 5

I'm using Cygnus make and a simple makefile which just uses implicit rules to generate xml- and pdf- files, could easily get extended to generate wav- and ogg-files or convert cap- into mscz-files:

# englisch Win7 64bit
MUSESCORE="/cygdrive/c/Program Files (x86)/MuseScore/bin/mscore.exe"
# german WinXP
#MUSESCORE="/cygdrive/c/Programme/MuseScore/bin/mscore.exe"
#ECHO=echo
ECHO=:

.SUFFIXES: .mscz .pdf .xml .ogg .cap

.mscz.pdf .mscz.xml .mscz.ogg .cap.mscz:
	@$(ECHO) Rule making $@ from $<
	$(MUSESCORE) -o "$@" "$<"

# All MuseScore files
SRCS := $(wildcard *.mscz) $(MSCZ)

PDFS := $(SRCS:.mscz=.pdf)
XMLS := $(SRCS:.mscz=.xml)

all: $(PDFS) $(XMLS) $(MSCZ)

Downside: blanks in filenames don't work whit this.

In reply to by [DELETED] 5

not quite
a) it generates everything whether needed (mszc newer than .pdf)
b) fom foo.mscz it generates foo.mscz.pdf rather than foo.pdf
Thanks anyway, I'd know how to do this in a shell-script for Linux, but not how in a batch file on Windows...

In reply to by [DELETED] 5

Sorry for the thread bump, but this is great info, and I'm wondering if anyone has thought about making a GUI wrapper for this?

Assuming not, and that this were something I were to want to undertake, what sort of environment might people recommend using for a very simple app like this? One of the Python GUI frameworks? Last time I did anything like this, "HyperCard" was all the rage (you younger folk may want to Google that one :-)

EDIT: maybe this is just as easily done as a plugin? looking into that now...

In reply to by Marc Sabatella

I've got something working as a plugin. Not ideal, but it works. Run the plugin, select a folder, it finds all MSCZ files without a corresponding PDF, or for which the PDF file is out of date, and loads the MSCZ files then saves as a PDF. Seemed more elegant than trying to invoke a MuseScore (via command line) from within MuseScore - plus I'd have had to worry about the path to the executable. Main drawback of my approach is that the scores loaded via the plugin cannot be closed automatically.

I've attached the preliminary version of the plugin; if anyone wants to give feedback before I post it for real, feel free.

Attachment Size
batch_pdf.zip 1.16 KB

In reply to by Marc Sabatella

Excelent idea! And it works quite well too, but:

  • if I open MuseScore, but do not open any Score, I can't select any of the plugins, so I need to open a dummy score first. While most plugins work on already open scores, some don't, this and the ABC plugin are examples
  • Every converted scores not only gets open and not closed again, as you mentioned, it also opens as 'unknown' (resp. 'unbekannt'), however, if I save it (not 'save as', just 'save', it 'remembers' its name? Is that possibly just another symptom for the 'not close' problem?
  • it should be more verbose about what it is doing (well, currently it is absolute silent if nothing is to be done and only opens the scores that had to be converted, without any other indication). How about an alert box "converted scores" or some such? See attchament.
  • maybe it could get extended to also pick up .mscx files?

I've created #13301: Need means for closing a score from the plugin framework

Attachment Size
batch_pdf.zip 1.24 KB

In reply to by Jojo-Schmitz

Thanks, I agree, close would be good, as would enabling the Plugins menu even with no score open.

For debugging purposes, I did originally have a dialog pop up telling me which scores were being converted. I considered leaving that in, but then I realized it was obvious enough which scores were being converted because the scores weren't being closed :-). So I figured the scores themselves served as their own status alerts, and having to hit OK to close a dialog is just adding to the pain of needing to close all the tabs for the newly opened scores. Would be better if they showed their names, though, I agree. I note the score.name field doesn't actually appear to work, and that's probably related.

In hindsight, these limitations are such that doing this as a standalone utility would probably have been better, but what the heck, this is already done, and I can live with its limitations.

Oh, most bothersome to me - no way to specificy a reasonable initial folder. I'd love it to be the folder the user specified as the default score location in Preferences, but there's not a way to get at it that I know of. I did manage to (accidentally) stumble on a simple way to make it remember the specified folder between invocations, though.

In reply to by [DELETED] 5

So this should work?

    if ((mscoreMajorVersion == 1 && mscoreMinorVersion >= 2) || mscoreMajorVersion > 1) {
      theScore.close(); // no close() method in earlier versions
    }

and score.title is really the title, not the lable on the tab, which reads "unknown" rather than the plain filename

In reply to by [DELETED] 5

Ah, very clever

I'm not really familiar with JavaScript, much more with C

Remaining problem: loading a score with score.load() leaves the tab being intialized with the word "unknown" rather that the filename (without path and extension) as it would when opening a score via the menu.
Bug?

In reply to by [DELETED] 5

Great! Dumb question, but what is score.name supposed to be for? idoesn't seem to contain anything that I can tell. I had once tried to write a plugin to export the current score as a PDF with the same base name (slightly easier than Save As and changing file type), but couldn't et at the filename of the current score - that's what I expected to find in score.name.

EDIT: It's coming back to me now. "name" is no longer documented (looks like it was plled a few months ago), as apparently it never worked.

In reply to by [DELETED] 5

Very good.
But there's still another issue: the plugins menu is not selectable as long as no score is open.
Some other menus are selectable where it doesn't make any sense are selectable though: File -> Save online and Edit -> Voices (but not the submenu after that)

Marc: are you going to submit this plugin to the plugins page?

In reply to by Marc Sabatella

Great stuff, thanks.
Could that possibly get extended to export other formats too? Like xml, ogg, well actually everything the "Save As" allows for? Maybe having a set of tick boxes for all the different formats in the 'select directory' dialog, PDF being ticked by default? Of course it'd be possible to create different plugins for every format out there, but that would be unneccessary code duplication to me.
I have no idea though how to code such a format selection screen, everything after that should be fairly simple?

Furthermore: there's a bug(let): if you don't select a score (i.e. hit cancel in the "select directory" dialog) it (rightfully) gives an warning message "No folder selected", but after that if gives another message "All files up to date". A simple "return;" right after that 1st message fixes this.

As a first step I've removed all references to PDF and modified so that changing the to be exported file type only needs to be done in one place (currently "pdf", actually an array with only one member, changing that to "pdf","xml" is just enough for me right now), and fixed above mentioned buglet.

Attachment Size
batch_export.zip 1.53 KB

In reply to by Jojo-Schmitz

More great ideas, thanks! Would you like me to add you as a maintainer so you can add improvements yourself?

I did think about extending this to other formats, but I didn't want to mess with the simplicity of the experience for the user. If I knew how to create a dialog that had the folder selection widget and checkboxes for format together in the same place, that wouldbe good, but as it is, the only way I'd know how is to introduce another dialog. i guess that's not the end of the world if it defaults to PDF, but I'm still very clumsy working with Qt GUI components, so this would be more work than I thought it was worth.

Ome reason I didn't comsider it important is that batch PDF export is going to be far more common than batch audio export, at least for me. The most common situatuion is a folder containining an ensemble score with a bunch of parts, and I want PDF's of all the parts to distribute to the players. The only audio file I'd ever want in that situation would be for the whole score. I also have a folder full of lead sheets, and could see wanting them converted to PDF as a batch - but again, not very likely for audio, since audio for lead sheets is not normally meaningful. MusicXML wasn't even on my radar, but probably should have been.

So since batch export of audio is not something that is likely to come up for me, I didn't want to complicate the export plugin (both as a programmer and as a user) just to accomodate that possibility. I do like the idea of parameterizing the output format in the code to make it easier to create a new version of the plugin for another format, though. And if someone else wants to design a nice UI and the supporting code to allow selection of format, I'm happy to check that in.

In reply to by Marc Sabatella

Yep, I'm fine with becoming maintainer of that plugin. And I agree PDF should be the default export format, as the most commonly needed one.
I'd need to have a deep look into how UI programming works with QT...
Need to look into that github thing too ;-)

Found another bug:

if (typeof theScore.close === 'function') { // does not exist on some systems

On '=' too many.

In reply to by Jojo-Schmitz

=== is fine. See https://developer.mozilla.org/en/JavaScript/Reference/Operators/Compari…
typeof sends back a string so it's ok.

Btw, it's Qt and not QT. Designing interface is quite easy, just install the Qt SDK or Qt Creator and there is a visual tool to create *.ui file. These UI files can be loaded in a plugin. Check the "Break every X measures" for a simple example. Communication between UI and the code is done with slots and signals. Look for connect in the code of the plugin to see how to connect a signal with a slot.

In reply to by Jojo-Schmitz

Ok, you're in now as co-maintainer. Feel free to make any of the changes you like.

Btw, I used the === because that's how it showed up up in the "typeof" sample code I found online. I hadn't seen it before, either. I realized == should probably work as well, but given this was code I couldn't fully test, I wasn't taking any chances.

In reply to by Marc Sabatella

Thanks. Most probably I won't find the time until after my vacation, so I'll have a look after Nov 5th...

Edit: I couldn't stop myself from doing it now ;-). Fixed the buglett and also have the code in place to enable exporting multiple formats. No GUI yet though..

In reply to by Jojo-Schmitz

Cool! A quick check shows no obvious problems, but I do have a few observations:

Why radio buttons rather than checkboxes for input format? Seems it should be perfectly possible to handle multiple input formats as well as multiple output formats, no?

I'd recommend putting PDF at or close to the top of the export list - it would make the fact that it is already selected by default more obvious.

As an eventual enhancement, the folder selection dialog could be configured with a filter to show files of the selected input (or input & output) formats only? I don't know how useful that would be in real life, but it would have come in handy as I was testing it, looking for folders that had particular types of files in them to select for testing.

In reply to by Marc Sabatella

Changing the radioButtons to checkBoxes is what I have on my ToDo list already (also grouping them, e.g one checkbox for all 3 MuseScore formats, similar for MIDI), but this could get tricky, e.g. what to do if I select *.mscz and *.mscx as the inFormats and there is a foo.mscz and a foo.mscx, which to take to convert into outFormats? First come, first serve? Which one of the two to take to check wheter any of the outFormats is out-of date?
Another problem I see (and like to be fixed) with multiple outFormats is that it should be sufficient to open the inFile only once, currently it is opened outFormat.length times. Esp. an issue with 1.1, which keeps them all open.
So I have to think about these issues a bit more...

The order on the dialog is derived from how MuseScore's open/save dialogs show them, I'd rather keep it that way.

I like the idea of filtering the folder select dialog to inFormat and possibly outFormts, will look into this.
[edit] Unfortunatly QFileDialog.getExistingDirectory() doesn't have this property , at least I wasn't able to find it?

Another issue I'd need to fix is that while the form is at display, I'd need to disable (and uncheck) an outFormats checkBox if the same format is being selected as inFormat and enable it again when another inFormat get's selected. No idea how to that though? Currently I ignore these in the scipt, but that ain't nice, GUI wise.

And another one: some inFormat come in lower and upper case (BB files, *.mgu and *.sgu vs *.MGU and *.SGU), would I need both in the selection? Not in Windows, I think, if I remember correctly no Windows file system (FAT, NTFS) is case sensitive, but how about Linux and Mac?

In reply to by Jojo-Schmitz

I had seen a Filter method on the file dialog class itself, although I haven't tried it so I don't know how it works.

I see your point about possible conflicts if you allow multiple input formats. My instinct is to not worry about it and just let the results be undefined. I'd expect it to not crash, but would imagine both files would get converted, with one output file overwriting the other.

I also understand the order listed in the dialog (although now I wonder why it is like that in open and save), but still wonder if something couldn't be done to make the current selection more obvious. Can the labels for the currently selected items be made bold? Not terribly important, of course.

In reply to by Marc Sabatella

I can set inFormat *.mscz and outFormats *.pdf bold and have a button 'reset to defaults'.
I have not been able to toggle the boldness with the selection.
But I found a way to disable an outFormat if it conflicts with an inFormat.
And fixed a few bugs along the way...

Edit: now it has checkboxes for the inFormats (i.e. we can have more than one at a time) and it opens every inFile only once, even if multiple outFormats are selected. Also it now gives a porper warning if no input- or output format had been selected.

Let me know what you think about this version, as far as I'm concerned if is ready for the plugins page

Attachment Size
batch_export.zip 7.43 KB

In reply to by Jojo-Schmitz

Looks great! I guess some might question whether it's worth boldfacing the initial/default choices if you can't update the labels on the fly, but I think it is. Especially with the Reset to Defaults button - it helps identify what the defaults are. At some point I may go in add code to bold the labels on the fly (I'm pretty sure this would be possible by connecting methods to each of the checkboxes, but if I do, I'll probably add some other indicator of what the defaults are.

In reply to by Marc Sabatella

Yeah, I didn't say that changing the boldness is not possible, just that I didn't manage to find how...
Found a minor issue meanwhile (the 'reset' button became the default button after first use), the final version will have that fixed, of course.
Would be nice to have some more translations available though, spanish and french maybe, lasconic?

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