tuplets in plugins

• Feb 19, 2020 - 07:38

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.


Comments

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.

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