LibreOffice / MuseScore Example Manager update coming

• May 2, 2015 - 21:53

Some of you may be aware of the "MuseScore Example Manager" extension I created for LibreOffice, to simplify the task of inserting musical examples into text documents. If not, you couldn't be faulted for not checking it out, as installing and configuring it was kind of a pain. I am in the process of updating this for MuseScore 2.0, and I should be able to get the set up to work more seamlessly. Actually *using* the extension was always very smooth, and that won't be changing :-). See http://extensions.libreoffice.org/extension-center/musescore-example-ma….

I will be looking for people to help test my update, so I will post a version of the extension here soon. But first, I am trying to understand some things about how MuseScore (and other applications) are typically installed on different systems. One of the things I want to do is make a better guess at the default location for the MuseScore executable, and if the guess is good, don't bother asking the user where he installed it.

My impression is that for Windows, the normal location for the MuseScore 2.0 executable is:

C:\Program Files (x86)\MuseScore 2\bin\MuseScore.exe

For Mac, I really have no idea; the whole "application bundle thing" is confusing to me. Is there a single default pathname I can assume this will be installed to by default?

For Linux, I imagine this is up to the package maintainer. Is "/opt/MuseScore2/bin/mscore" a typical location for the actual executable?

In all cases, if I find MuseScore in the expected place, no user intervention should be required. It also will no longer be necessary to install ImageMagick or GraphicsMagick. Only the ABC conversion features - which I suspect are of interest to hardly anyone except me - would still require user intervention to set up.

I do plan on taking this all another step or two in the future, but for now, the focus is on updating for 2.0 and simplifying the set up.


Comments

On Mac you can assume the mscore binary is at

/Applications/MuseScore\ 2.app/Contents/MacOS/mscore

On Linux you can probably assume it's in the $PATH and so just calling mscore or musescore(?) should work. You could just try to run mscore -v to check.

As far as I can see from the packages at ppa:mscore-ubuntu/mscore-stable they seem to install it as "/usr/bin/mscore". My self-compiled version is at "/usr/local/bin/mscore".

Would passing it to the "env" command be an option?

/usr/bin/env mscore <mscore-options>

If you want to know the location, instead of calling it via "env", you could also try

/usr/bin/which mscore

which returns the full path of mscore (if which is in /usr/bin, of course).

In reply to by heuchi

I can confirm that the default locations on Ubuntu are "/usr/bin/mscore" for full releases (e.g. 2.0), and "/usr/local/bin/mscore" for self-compiled development builds. (On Ubuntu, full releases can also be run from "/usr/bin/musescore", as this symlinks to "/usr/bin/mscore".)

It is important to note that "/usr/local/bin/" is listed before "/usr/bin/" in $PATH. You can find the location on Linux using

which mscore

BUT if a development build is installed then this will tell you the location of the development build, not 2.0. The appropriate command to find 2.0 is

which musescore

, or

which -a mscore

(this lists all mscore executables in $PATH instead of just the first one, you could then ask the user to choose the appropriate one).

Another consequence of the $PATH problem is compiling a development build renders the official release of 2.0 unusable.

In reply to by shoogle

I was afraid it would end up being messy. What I have for now is, I check the "expected" location - and for Linux, that is /usr/bin/mscore. If it exists, I use it. If not, I prompt the user for the actual location. Whatever answer he gives gets saved in an INI file and is used next time.

So this will always find /usr/bin/mscore in preference to /usr/local/bin/mscore when both are present, unless you hand-edit the INI file to tell MuseScore to use the local version instead. Ultimately, this should be an options dialog within LibreOffice, and I see there is support in the framework for this. There's a pretty big learning curve for this stuff, though.

I'm also struggling to get the packaging working right. I'd love to add a MuseScore button to the toolbar, with an actual icon, but can't figure this out. The code itself is all working, but if there is someone with experience doing LibreOffice / OpenOffice extensions who wants to help, I'd really appreciate it...

In reply to by Marc Sabatella

I have coding experience, but not with LibreOffice extensions. I would be interested in this extension, and potentially assisting in its development, because I am interested in using MuseScore to create a modern typeset version of an out-of-copyright opera for IMSLP. (I've already done this in LaTeX by inserting music with \importPDF.) Would you consider putting the extension on GitHub or similar, or would you be wary of possibly having to manage hundreds of pull requests?

BTW, the $PATH problem could be solved by using different names for MuseScore development executables (e.g. "mscore" or "mscoredev") and full release executables (e.g. "musescore"). Is this something the developers would consider, or would it be too messy?

In reply to by shoogle

I'm fine with putting the code on GitHub, but I'm not sure how exactly that is done with respect to a LibreOffice extension. Those sort of packaging issues are what I am trying to get help with :-)

I have no opinion right now on the executable name. I personally would solve it for myself, if I were concerned, by installing to somewhere that is *not* in my path, and in fact, that's exactly what I am doing right now.

In reply to by Marc Sabatella

I've seen Chrome extensions and mobile apps hosted on GitHub, so it should be possible. If you just upload the code and include a README with instructions (or a link to instructions elsewhere) saying how to get it up-and-running that would be helpful too. But if you're not sure how to get it to run on other people's systems then you could always create a blank README placeholder and let others write it via pull requests.

It might even be possible to automate the setup process with a shell script. I have an SVN repository with code designed to be run on a Raspberry Pi. I want to be able to edit the code on a normal computer, so the repository has two directories. The first directory contains code for the Pi and the second contains code for a normal PC that automatically transfers the Pi code to the Pi when requested. So after editing the Pi code I run "send-to-pi" instead of the usual "make && make install".

I hadn't thought of installing the development builds to a non-standard location. You would lose the ability to start it via the Unity launcher, but perhaps that's not a big problem for a development build. I currently achieve compatibility by manually editing the ".desktop" file for 2.0 to point to "musescore" instead of "mscore". This approach does allow both 2.0 and development builds to be run from the Unity launcher.

I have an initial cut at this hosted on github:

https://github.com/MarcSabatella/MuseScoreExampleManager

I am using Extension Compiler to package this as an extension (.oxt) file. Still sorting through the different options, but I think I have the basic hang of it. At some point it will be good to add more documentation etc. I'd also like to replace the INI file I use to store options with an actual options dialog, but the details on how to do this seem way too complex to be worth it for me. Maybe by having it on github, someone else will be able to help with that specifically.

Anyhow, here is the initial/current version of the extension itself for anyone who wants to try it:

https://github.com/MarcSabatella/MuseScoreExampleManager/blob/master/mu…

In reply to by Marc Sabatella

I can't find a way to configure the location of the executable. Since there was an error converting the mscz to png, I tried to find the INI file, but didn't find it. I looked in the code and I found the getIniUrl() function, but I couldn't find a file named .*/*.ini in my home, neither an *.ini anywhere else, that looks like it's connected to the Extension.
I'm using Kubuntu 14.04 and LibreOffice 4.2.8.2 (MuseScore is at /usr/local/bin/mscore)

In reply to by heuchi

The INI file is stored in ~/.MuseScore Example Manager/msem.ini, but it is only created "as needed", and as far as the extension can tell, it wasn't needed. So you can create it manually, and add a line "mscore=/usr/local/bin/mscore".

My guess is you have the same situation as me - /usr/bin/mscore exists, so my extension never throws up a dialog asking for help finding it, but that's the 1.3 version, so it doesn't actually work. Even if trying to insert an older score, I pass in the new "-T" option to trim the whitespace from the graphic.

My assumption is, this will only be an issue for those of us a) on Linux, b) who keep 1.3 installed, and c) are installing 2.0 into somewhere other than /usr/bin. That's probably just a few of use developers. Still, that's part of why I do hope to move to the options dialog scheme, to be able to expose this better.

Something else I could do for now is go ahead to put up the dialog asking for the location on first run anyhow, even if I find something at the location of my initial guess, just to ask for confirmation. Maybe only on Linux. It would be prepopulated with /usr/bin/mscore.

I could also run "mscore -v" and attempt to parse the output, but I was really hoping to avoid that sort of thing.

In reply to by Marc Sabatella

Thanks, shoogle, for the first PR, which I just merged. Nice cleanup of the packaging.

Heads-up - I did go ahead and change it to always ask on first run for the location of the executable - but if the guess appears to be good, the dialog asks you to "confirm" it rather than "enter" it, so it's maybe more apparent you probably just need to hit OK. But otherwise it was going to be too hard to discover how to dig yourself out if you are in the situation described earlier where the default executable exists but you'd rather use a different (presumably more recent) version you have installed in some non-default location.

I'll also update it to use a different INI file (in same folder) than the previous version, so it won't keep trying to use the 1.3 version of MuseScore if you had ever used the extension previously.

I'll test the new packaging on Linux, Windows, and Mac, and assuming all is well, I'll probably update this on the LibreOffice site soon.

I'd still like to update the code to use an options dialog rather than INI file, but that can wait.

In reply to by Marc Sabatella

It's working for some scores but not others (it gives the message "unable to convert MSCZ to PNG") but in both cases the directory containing the original MSCZ files is being filled with PNGs of the scores (and they aren't deleted even if they make it into the LibreOffice document).

Also, for some reason it doesn't prompt me for the path to mscore but it still works (even if I delete all the INI files).

But the really strange thing is that it *does* prompt for the path when it encounters a score that it doesn't like.

See examples. In both cases PNGs are produced in the directory containing the MSCZ file, but only in one case do they get added to the LibreOffice document. I can't see why it works for one and not the other (it doesn't seem to be based on the length of the score because I have longer examples that work, it even works on a score that MuseScore claims is corrupted).

Attachment Size
Working.mscz 7.59 KB
NotWorking.mscz 33.54 KB

In reply to by shoogle

Ok, so it does prompt for the mscore path with "Working.mscz" if I delete the "Working.png" (created on a previous run) from the score directory. It still doesn't import PNGs for "NotWorking.mscz" even though it successfully creates them in the directory. I assume there shouldn't be any leftover PNGs in the directory in either case?

In reply to by shoogle

Since you had earlier versions installed, you might have to uninstall as well as delete the INI files, and then close LibreOffice to clear its cache. Then try again to make sure you are seeing a clean installation. That's probably why it didn't prompt you.

As for the "unable to convert" - are you sure it was working with longer examples? Longer in what sense? I think the issue is that MuseScore appends page numebrs to the PNG files, so normally it's "Working-1.png" etc, but apparently for scores of 10 or more pages, it's "NotWorking-01.png" etc - two digital page numbers. The extension isn't really designed to work with scores of more than one page anyhow, but I could certainly add a check for this. Can you confirm that is really the issue? If I delete everything form page 10 on in your score, it works fine.

The PNG's indeed are not deleted. This allows them to be reused without being regenerated. Maybe not an important concern.

In reply to by Marc Sabatella

You're right, it works fine if it has 9 pages or fewer. I did delete the INI files before testing, but it wouldn't prompt if there were already PNGs in the directory of the MSCZ file. Once I deleted the PNGs it works properly.

I know you originally intended it to be for small snippets of music (i.e. examples), but I would have thought a more general use would be to insert any amount of music. It already does the PNG conversion for every page so it must be nearly at this point anyway.

Is there any real advantage to keeping the PNGs in the directory? It's not possible to re-insert them is it? When you click on the MuseScore icon again to update them, doesn't it just generate new ones and overwrite them all anyway?

A good feature for a future release might be an "update all" button that checks the modification date of the MSCZ files and updates any images that have changed. I might have a look into this if you are ok with it? It would be a good opportunity to understand the existing code.

In reply to by shoogle

The main advantage of keeping PNG files is performance - like if you add the example, change your mind and delete it, then add it back. Or wish to add the same example multiple times -say, a bit of blank staff for the reader to write in notes himself. The extension checks the modification date of the MSCZ versus the PNG and just reinserts that PNG if it's up to date. I have also toyed with not embedding the PNG in the document but storing a link.

"Update all" is definitely on my list of future enhancements I'd like to see happen, and I'd be thrilled to have someone else look at it! The complication, I think, is that currently there really is no special way to know that any particular image came from MuseScore. I'm sure that's solvable, though. The fact that the code already exists to only regenerate PNG's when necessary could be nice to leverage here.

If you want to see about tweaking the extension to handle multi-page scores, feel free. It's kind of outside the scope of what I intended this for, but if you have a use case that makes it worth supporting, have a ball! A complication here would be that it would presumably have to be inserted as a series of separate PNG files, and they'd all have to link back to the same MSCZ file, and it wouldn't be clear what should happen if you later udpate the MSCZ file and hit the "udpate" button for just one of the images.

In reply to by Marc Sabatella

Well the current version looks ready to go as it is, but I've got a few ideas for the next one:

- multiple pages
- button to update all images
- option to not store PNGs, or to store PNGs in "$HOME/.MuseScoreExampleManager" to reduce clutter in score directory
- use SVGs instead of PNGs (will probably involve parsing and editing of the SVG file exported by MuseScore to split pages and remove whitespace).

I'll start with multiple pages and see how I get on, but feel free to have a go at the others if any interest you.

In reply to by shoogle

These are all excellent ideas. I think I will promote this to release status "as is" soon, or maybe at most fix it to work with scores of >10 pages.

SVG in particular was something I had wanted to do but the whitespace-trimming in ImageMagick/GraphicsMagick was one issue, and support SVG was incomplete in LibreOffice and/or OpenOffice at the time I originally wrote this (I think it worked in one but not the other?). By now, probably SVG works in both, and as I recall the "-T" option I added to MuseScore to trim whitepsace does work with SVG.

Multi-page support will be tricky to model. The pages are completely separate separate image files, and it isn't at all clear how they should be linked together and/or with the source score. I still don't understand the use case, and suspect that if it's something like, important a whole songbook into LibreOffice in order to add headers, footers, title page, or whatever, that there really is a better solution to that problem than converting a score into potentially hundreds of separate image files that are each embedded individually.

Persnally, I rather like having the PNG's with the scores. If you do it within .MuseScore Example Manager, you'd have to reproduce the whole folder tree, or at least encode path information into the filenames to handle duplications. Maybe have separate ".MuseScore Example Manager" folders *within* each folder containing scores, or within the document folder. Seems I did that in an earleir version, but didn't care for it - I dn't like creating lots of hidden invisible files. But if it's an option, that's fine - as long as it's not the default.

As soon as we start talking about options, we *do* need to think about having an actual options dialog. I gather there is a way to create onbe with no buttns and have it invokable directly from the Extension Manager.

In reply to by Marc Sabatella

SVGs seem to work in LibreOffice, but MuseScore seems to have a few issues with SVGs:

1. Multipage MSCZs are exported as one big SVG rather than a separate image for each page.
2. I can't seem to get "-T" to work for SVGs.
3. SVGs are not optimised (the SVG file size is larger than a 300dpi PNG of the same score).
4. MuseScore doesn't support the SVGZ extension for compressed SVGs.

My intended use is to create a full vocal score for a opera. I agree that embedding images may not be the best way to do this. I did it before by using \importPDF in LaTex. This works very well and even generates a Table of Contents automatically, but it's not a graphical method so would put many people off.

In reply to by shoogle

As far as I know, the fact that multiple-page SVG's are created is normally considered a *feature*, not an issue. As for -T, what goes wrong when you try it?

As for importing a whole large score - yes, I do think importing a PDF makes more sense. Shouldn't this be supported already without the aid of an extension?

It seems to me the problems that might need to be solved to facilitate importing multi-page scores are rather different than the set of problems I was trying to solve.

BTW, I did published the version I had up as the final release. I didn't see the point of implementing a throwaway hack to handle scores >1- pages given it's still going to just import the first page only and not do at all what you were wanting.

In reply to by Marc Sabatella

I see, -T works for a single page MSCZ but not for a multiple page file.

I can see that a multipage SVG might be useful, but it would be helpful if the pages were kept in different layers or groups to allow them to be separated easily later:

<g id="page1">
     ...1st page content...
</g>
<g id="page2">
     ...2nd page content...
</g>

(BTW, thanks for the link lasconic. It looks like it could be very useful.)

In reply to by shoogle

I can't seem to find the part of the Example Manager code that creates the menu items in OpenOffice. Maybe you could point me in the right direction? How do you get "MuseScore Example" to appear under the "Insert" menu in OpenOffice? I see that the packaged version has a file called "AddonUI.xcu" that does this, but how is the "AddonUI.xcu" file itself created?

In reply to by shoogle

The menu items and button are not part of the code; that is part of the packaging performed by the msuescore.odt document. That document was created by another extension called the Extension Compiler. I entered information into that document (into some Basic macros attached to the document, actually) as directed in ths document itself, then hitting the "Compile" button generates the necessary files. It's all black magic to me, but I was happy to see it work.

In reply to by Marc Sabatella

I can't find version 2.0.0 at the extension-center link you gave. It mentions MuseScore version 2.0 is required but the latest release of the extension I see is 1.0.8
I didn't find a way to see a "release candidate".
EDIT: Oh, now I see it, not sure what happened, some cache problem maybe, although I thought I reloaded...

I install under Mint17.1 Rebecca

When installing there was an (erroneous) message claiming that it was yet installed.

I have now a Musescore and a ABC button in the main bar (at the left end)

I don't see any related menu.

I removed the older version and the INI file, installed the new version from the extension-center 'musescore-2-0-0.oxt' but was never asked to confirm the location of mscore. It didn't create a new INI file, but it works.

In reply to by heuchi

If it didn't ask your to confirm or create a new INI file, I'm guessing you were inserting an MSCZ file for which there already exists a PNG file. As I said above, the extension deliberaltely leaves the PNG file around to make it faster to add again later. Try adding an MSCZ file you *have* previously used.

It's also possible that you need to restart LibreOffice to clear its cache - it might possibly be remembering the location of MuseScore from a previous run with the older build.

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