1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
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()
}
} |
Partager