Script QML for MuseScore to expand/shrink a set of selected notes

Hi,

I need to create a plugin for MuseScore that can expand/shrink a set of selected notes
according to a chosen percentage
Chat GPT provided me with a qml script which has some errors

import QtQuick 2.0
import MuseScore 3.0

MuseScore {
    menuPath: "Plugins.ExamplePlugin"
    description: "Elargir/Rétrécir les durées des notes sélectionnées en pourcentage"

    function applyDurationPercentage(score, percentage) {
        var selectedElements = score.selectedNotes
        for (var i = 0; i < selectedElements.length; ++i) {
            var element = selectedElements[i]
            if (element.isChord()) {
                var chord = element.toChord()
                for (var j = 0; j < chord.notes.length; ++j) {
                    var note = chord.notes[j]
                    note.duration *= percentage / 100
                }
            } else {
                var note = element.toNote()
                note.duration *= percentage / 100
            }
        }
    }

    action: Action {
        text: "Elargir Durées"
        onTriggered: {
            var percentage = parseFloat(prompt("Entrez le pourcentage d'élargissement des durées (par exemple, 200 pour doubler)"))
            if (!isNaN(percentage)) {
                applyDurationPercentage(score, percentage)
            }
        }
    }

    action: Action {
        text: "Rétrécir Durées"
        onTriggered: {
            var percentage = parseFloat(prompt("Entrez le pourcentage de rétrécissement des durées (par exemple, 50 pour réduire de moitié)"))
            if (!isNaN(percentage)) {
                applyDurationPercentage(score, 100 / percentage)
            }
        }
    }
}

MuseScore’s qml script creator console says:
Component creation failed
line 35: Property value set multiple times

Could you correct this qml script?

thanks

Can you please pay attention to format it properly - i.e. use the “preformatted text” option?

Welcome to this forum. You are creating an native MuseScore app for SailfishOS?

With no definition of the type “MuseScore” and the code using “MuseScore” it is hard for me to understand this artificial code. So have a look to the error message:

Sure you have see this first: the property “action” (of type “Action”) is set mulitple times. You can rename this properties with personalised names. No idea what this mean for the other code in your project.

Happy to see your app in Jolla Store

Why no pop-up is displayed when clicking this plugin whose code has been modified?

import MuseScore 3.0
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1



MuseScore {
    menuPath: "Plugins.ScaleNotes"
    description: "Elargir/Rétrécir les durées des notes sélectionnées en pourcentage"

onRun: {
        if (!curScore) {
            error("No score open.\nThis plugin requires an open score to run.\n")
            Qt.quit()
        }
    }

    function applyDurationPercentage(score, percentage) {
        var selectedElements = score.selectedNotes
        for (var i = 0; i < selectedElements.length; ++i) {
            var element = selectedElements[i]
            if (element.isChord()) {
                var chord = element.toChord()
                for (var j = 0; j < chord.notes.length; ++j) {
                    var note = chord.notes[j]
                    note.duration *= percentage / 100
                }
            } else {
                var note = element.toNote()
                note.duration *= percentage / 100
            }
        }
    }

 
 Rectangle {
        color: "lightgrey"
        anchors.fill: parent

        GridLayout {
            columns: 2
            anchors.fill: parent
            anchors.margins: 10
            Label {
                text: qsTr("poucentage(0 to 100): ")
            }
           SpinBox {
    id: velocityOffset
    maximumValue: 100
    minimumValue: 0
    value: 0
    editable: true // Permet à l'utilisateur d'entrer directement une valeur

    // Gestionnaire d'événement appelé lorsque la valeur du SpinBox change
    onValueChanged: {
        var getValeur = velocityOffset.value; // Récupérer la valeur du SpinBox
        console.log("Nouvelle valeur de percentage:", percentage);
        // Utilisez la valeur de percentage comme vous le souhaitez
    }
  }

}
   }

  Button {
                id: applyButton
                text: qsTranslate("PrefsDialogBase", "Apply")
                onClicked: {
                    applyDurationPercentage(score, getValeur) 
                    Qt.quit()
                }
            }
}

Doesn’t look sailfishos related at all (and don’t even get me started on asking people to fix your AI-generated slop)

Nah, there’s that MuseScore application ( non-SFOS), and its plugins are qtquick/qml using that MuseScore plugin.

Indeed nothing to do with SFOS.

Yeah, that’s the thing, someone’s using a nail to hit a hammer, gibberish-generator (muh AI) can produce more plausible looking code-snippets than there are people in the world, so asking a biologically limited resource (humans) to debug its hallucinations is just… absurd, and it’s only going to get worse as the hype is still in full swing and zoomers literally use it instead of searching for real things