QML Plugin - How do I get the tempo

• Apr 26, 2015 - 16:49

Hi.

Are the TEMPO_TEXT elements accessible through the plugin API for MuseScore 2.0?

I'm writing a plugin to export scores into the Ultrastar format. To do that, I need the tempo of the score.
I understand that there can be multiple tempo markers in a score, but I can't find a single one in the score.
As I understand it, the tempo markers should be in elements of type TEMPO_TEXT, but I haven't been able to find any in the score when using a cursor to step through the score.

I am using a copy of MuseScore that identifies itself as 2.1.0 - I checked out the source code a couple of days ago and built it.


Comments

TempoText is accessible. it offers the properties tempo (beats (1/4) per second) and followText (true/falase)
Try the help in the plugin editor

In reply to by Jojo-Schmitz

Yep, I see it there in the documentation. Unfortunately, it doesn't say what it is attached to. I've run through all the tracks in the score and searched for an elemement of type TEMPO_TEXT, and didn't find one although I know for sure it is there.
I've checked on various objects in the score (measures, chords, notes, segments) and still couldn't find it.

In reply to by Joseph Eoff

I don't know if/how it might be exposed in plugins, but I can tell you that tempo text elements, like other text elements, are annotations on segments.

But FWIW, having to search through tempo texts to understand the tempo is not ideal. It would be better if you could access the Score::tempo(int tick) method that returns the tempo for any given tick. But it looks like this is not exposed.

In reply to by Marc Sabatella

For what I'm working on, I don't need the tempo for every tick. Ultrastar assumes one tempo for the whole score.
Since I couldn't find the temp text, I punted and put an entry field on the export form. I'll look into the annotations on the segments the next chance I get and see if I can find it there.
In case anyone is interested, I've attached the the current version of my UltraStar export plugin.
It is functional though ugly, and does some odd things to the exported lyrics.
Duet export is implemented, but not tested.
I work under OpenSuse Linux, so no idea whether this will work under Windows.
This plugin requires MuseScore 2.1.0 or better.

Attachment Size
UltrastarExport.qml.zip 2.77 KB

All Text elements are annotations to a segment and can be retrieved like this:

import QtQuick 2.0
import MuseScore 1.0

MuseScore {
      menuPath: "Plugins.pluginName"
      onRun: {
            var cursor = curScore.newCursor();
            cursor.rewind(0);
            while(cursor.segment) {
                  var an = cursor.segment.annotations;

                  for (var i = 0; i < an.length; i++) {
                        if (an[i].type == Element.TEMPO_TEXT) {
                              console.log("Tempo Text: tempo="+an[i].tempo);
                        }
                  }
                  cursor.next();
            }
            Qt.quit()
      }
}

However, it must be noticed, that the cursor might skip such segments if there's no element in the given track. To make sure one gets all the texts in the score, one might need to loop over segments. This is a restriction of the current cursor.

Regarding Score::tempo(tick): I'd vote for a Cursor.tempo property.

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