End Tick
How can I use the QML plugin framework to get the tick length of a score?
If some notes are selected, this gets what I need (the end of the selection):
cursor.rewind(2);
var endTick = cursor.tick;
However, when there is no selection, endTick ends up as zero. I'm currently working with nightly build 8bcd0f8.
Thanks.
Comments
Have a look at the notenames plugin that comes with the nighly build nowadays. It works on a selection if there is one and on the entire score otherwise. It is a bit tricky to find out which of the 2 options to take...
In reply to Have a look at the notenames by Jojo-Schmitz
Thanks, I've seen that, but how do I get the tick length of the score if there is no selection?
In reply to Tick length when no selection by DonH
just traverse the score to the end, I guess?
In reply to just traverse the score to by Jojo-Schmitz
I tried this, but sometimes the end tick result is lower than the start tick....?
What am I doing wrong?
function getEndTick(cursor)
{
// Run through all notes to get the last tick.
var endTick = 0;
console.log("getEndTick() : NStaves["+curScore.nstaves+"].");
for (var staff = 0; staff < curScore.nstaves; staff++)
{
console.log("getEndTick() : Staff["+staff+"].");
for (var v = 0; v < 4; v++)
{
cursor.rewind(0);
cursor.voice = v
cursor.staffIdx = staff;
while (cursor.segment)
{
console.log("getEndTick() : Segment.");
if(cursor.element){console.log("getEndTick() : Element["+cursor.element.type+"].")}
if (cursor.element && cursor.element.type == Element.CHORD)
{
console.log("getEndTick() : CursorTick["+cursor.tick+"] duration["+cursor.element.duration+"] = ["+(cursor.tick+cursor.element.duration)+"].");
var chordTickEnd = cursor.tick + cursor.element.duration;
if(chordTickEnd > endTick)
{
endTick = chordTickEnd;
}
}
cursor.next();
}
}
}
return(endTick);
}
In reply to Tick length when no selection by DonH
Not sure if it is available in all versions, but in the version under dev, once you have a
Cursor
, the methodCursor.rewind(2)
should position it at the end of the score; then you can extract the tick withCursor.tick
.M.
In reply to Cursor.rewind(2) by Miwarre
You only have a cursor, when you have a selection, I think?
In reply to You only have a cursor, when by Jojo-Schmitz
You only have a user interface cursor, when you have a selection (or an object being edited), but in a plugin, you may create a script cursor at any time, and move it independently of any visible cursor existing (or not!) in the user interface.
There are methods for creating scripts cursors, but I am not sure they are currently working: the plugin interface is again in a moving state...
M.