Plugins that apply to selection

• May 20, 2021 - 06:55

Hi, I've been trying out some existing plug-ins to see how they apply behaviour only to selected notes - and the ones I've checked don't actually work properly, they apply their changes to all the elements between the first and last selected elements! (I tried ColorNotes and another one that removed courtesy accidentals).
As far as I can see curScore.selection.elements is the correct enumeration of all selected elements so is there a reason such plugins don't use this?
Actually my plugin will need to add/remove from this enumeration, which I thought would need curScore.selection.elements.remove or similar, but no luck with that so far.
It seems none of the sample qml files reference selection.elements at all.


Comments

Ok, I managed to get it working using:

     var curSelection = []
     for (var i in curScore.selection.elements)
       curSelection.push(curScore.selection.elements[i])
     for (var n in curSelection)
        if (curSelection[n].pitch > 60)
           curScore.selection.deselect(curSelection[n])

But...it doesn't actually work if what's selected is a range! So how can I convert a range selection into a "individual notes" selection? Guess I have to do a clear and re-add?

In reply to by Dylan Nicholson1

Hah, finally got it:

     var curSelection = []
     for (var i in curScore.selection.elements)
       curSelection.push(curScore.selection.elements[i])
     curScore.selection.clear()
     for (var n in curSelection)
        if (curSelection[n].pitch > 60)
              curScore.selection.select(curSelection[n], true) 

It was the "true" parameter for select I was missing.

In reply to by Dylan Nicholson1

Any hints on how I could allow prompting the user to provide a pitch value (I want the 60 above to be configurable)? I've looked at some plugins that have configuration dialogs but haven't seen any for selecting a pitch.
Also can't see what function to use to shift notes to display on the staff above or below (ctrl+shift+up/down).

In reply to by Dylan Nicholson1

For now I just a very rudimentary dialog prompting for the pitch to split below:

   Dialog {
     id: selectPitch
     title: "Selects notes below..."
     contentItem: ColumnLayout {
       TextField {
         id: splitPitchText
         placeholderText: "60"
       }
       Button {
         text: "OK"
         onClicked: {
           selectPitch.visible = false
           selectBelow(splitPitchText.text || 60)
           Qt.quit()
         }
       }
     }
   }

As for the "why aren't other plugins using selection.elements" the answer is as plain and simple as: these plugins all predate this fairly recently added property.

In reply to by Jojo-Schmitz

I have it ready to go but it does behave slightly differently from the original as it leaves all notes selected if you start with nothing selected (the first thing it issues is cmd("select-all") in that case)...but nvm, fixed now, just issues cmd("escape") after doing it in that case now.
Is it necessary to create an issue/bug to link this against first?

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