From 3c8c8ad841be168474a3dce675b0a53c5ddcf7a1 Mon Sep 17 00:00:00 2001 From: laurent Date: Sat, 12 Mar 2022 17:45:11 +0100 Subject: [PATCH] Coloring the notes regarding their definition in the chords (e.g. 7, b9, ...) instead some standard roles (3,5,7) --- soloanalyser.qml | 53 +++++---- zparkingb/chordanalyser.js | 229 +++++++++++++++++++++++++++---------- 2 files changed, 194 insertions(+), 88 deletions(-) diff --git a/soloanalyser.qml b/soloanalyser.qml index d8fe1c5..c0022cd 100644 --- a/soloanalyser.qml +++ b/soloanalyser.qml @@ -6,8 +6,8 @@ import "zparkingb/notehelper.js" as NoteHelper import "zparkingb/chordanalyser.js" as ChordHelper /********************** -/* Parking B - MuseScore - Solo Analyser² plugin -/* v1.0.1 +/* Parking B - MuseScore - Solo Analyser plugin +/* v1.1.0 /* ChangeLog: /* - 1.0.0: Initial release /* - 1.0.1: Using of ChordAnalyzer shared library @@ -16,13 +16,15 @@ import "zparkingb/chordanalyser.js" as ChordHelper MuseScore { menuPath: "Plugins." + pluginName description: "Colors the notes part of each measure harmony." - version: "1.0.2" + version: "1.1.0" readonly property var pluginName: "Solo Analyser" readonly property var selHelperVersion: "1.2.0" readonly property var noteHelperVersion: "1.0.3" - readonly property var chordHelperVersion: "1.0" + readonly property var chordHelperVersion: "1.2.0" + + property var colorNonChord: false // should be managed by a GUI onRun: { @@ -104,25 +106,27 @@ MuseScore { p += 12; var color = null; if (p == 0) { - color = "darkblue"; //"crimson"; + color = "#03A60E" //"darkblue"; //"crimson"; degree = "1"; - } else if ((curChord.n3 != null) && (p == curChord.n3)) { - color = "slateblue"; //"magenta"; - degree = "3"; - } else if ((curChord.n5 != null) && (p == curChord.n5)) { - color = "blue"; //tomato - degree = "5"; - } else if ((curChord.n7 != null) && (p == curChord.n7)) { - color = "teal"; //"purple"; - degree = "7"; - } else if (curChord.keys.indexOf(p) >= 0) { - color = "purple"; //"green"; //slategray dodgerblue - } else if (curChord.outside.indexOf(p) >= 0) { - color = "red"; } else { - color = "black"; + var roles = curChord.chordnotes.filter(function (e) { + return (parseInt(e.note, 10) === p); + }); + + if (roles.length != 0) { + console.log("ROLE FOUND (" + roles.length + "): " + roles[0].note + "-" + roles[0].role); + color = "dodgerblue"; + degree = roles[0].role; + } else if (curChord.keys.indexOf(p) >= 0 && colorNonChord) { + color = "sandybrown"; //"green"; //slategray dodgerblue + } else if (curChord.outside.indexOf(p) >= 0) { + color = "red"; + } else { + color = "black"; + } + + console.log(note.pitch + "/" + curChord.pitch + " ==> " + p + " ==> " + color); } - console.log(note.pitch + "/" + curChord.pitch + " ==> " + p + " ==> " + color); } else // no current chord, so resetting the color { @@ -137,7 +141,6 @@ MuseScore { } } - function writeDegree(note, degree) { const degrees = '1;2;3;4;5;6;7;8;9;11;13'; @@ -152,10 +155,10 @@ MuseScore { for (var j = 0; j < el.length; j++) { var e = el[j]; if (e.type == Element.FINGERING) { - if (degrees.indexOf(e.text) >= 0) { - eltext = e; - break; - } + // if (degrees.indexOf(e.text) >= 0) { + if (e.text.match(/^((b|#)?[0-9]{1,2})?$/gm) != null); + eltext = e; + break; } } } diff --git a/zparkingb/chordanalyser.js b/zparkingb/chordanalyser.js index f27ddbf..44c85b0 100644 --- a/zparkingb/chordanalyser.js +++ b/zparkingb/chordanalyser.js @@ -1,14 +1,17 @@ /********************** /* Parking B - MuseScore - Chord analyser -/* v1.0.0 +/* v1.2.0 /* ChangeLog: +/* - 1.0.0: Initial release +/* - 1.0.1: The 7th degree was sometime erased +/* - 1.2.0: Exporting now the chord notes instead of n3/n5/n7 erased /**********************************************/ // ----------------------------------------------------------------------- // --- Vesionning----------------------------------------- // ----------------------------------------------------------------------- function checkVersion(expected) { - var version = "1.0.0"; + var version = "1.2.0"; var aV = version.split('.').map(function (v) { return parseInt(v); @@ -82,7 +85,15 @@ function scaleFromText(text) { def4 = null, def6 = null, def7 = null; - var keys = [0,12]; + var keys = [0, 12]; + var chordnotes = [{ + "note": 0, + "role": "1" + }, { + "note": 12, + "role": "1" + } + ]; var outside = []; text = new chordTextClass(text.replace("add", "")); @@ -111,21 +122,23 @@ function scaleFromText(text) { // dim,o else if (text.startsWith("dim") || text.startsWith("o")) { console.log("Starts with dim/o"); - // [0, 1, 3, 4, 6, 7, 9, 12] - def2=1; - def4=4; - n3 = 3; + // [0, 1, 3, 4, 6, 7, 9, 12] + def2 = 1; + def4 = 4; + n3 = 3; n5 = 6; - n7 = 9; + def7 = 9; // changed 12/3/22. Was "n7=" def6 = 7; // Je force une 6ème par défaut. Qui sera peut-être écrasée après. } // Half-dim else if (text.startsWith("0")) { console.log("Starts with 0"); + def2 = 1; // added 12/3/22 + def4 = 4; // added 12/3/22 n3 = 3; n5 = 6; - n7 = 10; + def7 = 10; // changed 12/3/22. Was "n7=" def6 = 8; // Je force une 6ème par défaut. Qui sera peut-être écrasée après. } @@ -173,17 +186,34 @@ function scaleFromText(text) { } // Compléments - // ..7.. + // ..7.. if (n7 == null && text.includes("7")) { console.log("Has 7"); n7 = 10; - } else if (n7 == null && def7 != null) { - n7 = def7; + }; + + if (n7 != null) { + keys.push(n7); + chordnotes.push({ + "note": n7, + "role": "7" + }); + } else if (def7 != null) { + keys.push(def7); } else { - n7=11; - } + keys.push(11); + } + + // ..3.. + if (n3 != null) { + keys.push(n3); + chordnotes.push({ + "note": n3, + "role": "3" + }); + } - // ..5.. + // ..5.. if (text.includes("b5")) { console.log("Has b5"); n5 = 6; @@ -192,64 +222,112 @@ function scaleFromText(text) { n5 = 8; } - // ..2/9.. + if (n5 != null) { + keys.push(n5); + chordnotes.push({ + "note": n5, + "role": "5" + }); + } else { + // pas de défault 5 + } + + // ..2/9.. if (text.includes("b9")) { console.log("Has b9"); - keys.push(1) + keys.push(1); + chordnotes.push({ + "note": 1, + "role": "b9" + }); } else if (text.includes("#9")) { console.log("Has #9"); - keys.push(3) + keys.push(3); + chordnotes.push({ + "note": 3, + "role": "#9" + }); } else if (text.includes("9")) { console.log("Has 9"); - keys.push(2) - } else if (def2!=null) { + keys.push(2); + chordnotes.push({ + "note": 2, + "role": "9" + }); + } else if (def2 != null) { keys.push(def2) - } else { + } else { keys.push(2) - } + } - // ..4/11.. + // ..4/11.. if (text.includes("b11")) { console.log("Has b11"); - keys.push(4) + keys.push(4); + chordnotes.push({ + "note": 4, + "role": "b11" + }); } else if (text.includes("#11")) { console.log("Has #11"); keys.push(6) + chordnotes.push({ + "note": 6, + "role": "#11" + }) } else if (text.includes("11")) { console.log("Has 11"); - keys.push(5) - } else if (def4!=null) { - keys.push(def4) - } else { - keys.push(5) - } + keys.push(5); + chordnotes.push({ + "note": 5, + "role": "11" + }); + } else if (def4 != null) { + keys.push(def4); + } else { + keys.push(5); + } - // ..6/13.. + // ..6/13.. + if (text.includes("6")) { + console.log("Has 6"); + keys.push(9); // "So in the case of min6 chords always always always make the 6th a major 6th." + chordnotes.push({ + "note": 9, + "role": "6" + }); + def6=null; + } if (text.includes("b13")) { console.log("Has b13"); - keys.push(8) + keys.push(8); + chordnotes.push({ + "note": 8, + "role": "b13" + }); } else if (text.includes("#13")) { console.log("Has #13"); - keys.push(10) + keys.push(10); + chordnotes.push({ + "note": 10, + "role": "#13" + }); } else if (text.includes("13")) { console.log("Has 13"); - keys.push(9) - } else if (def6!=null) { + keys.push(9); + chordnotes.push({ + "note": 9, + "role": "13" + }); + } else if (def6 != null) { keys.push(def6) - } else { + } else { keys.push(9) - } + } console.log("After analysis : >>" + text + "<<"); - if (n3 != null) - keys.push(n3); - if (n5 != null) - keys.push(n5); - if (n7 != null) - keys.push(n7); - - var scale = new scaleClass(n3, n5, n7, keys); + var scale = new scaleClass(keys, chordnotes); return scale; } @@ -290,27 +368,33 @@ function chordClass(tpc, name, scale) { this.accidental = tpc.accidental; this.scale = scale; - Object.defineProperty(this, "n3", { - get: function () { - return this.scale.n3; - } + /* Object.defineProperty(this, "n3", { + get: function () { + return getDegree(this.scale.chordnotes, 3); + } }); Object.defineProperty(this, "n5", { - get: function () { - return this.scale.n5; - } + get: function () { + return getDegree(this.scale.chordnotes, 5); + } }); Object.defineProperty(this, "n7", { + get: function () { + return getDegree(this.scale.chordnotes, 7); + } + }); + */ + Object.defineProperty(this, "keys", { get: function () { - return this.scale.n7; + return this.scale.keys; } }); - Object.defineProperty(this, "keys", { + Object.defineProperty(this, "chordnotes", { get: function () { - return this.scale.keys; + return this.scale.chordnotes; } }); @@ -326,18 +410,37 @@ function chordClass(tpc, name, scale) { } -function scaleClass(n3, n5, n7, keys, outside) { - this.n3 = n3; - this.n5 = n5; - this.n7 = n7; +function getDegree(notes, role) { + var res = notes.filter(function (e) { + return (parseInt(e.role, 10) === role); + }); + return (res.length == 0) ? undefined : res[0].note; +} + +function scaleClass(keys, chordnotes, outside) { this.keys = (!keys || (keys == null)) ? [] : keys; + this.chordnotes = (!chordnotes || (chordnotes == null)) ? [] : chordnotes; this.outside = (!outside || (outside == null)) ? [] : outside; - this.mode=((n3!=null) && (n3==3))?"minor":"major"; - - this.keys.sort(function compareFn(a, b) { if(a 0) && (n3[0].note === 3)) ? "minor" : "major"; + + this.keys.sort(function compareFn(a, b) { + if (a < b) + return -1; + else if (a == b) + return 0; + else + return 1; + }); this.toString = function () { - return keys.toString(); ; + return chordnotes.map(function (e) { + return e.role + ": " + e.note; + }).join(', '); }; } \ No newline at end of file