End Tick

• Apr 21, 2013 - 16:22

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 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 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.

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