MuseScore 3.3: Plugin API Update
A brief list of new features in plugins API in MuseScore 3.3:
- Expose
Align
enumeration. Can be used to assign values to text alignment properties of elements (align
,beginTextAlign
etc., seeElement
type documentation). - Expose note play events:
- Add
PlayEvent
type - Add
Note.playEvents
property. Play events can be read from this list. This is a writable list so events can also be appended withpush()
function and removed by clearing a list (n.playEvents = []
). See list QML type documentation. - Add
Chord.playEventType
property which controls whether play events are generated automatically by MuseScore or fully controlled by a user (or a plugin). Usually this property is assigned automatically, assign it manually toPlayEventType.Auto
to make play events be reset by MuseScore later.
- Add
- Adding and removing elements:
- Add
Chord.add()
andChord.remove()
functions. They were available in MuseScore 2 and allow to add individual notes and other elements to existing chords. - Add
removeElement()
function. - Add support for more types to Cursor.add() function (commit)
- Add
- Expose list of selected elements to plugins:
- Add
Score.selection
property - Add
Selection
type providing a read-only access to the list of selected elements.
- Add
- Restore some properties available in MuseScore 2 (and add some new ones):
- Add
Element.parent
property. - Add
Element.posX
andElement.posY
read-only properties providing an information about an element position. - Add
Note.tieBack
,Note.tieForward
,Note.firstTiedNote
,Note.lastTiedNote
properties and Tie type.
- Add
- Comparing variables:
- Add
ScoreElement.is()
andExcerpt.is()
functions. They allow to check whether different plugin objects correspond to the same internal MuseScore object which is not currently possible to determine correctly with==
or===
operators.
- Add
- Notifying plugins of score changes:
- [Experimental] Add onScoreStateChanged handler. Mostly useful for plugins that are supposed to be used interactively (like "dock" type plugins). See the documentation for usage example.
Comments
Glad to see plugin API evolving further, even adding some of the yet missing MuseScore 2 properties. Alas parts[].volume has not made its way into MuseScore 3 yet (see https://musescore.org/en/node/294183) :-(
This is (AFAIC) the last missing piece for me to be able to switch to (the highly appreciated) MuseScore 3 version...
Is there any way I can get the same results (meaning: setting volume for mp3 export separately per part)?
Thanks for all the effort all of you are putting into MuseScore!
In reply to Glad to see plugin API… by msmb
Thanks for your response!
The issue with exposing part volume is that a part can contain instrument changes anywhere in the middle of a score so exposing this property in a way that was used in MuseScore 2 would not really be complete and would not correspond to the way in which instruments and channels are manipulated in MuseScore code internally. Actually, looking briefly at MuseScore 2 code, it looks like setting a part volume from a plugin should also be incomplete as this would probably work incorrectly for instruments which use multiple MIDI channels (like violin for pizzicato and tremolo effects or some brass instruments for playing with a mute) and does not allow handling instrument changes. So exposing these properties probably requires exposing some parts of functionality of instruments data structures which is possible, of course, but still requires some effort.
As far as I know, there is no other way to set a part volume for mp3 export except for using a mixer manually (which is probably what you want to avoid here).
Still this functionality should probably return to MuseScore 3 plugins some day. Maybe you could also create a feature request in the issue tracker, then it would be easier to keep track of this issue.
In reply to Thanks for your response!… by dmitrio95
Hi dmitrios95, thank you for your reply!
I'm using this feature to generate mp3 files as study files for our choir, so the "instruments" are voices only in this case (soprano, alto, ...). In my little plugin I loop over all voices, exporting a mp3 file for each voice, having the current voice set to 100% volume, the other dimmed to 50% volume. I could do this manually, but it is very time consuming when exporting an eight voices sheet, probably several time throughout the process, so I really would like to avoid that. Getting this feature back would be highly appreciated and actually the last missing piece for me to switch to MuseScore 3 - currently I'm still sticking to MuseScore 2 because of this.
I've created a feature request in the forum: https://musescore.org/en/node/294183
Any chance for example code for adding (a few) chords to a score? I tried what seemed most straightforward https://musescore.org/en/node/296447 but failed, and I could not find hints to it in the API documentation; I attempted to follow the logic on the C/C++ side, but I gave up. Thank you in advance. (If this functionality is currently missing on the C/C++ side, pointers on how to implement it are welcome.)
In reply to Any chance for example code… by HuBandiT
Sorry for being so late with the answer, but starting from version 3.3.4 Cursor type gained an ability to add notes to existing chords (see
addToChord
parameter inaddNote
function). That should make adding chords easier so something like this should work:In reply to Sorry for being so late with… by dmitrio95
I didn't know that the cursor could address (as opposed to present an array of) chords. What is the "current chord" in this context? How to you get or set it?
In reply to I didn't know that the… by [DELETED] 1831606
Not many people are going to enjoy using plugins if (on the Mac) trying to assign a shortcut effectively crashes MuseScore. Please take a look if you know what's involved.
In reply to Not many people are going to… by [DELETED] 1831606
I didn't know about that crash, and I don't see anything like this in the issue tracker. I'll check that when I am able to test this on Mac.
In reply to I didn't know about that… by dmitrio95
Is that something you have reported in #298216: 3.3.4 MacOS: Can't quit Plugin Manager dialog?
In reply to Is that something you have… by dmitrio95
Verily, one and the same!
In reply to I didn't know that the… by [DELETED] 1831606
Current means that it belongs to a segment where cursor currently is. It can be positioned using
Cursor.next()
orCursor.prev()
, or shifts itself when usingCursor.addNote()
. Most of Cursor API in plugins actually reuses the implementation of note input in MuseScore so it should behave mostly the same as normal note input cursor.In reply to Current means that it… by dmitrio95
I guess in one voice, a segment only contains one chord.
In reply to I guess in one voice, a… by [DELETED] 1831606
Yes, there is always one chord per voice per segment. And you can choose which voice Cursor iterates over by assigning its
voice
ortrack
property.In reply to Sorry for being so late with… by dmitrio95
Thank you sir, this works now indeed!