Changing note.parent.parent.leadingSpace doesn't seem to work?

• May 20, 2021 - 11:43

I'm trying to write a plug-in to adjust note spacing based on stem direction. I understand leadingSpace is a property of a segment, which is the parent of a chord (which is the parent of a note), but setting the note.parent.parent.leadingSpace property doesn't seem to work?
In fact when I look at the note properties Segment|Leading Space shows as 0 after setting programmatically (to a non-zero value), even though if I'd manually tweaked it beforehand the appearance isn't updated.


Comments

Don't forget to wrap score changes between startCmd and endCmd for the undo stack and score layout to pick up on them.

The sample below works perfectly if you just single click a notehead and then run it:

import QtQuick 2.0
import MuseScore 3.0
 
MuseScore {
      menuPath: "Plugins.pluginName"
      description: "Description goes here"
      version: "1.0"
      onRun: {
      var theNote = curScore.selection.elements[0];
            console.log(theNote);
            console.log(theNote.parent);
            console.log(theNote.parent.parent);
            var theSegment = theNote.parent.parent;
            console.log(theSegment.leadingSpace);
            curScore.startCmd();
            theSegment.leadingSpace = 20;
            curScore.endCmd();
            console.log(theSegment.leadingSpace);
            return;
            }
      }

I'm not saying this approach cannot be made to work, but do be aware you really only want to do these adjustments if the durations match and the spacing is relatively tight. Otherwise it would just introduce extra space unnecessarily.

In reply to by Dylan Nicholson1

Copy / paste doesn't preserve leading space because that info isn't attached to any one note but rather the "segment", which is an abstraction that doesn't exist in the clipboard - only in the actual score.

FWIW, I actually have found in many cases setting minimum notes distance to 0 produces the best layout in terms of evenness of spacing, but it does commit you to using system breaks basically everywhere.

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