Changing note.parent.parent.leadingSpace doesn't seem to work?
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:
In reply to Don't forget to wrap score… by jeetee
Yeah that works, odd, I can't see what the difference is with mine.
In fact just
curScore.selection.elements[0].parent.parent.leadingSpace = 2
works fine too.
In reply to Yeah that works, odd, I can… by Dylan Nicholson1
Seems to have just been a bug in my code that it was overwriting the value after setting it, sorry, can close this.
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 I'm not saying this approach… by Marc Sabatella
In my example all the durations are the same. The spacing isn't that tight, but I just find musescore's default note spacing where the stem direction isn't taken into account less than ideal. That I can fix with a few lines of plugin code makes up for it though!
In reply to In my example all the… by Dylan Nicholson1
Except...not quite...even with layout stretch at the minimum and with leadingSpace at 0, there's too much spacing between a note with stems up and the following one with stems down and I still can't get the stem spacing the way I'd like it. Have attached example - I should be able to fit all 4 bars into one system.
In reply to Except...not quite...even… by Dylan Nicholson1
Fixed this by changing minimum note distance in Format|Style|Bar to 0. Basically looks right now! But...that setting applies to the whole score and rather messes up how the rest of it looks....
In reply to Fixed this by changing… by Dylan Nicholson1
Oh, why doesn't copy/paste preserve leadingSpace? Is there a way to make it do so?
In reply to Fixed this by changing… by Dylan Nicholson1
Also had to change "note left margin" to 0.50, finally got the spacing I think looks decent as attached. But as I said, those settings don't work well elsewhere in the score.
In reply to Fixed this by changing… 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.