Skip to content

Instantly share code, notes, and snippets.

@LTNMinh
Created May 16, 2022 16:19
Show Gist options
  • Save LTNMinh/a979ef3f1d2ec06891701df1a9f756dc to your computer and use it in GitHub Desktop.
Save LTNMinh/a979ef3f1d2ec06891701df1a9f756dc to your computer and use it in GitHub Desktop.
My Color Note Plugin Musescore
/=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2012 Werner Schweer
// Copyright (C) 2013-2017 Nicolas Froment, Joachim Schmitz
// Copyright (C) 2014 Jörn Eichler
//
// 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.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 Boomwhackers convention")
menuPath: "Plugins.Notes.Color Notes"
property variant colors : [ // "#rrggbb" with rr, gg, and bb being the hex values for red, green, and blue, respectively
"#e21c48", // C
"#f26622", // C#/Db
"#f99d1c", // D
"#ffcc33", // D#/Eb
"#fff32b", // E
"#bcd85f", // F
"#62bc47", // F#/Gb
"#009c95", // G
"#0071bb", // G#/Ab
"#5e50a1", // A
"#8d5ba6", // A#/Bb
"#cf3e96" // B
]
property string black : "#000000"
// 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)
if (note.tpc==0 ||note.tpc==7 || note.tpc==14 ||note.tpc==21 ||note.tpc==28) //C
note.color = colors[0];
else if (note.tpc==2 ||note.tpc==9 || note.tpc==16 ||note.tpc==23 ||note.tpc==30) //D
note.color = "#009C95"// colors[2];
else if (note.tpc==4 ||note.tpc==11 || note.tpc==18 ||note.tpc==25 ||note.tpc==32) //E
note.color = colors[4];
else if (note.tpc==-1 ||note.tpc==6 || note.tpc==13 ||note.tpc==20 ||note.tpc==27) //F
note.color = colors[5];
else if (note.tpc ==1 ||note.tpc==8 || note.tpc==15 ||note.tpc==22 ||note.tpc==29) //G
note.color = colors[7];
else if (note.tpc==3 ||note.tpc==10 || note.tpc==17 ||note.tpc==24 ||note.tpc==31) //A
note.color = colors[9];
else if (note.tpc==5 ||note.tpc==12 || note.tpc==19 ||note.tpc==26 ||note.tpc==33) //B
note.color = colors[11];
else
note.color = black;
else
note.color = black;
}
onRun: {
console.log("hello colornotes");
applyToNotesInSelection(colorNote)
Qt.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment