Spreading selected notes evenly

• Dec 6, 2016 - 14:24

I want to build a plugin which would spread selected notes evenly in duration keeping their original pitches.

If I select 4 notes this plugin should spread selected notes on 4 parts of equal duration (regardless of their original durations). For example if I select the following four notes: eighth-note (A) + eighth-note (B) + quarter-note (C) + half-note (D). They together have duration of 4 quarter-notes and this should be divided by plugin into 4 quarter-notes keeping original note's pitches (A,B,C,D). Ok, this is very simple example.

If I select 3 notes (sincope in this case) this plugin should spread selected notes on 3 parts of equal duration (that's triplet now). For example if I select there three notes: eighth-note (A) + quarter-note (B) + eighth-note (C). They together have duration of 2 quarter-notes and this should be divided into 3 quarter-notes keeping original note's pitches (A,B,C). This i still simple example.

However, if one makes a selection of 5 notes with duration of 7-eighth-notes this is more complex but not needed so much in praxis and it is not important if this plugin does not support these complex cases. Similar thing is if selection includes rests.

So general rule is: split selected duration evenly on number of selected notes:

I started to build such a plugin but I'm newbie in MuseScore plugin programming and need help with this:

Here is my starting code targeting selected notes:

import QtQuick 2.0
import MuseScore 1.0

  menuPath: "Plugins.pluginName"
   var c=curScore.newCursor();

    var endTick=c.tick;
    var startTick=c.tick;

    var selDuration=endTick-startTick;

    console.log("selection duration="+selDuration);

    var e=0;

Attachment Size
EvenlySpreadingNotes.qml 827 bytes


Note that creating tuplets from within a plugin is not "natively" supported by the framework. You can (partially) work around that by using the cmd() calls to execute the predefined tuplet actions.

In reply to by jeetee

You mean it is not possible to create tuplet (triplet) by API!? Strange, I can hardly believe that. We'll see. However, where can I find these "predefined tuplet actions" that can be run by cmd? I'd like to see how MuseScore creates tuples under the hood.

In reply to by Diego Puppin

Not really.
But we had some conversation about this in the past week in the developers chat. It currently is possible to detect tuplets by comparing notated chord duration fractions and the difference in ticks between this segment and the next. But that is quite non-straightforward.

The idea would be to add a .tuplet property to a ChordRest, which would be null if the ChordRest isn't part of a tuplet and not-null otherwise. The Tuplet object would then contain the full duration and ratio information.
This so far is just in the "idea"-stage and nobody has taken up any work in that direction yet.

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