Redefine colors in the Color Notes plug-in

• Jul 21, 2020 - 14:29

Hi there,

I am very excited about the color notes plug-in, and I was able to successfully apply it to a section of music.

I would like to redefine the colors, however, to the rainbow scheme as introduced to Solfege by Isaac Newton.

Can this change be made by one of the developers? I would like to do the coding myself, but I am not sure why the program wont run after I copy and paste Ziya Mete Demircan's .txt file into the plug-in creator. Please advise.

Best,

Anthony


Comments

It isn't a .txt file, but a .qml file. It is plain text though, so can get edited with any half-way decent plain text editor.
The plugin editor should be sufficient.
But please mention which file, from where, you're referring to

In reply to by Basquiat1981

I just need someone to explain the logic here to me so that I can better understand the program:

property string noteC : "#FF0000";
property string noteD : "##FF7F00";
property string noteE : "FFFF00";
property string noteF : "#00FF00";
property string noteG : "#0000FF";
property string noteA : "#2E2B5F";
property string noteB : "#8B00FF";

  property string black : "#000000";

property variant colors : [ noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB ]

In reply to by Basquiat1981

Do not touch (or change) the "property variant colors" section. That part is prepared for tpc.

It is used to color notes, usually to color each note in note training.
Different schools have different color uses.
The student usually memorizes like "C is red" or "C is blue".
But whatever color he learned, he continues with it. Colors do not change for each different key. These colors are often matched to the piano keys or notes.
It didn't make sense to use different colors for each different Key.

In reply to by Basquiat1981

And here's the code:

import QtQuick 2.2
import MuseScore 3.0

MuseScore {
version: "3.0"
description: qsTr("This plugin colors notes in the selection depending on their pitch as per the RAINBOW")
menuPath: "Plugins.Notes.Color Notes tpc"
// "#rrggbb" with rr, gg, and bb being the hex values for red, green, and blue, respectively

  // No need to specify Sharp or Flats, the plugin sets itself. 
property string noteB : "#FF0000";

property string noteC : "#FF7F00";
property string noteD : "#FFFF00";
property string noteE : "#00FF00";
property string noteF : "#0000FF";
property string noteG : "#2E2B5F";
property string note : "#8B00FF";

  property string black : "#000000";

property variant colors : [ noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB, noteF, noteC, noteG, noteD, noteA, noteE, noteB ]

  // Apply the given function to all notes in selection
  // or, if nothing is selected, in the entire score

  function applyToNotesInSelection(func) {
        var cursor = curScore.newCursor();
        cursor.rewind(1);
        var startStaff;
        var endStaff;
        var endTick;
        var fullScore = false;
        if (!cursor.segment) { // no selection
              fullScore = true;
              startStaff = 0; // start with 1st staff
              endStaff = curScore.nstaves - 1; // and end with last
        } else {
              startStaff = cursor.staffIdx;
              cursor.rewind(2);
              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
                    endTick = curScore.lastSegment.tick + 1;
              } else {
                    endTick = cursor.tick;
              }
              endStaff = cursor.staffIdx;
        }
        //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.voice = voice; //voice has to be set after goTo
                    cursor.staffIdx = staff;

                    if (fullScore)
                          cursor.rewind(0) // if no selection, beginning of score

                    while (cursor.segment && (fullScore || cursor.tick < endTick)) {
                          if (cursor.element && cursor.element.type === Element.CHORD) {
                                var graceChords = cursor.element.graceNotes;
                                for (var i = 0; i < graceChords.length; i++) {
                                      // iterate through all grace chords
                                      var graceNotes = graceChords[i].notes;
                                      for (var j = 0; j < graceNotes.length; j++)
                                            func(graceNotes[j]);
                                }
                                var notes = cursor.element.notes;
                                for (var k = 0; k < notes.length; k++) {
                                      var note = notes[k];
                                      func(note);
                                }
                          }
                          cursor.next();
                    }
              }
        }
  }

  function colorNote(note) {

        if (note.color == black) {
              note.color = colors[note.tpc+1];
              console.log("103, Note Color: note.tpc: "+ note.tpc + " pitch:" + note.pitch);
        } else {
              note.color = black;
        } 

        if (note.accidental) {
            if (note.accidental.color == black) {
                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;
                }
        }


        for (var i = 0; i < note.dots.length; i++) {
              if (note.dots[i]) {
                    if (note.dots[i].color == black) {
                          note.dots[i].color = colors[note.tpc+1];
                console.log("122, Note Dots: note:"+ note.dots[i] + " color:" + colors[note.tpc+1]);
                    } else {
                          note.dots[i].color = black;
                    }
              }
        }
     }

  onRun: {
        console.log("hello colornotes");

        if (typeof curScore === 'undefined')
              Qt.quit();

        applyToNotesInSelection(colorNote)

        Qt.quit();
     }

}

Is there a way to make the plugin recognize different keys? That way I don't have to edit the code every time I switch to a song that is in a different key? Thanks.

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