Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Mu4, improved version #15

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
68 changes: 41 additions & 27 deletions blacknotes.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -20,28 +20,39 @@
//=============================================================================

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
visible: false
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)
Expand All @@ -51,24 +62,24 @@ 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"
for (var i = 0; i < element.dots.length; i++) {
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
Expand All @@ -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
Expand All @@ -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)
}
}
Expand All @@ -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)()
}
}
Binary file added color_notes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.