How to write a plugin for Musescore 4?

• Dec 30, 2022 - 12:49

First of all I'm aware that writeScore() is not working on Musescore4.0 for the time being.
However
I created a directory called "export_midi"

so "....blablabla... Documents\MuseScore4\Plugins\export_midi"

Inside it I put a png called "midi_export.png" and a "qml" file called "export_midi.qml"

This qml file contains these lines (I used the existent plugins to try to follow them and to get sume hint)

  import QtQuick 2.2
  import MuseScore 3.0

  MuseScore {
          version: "2.0"
          title: "MIDI Exporter"
      description: "Export MIDI for REAPER"
      categoryCode: "composing-arranging-tools"
            thumbnailName: "midi_export.png"

  MessageDialog {
             id: versionError
              visible: false
              title: "Unsupported MuseScore Version"
              text: "This plugin needs MuseScore v3.0.5 or higher"
              onAccepted: { quit() }
  }

onRun{
    var s = curScore;
    var p = curScore.path;
        p = p.slice(0, -5);
        p = p.replace(/\//gi,"\\");
        writeScore(s, p, 'mid');

        curScore.endCmd();

        quit();
      }
  }

When I run Musescore 4 it doesn't detect this plugin.
So I thought it was for the function writeScore() then I commented that line, and restarted Musescore.
But the plugin doesn't pop-up. It's not listed, is not anywhere

I tried to move the whole directory "export_midi" into the main plugin folder of Musescore 4 having the same result: no detection.

What am I missing please?

EDIT

I corrected it implementing the first 3 suggestions I received in the comments. But the plugin doesn't show up. Even commenting or deleting the line writeScore(s, p, 'mid');


Comments

run Musescore from command line and You will get some messages.

"var p = curScore path;" is problem. missing dot? "var p = curScore.path;"

In reply to by duresport

don't use it. The plugin folder you have to use is the one on Edit > Preferences > General > Folders
I did use the native folder just to be sure about my code. NOthing else.
Not that's working (I mean: now that MU4.0 is showing up my plugin into the list and I'm able to activate it) I transferred that code into the above directory and it works.

In reply to by sammik

I added that line but without being successful.

Just to be sure:

I tried with the folder "export_midi" where teh qml and png files are located, on the folder indicated by Preferences > Folders as well as on the root folder C:\Program Files\MuseScore 4\plugins

In both cases: Musescore doesn't show the plugin up

In reply to by parkingb

I will certainly read the link you shared. thank you for that.
With "it doesn't show up" it means that not only I don't see it into the list of the plugins, but also from the menu, I don't see its name. So how can I"call" it? I'm supposed to start iit manually via a click or even a button from within Musescore

In reply to by sammik

It was not showing up.

What I did now, in order to spot any error from my side, is to copy and paste (a duplicate ) of a simple working plugin.
I changed the names of the pasted folder and the files inside.
I edited it and line by line copied and pasted it from my plugin to the working one,

I wanted to see what was blocking mine.
but all the pasted lines are working. And the "new" plugin is visible.
I still don't know what's causing the real mine one do not be visible.

I even counted the spaces for the ident of each line to be sure is not depending about such thing (like in Fortran :-D )

In reply to by tormyvancool

> It was working on MS3.6
:-/ It must be "It is working on MS3.6".

This is your sole chance of having it working under MU4.0 : A MU3.6-compatible plugin on which you applied the guidelines. If it doesn't work like that, there are little chances that it works on MU4.0.

As for your request about a Plugin API documentation for MU4.x, you must understand that most of the plugin stuff has been out-of-scope of MU4.0. So the best Plugin API documentation around is the one of 3.5 (*) - but nothing prevents you from generating it from the source code.

What puzzles me is why you stick so hard to MU4.0 ? Is your script for your own usage ?
I'm asking because writeScore DOES NOT WORK in MU4.0. So how hard you are trying, your plugin will not work in MU4.0

(*) you'll notice the doc hasn't been even generated for 3.6

In reply to by parkingb

When the script will work as it should I will share it.
Yes as I said in the beginning, I know that writeScore is not any-longer in use.
I want that script ready for when there will be the writeScore back or a similar function.
The goal of the script, is to export the MIDI file of the score.
Now, today i was able to make it visible from MU4.0 and it works (with the exception the writeScore line.
I will wait for the 4.1, mean while I will use the version 3.6 to work.

In reply to by tormyvancool

> When the script will work as it should I will share it.
The advantage of sharing it now (even in some limited-audience way) is that we could have a look at it and help you improving it.

But anyway, this is a really trivial plugin. So here you are:
https://gist.github.com/lgvr123/da646ab7bbaafbabf7d6e4379305dadf

Your plugin working in MU3.6, appearing in MU4.0 plugins list and plugins menu once enabled:
exportReaper_PluginList.png
exportReaper_Menu.png

In reply to by tormyvancool

I've made a pull request on your repo with a working version.
I've commented out everything that was not necessary (e.g. import FileIO, startCmd(), ...) and what was not supported by MU3.6 (e.g. the quit())

That version appears in the plugins panel:
exportReaper_PluginList.png
And is working (at least opening the DONE dialog box)
exportReaper_Output.png

However one can observe that the plugin is not able to retrieve the score path, which is similar to what one can observe in other plugins ported to MU4.0: the lack/poor support of the score objects.

And interesting test to do is to uncomment the import FileIO. I guess this line might cause your plugin not to appear in the plugin manager. If this would be the case it worths being added as a new issue.

In reply to by parkingb

Hi @parkingb, I merged it.

Well I was able to make it visible yesterday. I described what I did. inexplicably: it was visibile, so from yesterday on I tried to do something. but without anything great since to save/export MIDI is not possible in MU4.0
I tried to use FileIO, startCmd() to verify if there was a kind of workaround but there isn't any.

I noticed also that .slice() and .replace() they don't work. Or so it seems (perhaps because it is undefined?). Hence I commented them

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