Spreading selected notes evenly
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 MuseScore { menuPath: "Plugins.pluginName" onRun: { var c=curScore.newCursor(); c.rewind(2);//gotoSelectionEnd var endTick=c.tick; c.rewind(1);//gotoSelectionStart var startTick=c.tick; var selDuration=endTick-startTick; console.log("selection duration="+selDuration); var e=0; while(c.tick
Attachment | Size |
---|---|
EvenlySpreadingNotes.qml | 827 bytes |
Comments
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 Note that creating tuplets 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 You mean it is not possible by sbrbot
You will find that there is quite a lot not possible via the plugin API, merely because so far very little development time has been put into that aspect of MuseScore. Hence also the lack of documentation.
As for finding out what commands you can run using cmd(), they are listed in ScoreView::cmd. For tuplets specifically here: https://github.com/musescore/MuseScore/blob/b4c28adcd1ff6046368e4dafec2…
In reply to You will find that there is by jeetee
Has this changed with Musescore 3.0? I still can't find any way to manipulate a triplet.
In reply to Has this changed with… 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 benull
if the ChordRest isn't part of a tuplet and not-null otherwise. TheTuplet
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.
In reply to Not really. But we had some… by jeetee
If there's sufficient demand for this I'd be keen at looking at it, as being able to easily detect and create/manipulate tuplets from a plugin seems pretty essential.
In reply to If there's sufficient demand… by Dylan Nicholson1
BTW adding tuplets (and then changing notes inside them) seems easy enough, it's just examining existing tuplets that seems to be lacking?
In reply to BTW adding tuplets (and then… by Dylan Nicholson1
Actually this has already been implemented with tuplet property which is valid for chords, rests and tuplets (to be able to handle nested tuplets).
In reply to No, you can access existing… by dmitrio95
Ah ok, great, nothing further to do then!