Skip to content

Commit

Permalink
Ajout des 7th, 9th, 11th dans les accords 11th et 13th
Browse files Browse the repository at this point in the history
Ajout des accords 10th
bug: mauvaise reconnaissance des accords ##
  • Loading branch information
laurent committed Oct 13, 2024
1 parent ad08f7d commit 071f591
Show file tree
Hide file tree
Showing 5 changed files with 1,081 additions and 194 deletions.
62 changes: 60 additions & 2 deletions soloanalyser/chordanalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
/* - 1.2.20: Case-insensitive search for "Aug", "Sus2", ...
/* - 1.2.21: Accords "Alt"
/* - 1.2.22: b5 and #5 chords wrongly analysed
/* - 1.2.23: Ajout des 7th, 9th, 11th dans les accords 11th et 13th
/* - 1.2.23: Ajout des accords 10th
/* - 1.2.24: bug: mauvaise reconnaissance des accords ##
/**********************************************/
// -----------------------------------------------------------------------
// --- Vesionning-----------------------------------------
// -----------------------------------------------------------------------
var default_names = ["1", "b9", "2", "#9", "b11", "4", "#11", "(5)", "m6", "M6", "m7", "M7"];

function checkVersion(expected) {
var version = "1.2.22";
var version = "1.2.24";

var aV = version.split('.').map(function (v) {
return parseInt(v);
Expand All @@ -59,10 +62,17 @@ function chordFromText(source) {
//var text = source.replace(/(\(|\))/g, '');
var text = source.replace(/(^\s*\(\s*|\s*\)\s*$)/g, ''); // on vire les "(" et ")" de début et fin

console.log("chordFromText: source: "+source);
console.log("chordFromText: cleaned: "+text);

var rootbass = text.split("/");
text = rootbass[0];
var bass = (rootbass.length > 1) ? rootbass[1] : null;

console.log("chordFromText: /w bass : "+text);
console.log("chordFromText: bass : "+text);


// Root
var rootacc = getRootAccidental(text);
text = rootacc.remaingtext;
Expand Down Expand Up @@ -98,9 +108,15 @@ function chordFromText(source) {
function getRootAccidental(text) {
var root = text.slice(0, 1).toUpperCase();
var alt = text.slice(1, 2);
console.log("Searching root and accidental in : "+text);
console.log("Root: "+root);
console.log("Alteration text: "+alt);
if ("bb" === text.slice(1, 3)) {
alt = 'FLAT2';
text = text.substr(3);
} else if ("##" === text.slice(1, 3)) {
alt = 'SHARP2';
text = text.substr(3);
} else if ("x" === alt) {
alt = 'SHARP2';
text = text.substr(2);
Expand All @@ -115,6 +131,8 @@ function getRootAccidental(text) {
text = text.substr(1);
}

console.log("Searching for tp for root="+root+", accidental="+alt);

var ftpcs = NoteHelper.tpcs.filter(function (e) {
return ((e.raw === root) && (e.accidental === alt));
});
Expand Down Expand Up @@ -306,6 +324,9 @@ function scaleFromText(text, bass) {
if (n3 !== null) {
pushToKeys(keys, n3, "n3");
pushToNotes(chordnotes, n3, "3");
} else if (text.includes("10")) {
pushToKeys(keys, 4, "10");
pushToNotes(chordnotes, 4, "10");
} else if (def3 !== null) {
pushToKeys(keys, def3, "def3");
}
Expand Down Expand Up @@ -372,8 +393,9 @@ function scaleFromText(text, bass) {
}

// Adding an explicit 7 if a 9 is present
if ((n9 !== null) && (n7 === null) && (def7 !== null)) {
//if ((n9 !== null) && (n7 === null) && (def7 !== null)) {
// n7 = def7;
if ((n9 !== null) && (n7 === null)) {
n7 = 10;
}

Expand Down Expand Up @@ -411,6 +433,21 @@ function scaleFromText(text, bass) {
if (getNote(chordnotes, def4) === undefined)
pushToNotes(allnotes, def4, "4");
}

// Adding an explicit 7 and 9 if a 11 is present
console.log("---Adding 7 in 11 chord :"+n11+"/"+n7+"/"+def7);
if ((n11 !== null) && (n7 === null)) {
console.log("...Ajouté");
n7 = 10;
}

if ((n11 !== null) && (n9 === null)) {
n9 = 2;
pushToKeys(keys, n9, "9");
pushToNotes(chordnotes, n9, "9");
}



// ..6/13..
if (n6===null) {
Expand Down Expand Up @@ -451,12 +488,33 @@ function scaleFromText(text, bass) {
if (getNote(chordnotes, def6) === undefined)
pushToNotes(allnotes, def6, "6");
}

// Adding an explicit 7, 9, 11 if a 13 is present
if ((n13 !== null) && (n7 === null)) {
n7 = 10;
}

if ((n13 !== null) && (n9 === null)) {
n9 = 2;
pushToKeys(keys, n9, "9");
pushToNotes(chordnotes, n9, "9");
}

if ((n13 !== null) && (n11 === null)) {
n11 = 5;
pushToKeys(keys, n11, "(11)");
pushToNotes(chordnotes, n11, "11");
}



//..7..
if (n7 !== null) {
console.log("found 7 as explicit ("+n7+")");
pushToKeys(keys, n7, "n7");
pushToNotes(chordnotes, n7, "7");
} else if ((at = [10, 11].indexOf(bass)) >= 0) {
console.log("found 7 as bass ("+bass+")");
n7 = bass;
pushToKeys(keys, bass, "bass as 7");
pushToNotes(chordnotes, bass, ["m", "M"][at] + "7");
Expand Down
114 changes: 104 additions & 10 deletions soloanalyser/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
/* - 1.2.5: Don't analyse drum staves
/* - 1.2.6: New option for not using chords preceeding the selection
/* - 1.2.7: new "unknown symbol" "✗"
/* - 1.2.8: Starting Chord Symbol not used in the analyse when the track 0 has no segmennt at the tick
/* - 1.2.8: A Chord Symbol is not used in the analyse when the track 0 has nothing defined at that segment's tick.
/* - 1.2.9: Better treatment of lack of chord symbols and uparsable chord symbols (e.g. chord symbols for files just imported from MusicXML does not work unless the chords are manually edited).
/**********************************************/

var degrees = '1;2;3;4;5;6;7;8;9;11;13';
Expand Down Expand Up @@ -129,11 +130,21 @@ function doAnalyse() {
for (var j = 0; j < annotations.length; j++) {
var ann = annotations[j];
//console.log(" (" + i + ") " + ann.userName() + " / " + ann.text + " / " + ann.harmonyType);
if (ann.type !== Element.HARMONY || ann.harmonyType!== HarmonyType.STANDARD ) { // Not using the Roman and Nashvill Harmony types
if (
(ann.type !== Element.HARMONY || ann.harmonyType!== HarmonyType.STANDARD ) // Not using the Roman and Nashvill Harmony types
&& (ann.type !==Element.FRET_DIAGRAM) // Not a Fretboard diagram (that includes chord name)
) {
console.log(segment.tick+": rejecting non relevant annotation: "+ann.userName());
continue;
}

debugO("elements: ",ann.elements);

if (!ann.text) {
console.log(segment.tick+": rejecting relevant annotation without text: "+ann.userName());
continue;
}

if (ignoreBrackettedChords && (ann.text.search(/^\(.+\)$/g)!==-1)) {
console.log(segment.tick+": rejecting chord name with parentheses: "+ann.text);
continue;
Expand All @@ -144,22 +155,27 @@ function doAnalyse() {
console.log(segment.tick+": rejecting annotation on out of range track");
continue;
}

count++;

if (byTrack[ann.track] === undefined)
byTrack[ann.track] = [];

console.log(segment.tick+": going forward with analyse of "+ann.text);


var chord = ChordHelper.chordFromText(ann.text);
if (chord !== null) {
console.log(segment.tick+": adding "+ann.text+" to track "+ann.track);
// If the chord is correctly analyzed, add it (to avoid invalid chord names, or "%" chord names)

if (byTrack[ann.track] === undefined)
byTrack[ann.track] = [];

count++;

byTrack[ann.track].push({
tick: segment.tick,
chord: chord
});
} else {
console.log(segment.tick+": rejecting invalid chord name: "+ann.text);
console.log(segment.tick+": rejecting invalid chord name: \""+ann.text+"\"");
//debugO("Empty annotation at "+segment.tick,ann); // fait planter le système quand on lit des accords chargés depuis MusicXML:-(
}
}
}
Expand Down Expand Up @@ -220,6 +236,8 @@ function doAnalyse() {
cursor.rewindToTick(segMin);
var segment = cursor.segment;
var values = (byTrack[track] !== undefined) ? byTrack[track] : [];
debugO("Chords at track "+track,values);
console.log("Chords found at track=+"+track+": "+values.length);
var curChord = null;
var check=null;
var step = lookAhead?0:-1; // if we lookAhead, we start from the first chord, even if it is further that start segment.
Expand All @@ -233,7 +251,7 @@ function doAnalyse() {
// curChord = ChordHelper.chordFromText(values[step].text);
}

if(step>=0) {
if((step>=0) && (step<=(values.length-1))) {
curChord = values[step].chord;
check = values[step].tick;
}
Expand Down Expand Up @@ -453,4 +471,80 @@ function getSelection() {

return chords;

}
}

function debugO(label, element, excludes, isinclude) {

if (typeof isinclude === 'undefined') {
isinclude = false; // by default the exclude is an exclude list.otherwise it is an include
}
if (!Array.isArray(excludes)) {
excludes = [];
}

try {
if (typeof element === 'undefined') {
console.log(label + ": undefined");
return;
}
} catch (error) {
console.log("!! "+label+": failed to check for undefined");
console.log(error);
return;
}

try {
if (element === null) {
console.log(label + ": null");
return;
}
} catch (error) {
console.log("!! "+label+": failed to check for null");
console.log(error);
return;
}


try {
if (Array.isArray(element)) {
for (var i = 0; i < element.length; i++) {
debugO(label + "-" + i, element[i], excludes, isinclude);
}
return;
}
} catch (error) {
console.log("!! "+label+": failed to check for isArray");
console.log(error);
return;
}


try {
if (typeof element === 'object') {

var kys = Object.keys(element);
for (var i = 0; i < kys.length; i++) {
if ((excludes.indexOf(kys[i]) == -1) ^ isinclude) {
debugO(label + ": " + kys[i], element[kys[i]], excludes, isinclude);
}
}
return;
}
} catch (error) {
console.log("!! "+label+": failed to check for undefined");
console.log(error);
return;
}


try {
console.log(label + ": " + element);
return;
} catch (error) {
console.log("!! "+label+": failed to check for undefined");
console.log(error);
return;
}


}
Loading

0 comments on commit 071f591

Please sign in to comment.