How to edit Color Notes plugin in MS 4.x

• Jun 5, 2023 - 16:22

Hi all, searched but couldn't find an answer to my question.

I want to edit the Color Notes plugin to set custom note colours but my \Documents\MuseScore4\Plugins folder is empty, which I believe is where the plugin is supposed to be located?
Is it still possible to edit the plugin in 4.x? I'm aware we're in a limbo period at the moment while the plugins system gets overhauled.

Many thanks,
Joe


Comments

I have tried to modify ColorNotes_tpc.zip plugin to color only accidentals and sharps/flats, red for # and sharp notes and blue for b and flat notes, leaving all other notes as black. This is quite useful to quickly note sharps and flats if phrases are long and key is quite complex. However, manipulating TPC order leads to strange results and I failed to achieve desired effects. I have made Musescore 3 working plugin, but it does not work in Muscore 4. Perhaps someone could do it quickly as I have been struggling with this for a long time.

In reply to by Marc Sabatella

Here is my simple code, but it does not load.

//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Changes by: Wlodzislaw Duch
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in the file LICENCE.GPL
//=============================================================================

import QtQuick 2.9
import MuseScore 4.0

MuseScore {
version: "4.0"
description: qsTr("This plugin colors sharp notes red and flat notes blue")
menuPath: "Plugins"

Component.onCompleted: {
    if (mscoreMajorVersion >= 4) {
        title = qsTr("Notes.Color SharpFlat");
        category = "color-notes";
    }
}

// Function to color notes based on accidental
function colorNoteByAccidental(note) {
    // Default all notes to black
    note.color = "#000000";

    // Check if the note has an accidental
    if (note.accidental) {
        // Check if the accidental is a sharp
        if (note.accidental.symbol === "sharp") {
            note.color = "#FF0000"; // Red color for sharps
            note.accidental.color = "#FF0000"; // Red color for sharp accidental
        }
        // Check if the accidental is a flat
        else if (note.accidental.symbol === "flat") {
            note.color = "#0000FF"; // Blue color for flats
            note.accidental.color = "#0000FF"; // Blue color for flat accidental
        } else {
            note.accidental.color = "#000000"; // Set accidental color to black if neither sharp nor flat
        }
    }
}

// Apply the colorNoteByAccidental function to all notes in the selection or entire score
function applyToAllNotes(func) {
    var cursor = curScore.newCursor();
    cursor.rewind(0); // Start at the beginning of the score

    while (cursor.segment) {
        if (cursor.element && cursor.element.type === Element.CHORD) {
            var notes = cursor.element.notes;
            for (var k = 0; k < notes.length; k++) {
                var note = notes[k];
                func(note);
            }
        }
        cursor.next();
    }
}

// Entry point when the plugin is run
onRun: {
    console.log("Running Color Notes by Accidental");

    if (typeof curScore === 'undefined') {
        (typeof(quit) === 'undefined' ? Qt.quit : quit)();
    }

    applyToAllNotes(colorNoteByAccidental);

    (typeof(quit) === 'undefined' ? Qt.quit : quit)();
}

}

In reply to by Wlodzislaw

This looks dubious to me: note.accidental.symbol === "flat"

Look at
https://musescore.org/nl/project/add-and-remove-courtesy-accidentals
how a plugin looks for accidentals via tpc
EDIT:
In the attached colornotes3.qml I added at line 83
console.log("note.accidental.symbol = ", note.accidental.symbol)
and the Plugin Creator window (MU3 only) says
Debug: hello colornotes
Debug: note.accidental.symbol = undefined

Also: https://musescore.org/en/project/colornotestpc
seems to do what you want (& more)
colornotes3.qml

In reply to by elsewhere

Thank you for advice. I was trying to use colornotes3, it is coloring each note in a different way and I want only sharps and flat to be clearly visible. I was experimenting with color assignments but could not get proper colors, I have made once working Musescore 3 version, but it does not work in MS4.
Accidental.FLAT; and Accidental.SHARP;
It still does not work.

Attachment Size
ColorNotes_tpc.qml 2.68 KB

In reply to by elsewhere

I have tried to add it to this loop, but the plugin does not load with this line. Should it go somewhere else?

    if (note.accidental) {
            if (note.accidental.color == black) {
            if (note.tpc < 13)
              note.color = "#00ccff"
              note.accidental.color = "#00ccff"
             else
                note.color = "#ff0000"
                //note.accidental.color = colors[note.tpc+1];
                console.log("111, Note Accidental: note:"+ note + " pitch:" + note.pitch + " accidental:" + note.accidental);
                } else {
                note.accidental.color = black;
                }
        }

In reply to by Wlodzislaw

You don't know anything about coding in javascript. If an 'if' statement is followed by 2 lines of code it needs to be in brackets {}. If you run you code from the plugin creator you will see error messages (often confusing), e.g.

if (note.tpc < 13){
note.color = "#0000ff"
note.accidental.color = "#0000ff"
}

In reply to by elsewhere

Thank you for this reminder, indeed I have not done any JS programming for years and made an obvious error.
Accidentals placed before note change colors correctly, but those that define scale are not recognized.
Still the script does not work well. It does not color sharps and flats that are in the scale, I am just trying to color a piece where 4 scales are used and have to make manual selections in different parts.

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