plugins: impossible to set the played duration of a chord

• Oct 23, 2018 - 16:18
S5 - Suggestion

I tried to set the duration of chords from a plug-in. I achieved to modify the displayed duration (correct head type), but not the played duration.

I seems that the displayed duration (head) is set from the property "durationType", while the played duration is set from "duration". The latter is defined by a fraction with properties "numerator" and "denominator". But these properties cannot be written to - I get a read-only error when trying so.

I append the plug-in that I used - the critical lines are commented-out (lines 176ff)

Attachment Size
chordsToNotes.qml 13.07 KB


I believe the duration property was originally meant to be read-only there and never really made to work.
But you can set the duration of the note/chord to enter if you use the cursor methods for that, see for example the random.qml plugin included with MuseScore which does something like:

cursor.setDuration(1, 8);
cursor.setDuration(1, 4);

In reply to by jeetee

I tried to use cursor.setDuration, but this only applies to cursor.addNote.
As I use chords and then add the chord to the cursor position with cursor.add, I need to set the duration to the chord. It seems to work with "durationType" (line 175 of my code), but then only the displayed duration is correct, not the played duration which seems to be handled separately with "duration".

Untested: but wouldn't multiple addNote() commands add up to a chord?
Or other workaround, first addNote to get the correct duration, then set chord to that segment?

Type Functional Plugins
Reported version 2.3  
Regression No
Workaround Yes

A workaround (which works only since 3.3 version though) is to make use of the fact that the newly added note gets automatically selected. Not sure how reliable is it but this seems to work:

cursor.setDuration(1, 4);
var note = curScore.selection.elements[0];
var chord = note.parent;
// add other notes to that chord with Chord.add()