diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/blacknotes.qml b/blacknotes.qml index 92b7ac8..8124212 100644 --- a/blacknotes.qml +++ b/blacknotes.qml @@ -4,7 +4,7 @@ // // Copyright (C)2010 Nicolas Froment (lasconic) // Copyright (C)2014 Jörn Eichler (heuchi) -// Copyright (C)2012-2019 Joachim Schmitz (Jojo-Schmitz) +// Copyright (C)2012-2024 Joachim Schmitz (Jojo-Schmitz) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2. @@ -20,13 +20,24 @@ //============================================================================= import QtQuick 2.9 -import QtQuick.Dialogs 1.2 +//import QtQuick.Dialogs 1.2 import MuseScore 3.0 MuseScore { version: "3.0" - description: "This plugin paints all chords and rests in black" + description: qsTr("This plugin paints all chords and rests in black") menuPath: "Plugins.Notes.Color Notes in Black" + //4.4 title: "Color Notes in Black" + //4.4 thumbnailName: "color_notes.png" + //4.4 categoryCode: "color-notes" + + Component.onCompleted : { + if (mscoreMajorVersion >= 4 && mscoreMinorVersion <= 3) { + title = "Color Notes in Black"; + thumbnailName = "color_notes.png"; + categoryCode = "color-notes"; + } + } MessageDialog { id: versionError @@ -34,14 +45,14 @@ MuseScore { title: qsTr("Unsupported MuseScore Version") text: qsTr("This plugin needs MuseScore 3.0.2 or later") onAccepted: { - Qt.quit() + (typeof(quit) === 'undefined' ? Qt.quit : quit)() } } function blackenElement(element) { - if (element.type == Element.REST) + if (element.type === Element.REST) element.color = "black" - else if (element.type == Element.CHORD) { + else if (element.type === Element.CHORD) { if (element.stem) element.stem.color = "black" if (element.hook) @@ -51,7 +62,7 @@ MuseScore { if (element.stemSlash) element.stemSlash.color = "black" } - else if (element.type == Element.NOTE) { + else if (element.type === Element.NOTE) { element.color = "black" if (element.accidental) element.accidental.color = "black" @@ -59,16 +70,16 @@ MuseScore { if (element.dots[i]) element.dots[i].color = "black" } - } + } else - console.log("Unknown element type: " + element.type) + console.log("Unknown element type: " + element.type) } // Apply the given function to all chords and rests in selection // or, if nothing is selected, in the entire score function applyToChordsAndRestsInSelection(func) { var cursor = curScore.newCursor() - cursor.rewind(1) + cursor.rewind(Cursor.SELECTION_START) var startStaff var endStaff var endTick @@ -80,12 +91,12 @@ MuseScore { } else { startStaff = cursor.staffIdx; - cursor.rewind(2) - if (cursor.tick == 0) { + cursor.rewind(Cursor.SELECTION_END) + if (cursor.tick === 0) { // this happens when the selection includes // the last measure of the score. - // rewind(2) goes behind the last segment (where - // there's none) and sets tick=0 + // rewind(Cursor.SELECTION_END) goes behind the last segment + // (where there's none) and sets tick=0 endTick = curScore.lastSegment.tick + 1 } else @@ -95,29 +106,29 @@ MuseScore { console.log(startStaff + " - " + endStaff + " - " + endTick) for (var staff = startStaff; staff <= endStaff; staff++) { for (var voice = 0; voice < 4; voice++) { - cursor.rewind(1) // sets voice to 0 + cursor.rewind(Cursor.SELECTION_START) // sets voice to 0 cursor.voice = voice //voice has to be set after goTo cursor.staffIdx = staff if (fullScore) - cursor.rewind(0) // if no selection, beginning of score + cursor.rewind(Cursor.SCORE_START) // if no selection, beginning of score while (cursor.segment && (fullScore || cursor.tick < endTick)) { if (cursor.element) { - if (cursor.element.type == Element.REST) + if (cursor.element.type === Element.REST) func(cursor.element) - else if (cursor.element.type == Element.CHORD) { + else if (cursor.element.type === Element.CHORD) { func(cursor.element) var graceChords = cursor.element.graceNotes; for (var i = 0; i < graceChords.length; i++) { // iterate through all grace chords func(graceChords[i]) - var notes = graceChords[i].notes + var gnotes = graceChords[i].notes for (var j = 0; j < graceChords[i].notes.length; j++) - func(graceChords[i].notes[j]) + func(graceChords[i].gnotes[j]) } var notes = cursor.element.notes - for (var i = 0; i < notes.length; i++) { - var note = notes[i] + for (var k = 0; k < notes.length; k++) { + var note = notes[k] func(note) } } @@ -131,10 +142,13 @@ MuseScore { onRun: { console.log("Hello, Black Notes") // check MuseScore version - if (mscoreMajorVersion == 3 && mscoreMinorVersion == 0 && mscoreUpdateVersion <= 1) - versionError.open() - else - applyToChordsAndRestsInSelection(blackenElement) - Qt.quit(); + if ((mscoreMajorVersion < 3) || ((mscoreMajorVersion == 3 && mscoreMinorVersion == 0 && mscoreUpdateVersion <= 1))) + versionError.open(); + else { + curScore.startCmd(); + applyToChordsAndRestsInSelection(blackenElement); + curScore.endCmd(); + } + (typeof(quit) === 'undefined' ? Qt.quit : quit)() } } diff --git a/color_notes.png b/color_notes.png new file mode 100644 index 0000000..3535704 Binary files /dev/null and b/color_notes.png differ