Break every X measures plugin for 2.0

• Apr 15, 2015 - 07:55


import QtQuick 2.0
import MuseScore 1.0
import QtQuick.Controls 1.1

MuseScore {
menuPath: "Plugins.Break every X measures"
description: qsTr("This plugin will add a line break every X measures in the selection or in in the full score if no selection.")
pluginType: "dialog"

width: 230
height: 50
id: window

onRun: {}

function make() {
var m = curScore.firstMeasure
var nNum = 1
while (m) {
if (nNum == input.text){
m.lineBreak = true
nNum = 0
} else {
m.lineBreak = false
}
m = m.nextMeasure
nNum++
}
Qt.quit()
}

TextInput {
id: input
maximumLength: 3
text: "4"
inputMask: "000"
focus: true
anchors.top: window.top
anchors.topMargin: 10
anchors.left: window.left
anchors.leftMargin: 100
font.bold: true
font.pointSize: 15
smooth: false
}

Button {
id : buttonCancel
text: qsTr("Cancel")
anchors.bottom: window.bottom
anchors.right: window.right
anchors.topMargin: 10
anchors.bottomMargin: 0
onClicked: { Qt.quit() }
}

Button {
id : buttonOK
text: qsTr("OK")
anchors.bottom: window.bottom
anchors.left: window.left
anchors.topMargin: 10
anchors.bottomMargin: 0
onClicked: { make() }
}
}

1) TextInput is broken...
2) Score is not updated...

(Sorry, I do not speak in English. I use Google translate.)


Comments

In reply to by Jojo-Schmitz

I tried your code and I don't understand your 1) problem. TextInput works fine for me.

About the other things:

  • m.lineBreak works, as I've already said, this was my misunderstanding. Sorry again.
  • Your code however (first post) doesn't work, because it's using
    pluginType: "dialog"
    

    This will not call Score.cmdStart() and Score.cmdEnd() automatically and therefore:

    1. no relayout will take place. (saving will force a relayout, CTRL-A 'select all' also will. That's why the changes only appear later)
    2. A lot worse: Undo won't work. Try to undo the changes (CTRL-Z) made by your version of the plugin. It won't work.

    If you use pluginType: "dialog" you will need to include the calls to curScore.startCmd() and curScore.endCmd() as Jojo-Schmitz said.

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