how to get the length of a rest with plug-in script?

• Sep 21, 2009 - 09:59
Type
Functional
Severity
S5 - Suggestion
Status
closed
Project

hi,

i find the possibility to write plug-ins great! :)

i wrote now a little plug-in that guesses the chords for a measure that fit the notes in that measure. the only thing i would need is the length of the measures...
could you tell me how to get this? or if it is not in, could you put this into the next release?

here is a piece of code to demonstrate, what i wloud need:

function run()
  {
	var cursor = new Cursor(curScore);
	cursor.staff = 0;
	cursor.voice = 0;
	cursor.rewind();
	var a =0;
	var len = 0;
	while (!cursor.eos()) 
	{
		if (cursor.isChord())	a++; // just to do someting
		else
			len += 1; // i would need here the tickLen of the rest
		
		cursor.next();
	}
  }

by the way: the cursor.chord() is also an [object Rest] when cursor.isChord() is true according to the script debugger.


Comments

i thought that if cursor.isChord() is false, than cursor.chord() can not be called, because is not a chord, but a rest. but cursor.rest() did not work.

it also would be useful to know how many ticks are in a measure.

Status (old) active fixed

Rev. 2295 extends scripting with two new functions cursor.isRest() and cursor.rest()

function run()
{
var cursor = new Cursor(curScore);
cursor.staff = 0;
cursor.voice = 0;
cursor.rewind();
var len = 0;
while (!cursor.eos()) {
if (cursor.isRest()) {
var rest = cursor.rest();
len += rest.tickLen;
}
cursor.next();
}
print("==========len ", len);
}