"explode" measure by measure

• Aug 1, 2020 - 04:13

Love the explode tool in MuseScore. Is there a way to use this in a plugin?

I noticed that I am manually exploding chords measure by measure and it's getting quite tedious. Would love to find a way to explode measure one, then explode measure two, then three, etc.

In the ideal world, would love to be able to explode note-by-note, but I would be quite satisfied with measure-by-measure for now.

Screen Shot 2020-07-31 at 8.05.46 PM.png

Explode measure by measure:
Screen Shot 2020-07-31 at 8.06.02 PM.png

[Don't want] to explode whole line:
Screen Shot 2020-07-31 at 8.10.51 PM.png

Pipe dream: explode note by note:
Screen Shot 2020-07-31 at 8.12.14 PM.png


Hi! I'm not sure I understand what you are doing here. Why are you going measure by measure instead of just selecting the whole passage? Is the idea that you don't want single notes to get copied to multiple staves? Can you explain more about that use case? I am not understanding how that would ever come up, but if there is something we are missing, we could conceivably enhance the tool to handle that special case better.

You can control how many staves a line gets exploded onto by selecting the staves you want affected. If you select just one staff, it explodes each chord across however many staves are needed. If you select multiple staves, it explodes only across those staves. Maybe somehow this can help.

Meanwhile, in a plugin, you can involve any command by its internal name using the "cmd" function, something like that. Sorry, I know more about the internals than about the plugin interface.

In reply to by Marc Sabatella

Appreciate the thoughts! With my orchestra being on hiatus until the world normalize, I am trying to rescore some performances for a solo ensemble.

For instance, explode is a great tool to allow me to play piano pieces on a violin (separate out the notes, record myself playing each line, and layer the recordings together). However, if the right piano hand is mostly playing single notes with interspersed chords, exploding the whole line means a lot of redundancy between the exploded parts.

I did not know about the "cmd" function. Cheers!

In reply to by syncopassionfruit

I'd argue that you are better off including the doubled notes. It's probably true to the intent of the original, and it will prevent those notes from sounding softer than the others, which probably was not the intent (a pianist would naturally likely adjust naturally in performance). Plus it will just be more natural then having weird "holes" in the lines. Although there might be weird interval leaps.

Anyhow, if I did want to solve this programmatically, I'd be more likely to do the full explode then write a plugin to detect and delete the doubled notes.

You can invoke the "explode" command by calling cmd("explode"); in your plugin. However you would need to establish a selection on a measure first. The best way to do so will be available in MuseScore 3.5 (which is now in a release candidate stage) which would add selectRange() method to Selection object. However a similar thing can be achieved in earlier versions with something like this:

// Remember current track number (to restore a selection in a correct staff later)
var track = curScore.selection.elements[0].track;
// Do explode.
// Restore selection in a correct staff.
// This will select only a part of a measure but that seems to be enough
// for explode tool to work.
while (curScore.selection.elements[0].track > track) {

Doing so in a loop will allow running explode tool on every measure separately, although the code above seems to break for me if it encounters a full-measure rest.

The command names suitable for use with cmd() can be found here and correspond to actions available to users via keyboard shortcuts.

In reply to by dmitrio95

This is really great! I've been playing around with your code and trying to throw in a while look with a try/catch block but not quite sure how to make it work in musescore. I will keep playing around with it. If I find a solution that doesn't require human attention, I will post it in a reply here.

In reply to by syncopassionfruit

This is a result of selection behavior of "explode" command: if you select an empty measure and run Tools→Explode then the two staves including the upper one is selected. I don't think this is how selection is intended to work with this command, probably that just didn't come to attention of anyone since using Explode on empty measure does not usually make much sense. Maybe for plugin it would make sense to check if current measure is empty before executing "explode" command and just move to the next measure in this case.

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