need specific plugin:copy and paste notes according a percentage of duration

• Oct 21, 2024 - 00:35

Hi,

if i copy/paste in double duration, the duration percentage is 200%
if i copy/paste in half duration, the duration percentage is 50%
i need a qml script that :
-selects and copies a group of notes
-asks me for the new duration percentage between 0 and 200%.
-pastes this group of notes according to the new duration percentage

thnks


Comments

There may not be a note value at percentages other than 50% and 200%. For example, I think it's almost definite that there's no note available to paste that is 73% of ANY note. At a guess, I would say that only 25%, 50%, 75%, 100% (no change), 125%, 150%, 175%, and 200% are even possible and most of them (indeed, all of them except 25%, 50%, 100%, and 200%) are problematic to some degree.

In reply to by fionacar

Instead, you need a DAW. For example Cubase has the 'Logical Editor' which allows any type of transformation. But Cubase is also (secondarily) a 'notation software': if you go and see the result of unusual transformations after removing the 'quantization' you will realize the absurdity of your request.

In reply to by yonah_ag

Of course it can be done. But in my opinion we must also think about the practical side of the issue. A simple dotted quaver (360 ticks) at 75% becomes a value of 270 ticks: this value cannot be represented by a single note. The developer will have to think about how to represent it in relation to its position in the measure; if it is at the beginning of the bar we will have a quaver tied to a hemi-demi-semiquaver. And this for a simple dotted quaver, and to obtain an illegible score. Best wishes to the developer!

In reply to by fionacar

ChatGPT m'a donné ce script qml qui contient des erreurs que je n'arrive pas à corriger:
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import MuseScore 3.0

MuseScore {
menuPath: "Plugins.ScaleAndPasteNotes_3"
description: "Copies selected notes, scales durations, and pastes"

function applyDurationPercentage(score, percentage) {
    // Get selected notes
    var selectedElements = score.selectedNotes
    var copiedNotes = []

    // Copy selected notes
    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]
                // Save note with original duration
                copiedNotes.push({
                    pitch: note.pitch,
                    duration: note.duration
                })
            }
        } else if (element.isNote()) {
            var note = element.toNote()
            // Save note with original duration
            copiedNotes.push({
                pitch: note.pitch,
                duration: note.duration
            })
        }
    }

    // Modify duration according to percentage and apply to selected notes
    for (var i = 0; i < selectedElements.length; ++i) {
        if (i < copiedNotes.length) {
            var element = selectedElements[i]
            var noteData = copiedNotes[i]
            var newDuration = noteData.duration * (percentage / 100)

            if (element.isNote()) {
                element.toNote().duration = newDuration
            } else if (element.isChord()) {
                var chord = element.toChord()
                for (var j = 0; j < chord.notes.length; ++j) {
                    chord.notes[j].duration = newDuration
                }
            }
        }
    }
}

// Dialog to input new percentage

function showPercentageDialog() {
var dialog = Qt.createQmlObject(
`import QtQuick.Dialogs 1.2;
import QtQuick.Controls 1.4;

     Dialog {
         id: inputDialog
         title: "Set Duration Percentage"
         modal: true
         standardButtons: Dialog.Ok | Dialog.Cancel

         contentItem: Item {
             width: 200
             height: 100

             TextField {
                 id: percentageField
                 anchors.centerIn: parent
                 width: parent.width * 0.8
                 placeholderText: "Enter percentage (0-200, multiple of 25)"
                 inputMethodHints: Qt.ImhFormattedNumbersOnly
             }
         }

         onAccepted: {
             var percentage = parseInt(percentageField.text)
             if (isNaN(percentage) || percentage < 0 || percentage > 200 || percentage % 25 !== 0) {
                 console.log("Invalid input")
                 return
             }
             applyDurationPercentage(score, percentage)
         }
     }
    `, 
    Qt.application, "inputDialog"
);

dialog.visible = true;  // Assure l'affichage du dialogue

}

onRun: {
    showPercentageDialog()
}

}

Quelqu'un peut-il le corriger?

In reply to by fionacar

This plugin is nonsense, no wonder ChatGPT wrote it. Unfortunately it is not so simple to conceive a plugin that can realize your requests. For one thing, 'duration' does not belong to the 'note' object, and it is a complex object, it cannot be calculated directly, and if I remember correctly it is also 'read-only' (and this would only be the least of the problems...)

In reply to by ILPEPITO

I have recently been wrestling with note duration modification in a plugin. As you rightly say, duration does not belong to the note object but to the chord object, (via the properties inherited from the DurationElement). I could not find a way to modify duration directly and had to resort to cmd('pad-note-n'), which is very slow.

In reply to by yonah_ag

No, you cannot directly change note durations. Personally I prefer to memorize them (the notes), and then rewrite them with 'setDuration' and 'addNote', but each has its own methods. The two methods I mentioned also have limits: the main one is that if I change the duration of a note and end up having a fraction that does not correspond to a single note, I will have to manage the creation of more notes. Finally, the creation of ChatGTP is rather abstract: the management of the new positions of the notes is totally missing (essential above 100%, if I have not misunderstood the meaning of the request, not very clear), even if this is perhaps not due to ChatGTP.

In reply to by yonah_ag

I wrote chatGTP instead of chatGPT...I must be allergic to AI. I have no idea if it can be faster, certainly 'addRest' and 'addNote' allow you to insert dotted values ​​directly; also, it works with Musescore4 ('cmd' instead I think not). If your scenario only involves transformations with division and multiplication with the number 2, there will certainly be no problems.

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