tuplets in plugins
Hello,
I want to create a plugin that modifies rhythms and I would like to know if it is possible to check and create a tuplet in a plugin ?
Thank you.
Hello,
I want to create a plugin that modifies rhythms and I would like to know if it is possible to check and create a tuplet in a plugin ?
Thank you.
Do you still have an unanswered question? Please log in first to post your question.
Comments
I have this question too. Can't see how to check for them.
Checking the presence of a tuplet is quite simple: notes under a tuplet present a theoretical value (expressed in ticks) different from the actual one.
Starting from a cursor that points to the current element, you can retrieve the former duration in this way:
var theoretical_duration_ticks = cursor.element.duration.ticks
and the latter in this way:
var real_duration_ticks = cursor.segment.next.tick - cursor.segment.tick
Tentatively, you can also find the tuplet ratio:
1. calculate the greatest common divisor between the two values, and
2. divide both values by their gcd.
This should provide the ratio.
For example, let us consider a tuplet of 3 quarter notes in the space of 2 (a half note):
- Theoretical duration in ticks: 480
- Real duration in ticks: 320
- Ratio: 3:2
Unfortunately, this won't work well when the amount of 480 ticks per quarter note cannot be exactly divided. For instance, if you try to divide 480 by 13, notes will not be equally spaced (even if the total sum of ticks will be 480), so you should introduce some form of approximation.
However, in MuseScore 2.x API there was the property cursor.element.globalDuration, and its value for tuplets was different from cursor.element.duration. Unfortunately, I cannot find anything similar.
In reply to Checking the presence of a… by luca.ludovico
Thanks - yes I already implemented this earlier today following advice from some helpful folks on the Telegram chat group for developers, and it works OK. I think everyone there agreed that the API should be more helpful in this regard.
In reply to Thanks - yes I already… by adam.spiers
Could you share some code? I'm trying to write a plugin to convert a quarter+eight triplet into dotted 1/8 + 1/16, and you are right the API is not easy to use. Thanks.
In reply to Could you share some code? I… by Diego Puppin
Sure, hopefully the attached will help.
In reply to Sure, hopefully the attached… by adam.spiers
Beware - I just realised that the above example code only works when the tuple is all notes. If it contains or is followed by a rest then it will probably break.
In reply to Beware - I just realised… by adam.spiers
I have just published an alpha of my groove plugin which contains an example of how to calculate this correctly: https://github.com/aspiers/mscore-groove/blob/a758093e72ac5281f01cc4934…
In reply to I have just published an… by adam.spiers
Thanks so much for sharing, Adam.