Jump to content

Chord analysis


coatsie

Recommended Posts

I have an array of notes that's being compared to a list of chords. I adapted this from some python I found.

 

Issue #1: I know there's got to be a better way of parsing the note from the event. This is just embarrassing.

 

Issue #2: It's not seeing a lot of the chords. As soon as I hit 3 notes in a triad, it won't see the 7 , if added, for instance. The console will display some 6 chords and some augmented, but I don't know what I'm missing.

 

var chr_scale = ['A', 'A#', 'B', 'C', 'C#', 'D',
            'D#', 'E', 'F', 'F#', 'G', 'G#']

const chord_names = {"Major": [0,4,7], "Minor": [0,3,7], "Major7": [0,4,7,11],
              "Augmented": [0, 4, 8], "Diminished": [0,3,6], "Diminished7": [0,3,6,9],
              "Half-diminished7": [0,3,6,10], "Minor-major7": [0, 3, 7, 11],
              "Augmented7": [0, 4, 8, 10], "Augmented major7": [0, 4, 8, 11],
              "Minor7": [0,3,7,10], "Major6": [0,4,7,9],
              "Minor6": [0,3,7,9], "Dominant7": [0,4,7,10],
              "Sus2": [0,2,7], "Sus4": [0,5,7], "Add9": [0,2,4,7]}
var noteIn = "";
var basic_notes = [];
var raw_list = [];
function HandleMIDI(e) {
 e.send();
if (e instanceof NoteOn) {
init = e.toString().indexOf('pitch'); //parses out just the note
fin = e.toString().indexOf('vel'); //still parsing
noteIn = (e.toString().substr(init+10,fin-init-13)); //still parsing
basic_notes.push(noteIn);
Trace(basic_notes);
} else if (e instanceof NoteOff) {
	for (i = 0; i < basic_notes.length; i++) {
		init2 = e.toString().indexOf('pitch'); //parses out just the note
		fin2 = e.toString().indexOf('vel'); //still parsing
		if (basic_notes[i] == (e.toString().substr(init2+10,fin2-init2-13))) {
			basic_notes.splice(i, 1);
			Trace(basic_notes);
			break;
			}
 	}
}
   for (tonic in basic_notes){
   		var tonic_note = basic_notes[tonic];

   	    var pattern = [];
   	    for (note in basic_notes){
       		var actual_note = basic_notes[note];
           interval = ((chr_scale.indexOf(actual_note) - chr_scale.indexOf(tonic_note)) + 12 ) % 12;
           pattern.push(interval);  
           }
	pattern.sort();
      	for (const [key, value] of Object.entries(chord_names)) {
      		if (JSON.stringify(value) === JSON.stringify(pattern)) {
					Trace(tonic_note);
					Trace(key);
}}}}

Link to comment
Share on other sites

Maybe you're just trying to mess with us. ? :-)

 

hahahaha no. It does actually work, except, I wanna get the 7 chords. It's my first time using javascript so I'm just scouring stack exchange to find equivalent code from my native Python knowledge.

 

I'll figure it out. It's part of a larger script I'm working on that prints the chords to a track.

 

 

IMG_2710.thumb.jpg.493e32831e97456500b04c1cc46aa207.jpg

 

If I could just get it to recognize more than just triads, it'll be complete.

 

 

IMG_2712.thumb.jpg.1137a9307b54711d616d2d1e263bc06f.jpg

 

 

See? No 7 chords display properly.

Link to comment
Share on other sites

Fun prank. Let’s see a video demo

 

This is being made for people that miss the chord track from Logic 9.

 

 

I didn't include the rest of the script because the array that holds the notes to draw the chords is enormous, but the code itself is just a for loop inside a for loop that spits out columns on 32nd notes.

Edited by coatsie
Link to comment
Share on other sites

alright, taking a closer look at the script, be back in a few minutes. How are you generating the piano roll graphics?

 

Here's the entire script. Beware, the array is huge!

 

var all_chords = [[[64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [72, 79],   [72, 79],   [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]]  ,  [[45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 72, 79],   [37, 38, 39, 45, 72, 79],   [40, 41, 42, 45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45]]  ,  [[48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],   [54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 54, 55, 72, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],   [40, 41, 42, 45, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]]  ,  [[53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 72, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],   [47, 48, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [49, 50, 51, 52, 53, 54]]  ,  [[59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [58, 59, 60, 61, 62, 72, 79],   [59, 61, 72, 79],   [58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [59, 61]]  ,  [[45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 58, 59, 60, 61, 62, 72, 79],   [37, 38, 39, 45, 59, 61, 72, 79],   [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 59, 61]]  ,  [[48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 58, 59, 60, 61, 62, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],   [54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],   [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 58, 59, 60, 61, 62, 72, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],   [47, 48, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [64, 72, 79],   [64, 72, 79],   [65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78]]  ,  [[45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 64, 72, 79],   [37, 38, 39, 45, 64, 72, 79],   [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],   [43, 44, 45]]  ,  [[48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 64, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],   [54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 54, 55, 64, 72, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],   [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]]  ,  [[53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 64, 72, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],   [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],   [49, 50, 51, 52, 53, 54]]  ,  [[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [64, 79],   [64, 79],   [65, 78]]  ,  [[45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 64, 79],   [37, 38, 39, 45, 64, 79],   [40, 41, 42, 45, 65, 78],   [43, 44, 45]]  ,  [[48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 64, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],   [54, 55, 65, 78],   [48, 49, 50, 51, 52, 53, 54]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 54, 55, 64, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],   [40, 41, 42, 45, 54, 55, 65, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]]  ,  [[53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 64, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],   [47, 48, 54, 55, 65, 78],   [49, 50, 51, 52, 53, 54]]  ,  [[59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [58, 59, 60, 61, 62, 64, 79],   [59, 61, 64, 79],   [58, 59, 60, 61, 62, 65, 78],   [59, 61]]  ,  [[45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 58, 59, 60, 61, 62, 64, 79],   [37, 38, 39, 45, 59, 61, 64, 79],   [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 78],   [43, 44, 45, 59, 61]]  ,  [[48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 58, 59, 60, 61, 62, 64, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],   [54, 55, 58, 59, 60, 61, 62, 65, 78],   [48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],   [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 58, 59, 60, 61, 62, 64, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],   [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 78],   [49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [64, 79],   [64, 79],   [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]]  ,  [[45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 64, 79],   [37, 38, 39, 45, 64, 79],   [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45]]  ,  [[48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 64, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],   [54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 54, 55, 64, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],   [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]]  ,  [[53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 64, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],   [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [49, 50, 51, 52, 53, 54]]  ,  [[59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [58, 59, 60, 61, 62, 64, 79],   [59, 61, 64, 79],   [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [59, 61]]  ,  [[45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 58, 59, 60, 61, 62, 64, 79],   [37, 38, 39, 45, 59, 61, 64, 79],   [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 59, 61]]  ,  [[48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 58, 59, 60, 61, 62, 64, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],   [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],   [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 58, 59, 60, 61, 62, 64, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],   [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [64, 72, 79],   [64, 72, 79],   [64, 72, 79]]  ,  [[45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 64, 72, 79],   [37, 38, 39, 45, 64, 72, 79],   [40, 41, 42, 45, 64, 72, 79],   [43, 44, 45]]  ,  [[48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 64, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],   [54, 55, 64, 72, 79],   [48, 49, 50, 51, 52, 53, 54]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 54, 55, 64, 72, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],   [40, 41, 42, 45, 54, 55, 64, 72, 79],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]]  ,  [[53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 64, 72, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],   [47, 48, 54, 55, 64, 72, 79],   [49, 50, 51, 52, 53, 54]]  ,  [[64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [72, 79],   [72, 79],   [72, 79]]  ,  [[45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 72, 79],   [37, 38, 39, 45, 72, 79],   [40, 41, 42, 45, 72, 79],   [43, 44, 45]]  ,  [[48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],   [54, 55, 72, 79],   [48, 49, 50, 51, 52, 53, 54]]  , [[45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 54, 55, 72, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],   [40, 41, 42, 45, 54, 55, 72, 79],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]]  ,  [[53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 72, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],   [47, 48, 54, 55, 72, 79],   [49, 50, 51, 52, 53, 54]]  ,  [[59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [58, 59, 60, 61, 62, 72, 79],   [59, 61, 72, 79],   [58, 59, 60, 61, 62, 72, 79],   [59, 61]]  ,  [[45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 58, 59, 60, 61, 62, 72, 79],   [37, 38, 39, 45, 59, 61, 72, 79],   [40, 41, 42, 45, 58, 59, 60, 61, 62, 72, 79],   [43, 44, 45, 59, 61]]  ,  [[48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 58, 59, 60, 61, 62, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],   [54, 55, 58, 59, 60, 61, 62, 72, 79],   [48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],   [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],   [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 72, 79],   [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],   [54, 55, 58, 59, 60, 61, 62, 72, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],   [47, 48, 54, 55, 58, 59, 60, 61, 62, 72, 79],   [49, 50, 51, 52, 53, 54, 59, 61]]  ,  [[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [64, 79],   [64, 79],   [64, 72, 79],   [65, 66, 67, 68, 69, 70, 71, 72]]  ,  [[45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 64, 79],   [37, 38, 39, 45, 64, 79],   [40, 41, 42, 45, 64, 72, 79],   [43, 44, 45, 65, 66, 67, 68, 69, 70, 71, 72]]  ,  [[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54, 64, 79],   [54, 55, 64, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],   [54, 55, 65, 66, 67, 68, 69, 70, 71, 72]  ,  [48, 49, 50, 51, 52, 53, 54]],   [[45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 48, 49, 50, 51, 52, 53, 54, 64, 79],   [37, 38, 39, 45, 54, 55, 64, 79],   [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79]   ,  [43, 44, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72],   [48, 49, 50, 51, 52, 53, 54]],   [[53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [54, 55, 64, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 64, 79]  ,  [47, 48, 54, 55, 64, 72, 79],   [49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72]],   [[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [59, 61, 64, 79],   [58, 59, 60, 61, 62, 64, 79]   ,  [59, 61, 64, 72, 79],   [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],   [59, 61]],   [[45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [45, 58, 59, 60, 61, 62, 64, 79]  ,  [37, 38, 39, 45, 59, 61, 64, 79],   [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 72, 79],   [43, 44, 45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72]],   [[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79]  ,  [54, 55, 58, 59, 60, 61, 62, 64, 79],   [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],   [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],   [48, 49, 50, 51, 52, 53, 54, 59, 61]],   [[45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]  ,  [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],   [37, 38, 39, 45, 54, 55, 58, 59, 60, 61, 62, 64, 79],   [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],   [43, 44, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],  [48, 49, 50, 51, 52, 53, 54, 59, 61]],  [[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],   [53, 54, 59, 61, 64, 79],   [54, 55, 58, 59, 60, 61, 62, 64, 79],   [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 72, 79],   [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72], [49, 50, 51, 52, 53, 54, 59, 61]],  [[58, 59, 60, 61, 62, 74, 75, 76, 77, 78, 79],   [58, 60, 62, 78],   [65],   [58, 59, 60, 61, 62, 76],   [60, 62, 64, 65, 66, 67, 68, 69, 70, 75],   [58, 59, 61, 66, 70, 73, 74, 75, 76, 77, 78, 79],   [66, 70],   [58, 59, 60, 61, 62, 66, 70, 73, 74, 75, 76, 77, 78, 79]]]
var tonky = "";
var chr_scale = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']

const chord_names = {"Major": [0,4,7], "Minor": [0,3,7], "Major7": [0,4,7,11],
              "Augmented": [0, 4, 8], "Diminished": [0,3,6], "Diminished7": [0,3,6,9],
              "Half-diminished7": [0,3,6,10], "Minor-major7": [0, 3, 7, 11],
              "Augmented7": [0, 4, 8, 10], "Augmented major7": [0, 4, 8, 11],
              "Minor7": [0,3,7,10], "Major6": [0,4,7,9],
              "Minor6": [0,3,7,9], "Dominant7": [0,4,7,10],
              "Sus2": [0,2,7], "Sus4": [0,5,7], "Add9": [0,2,4,7]}
//var chord = 1;
var ffffff = "hoo";
var basic_notes = [];
var raw_list = [];
var NeedsTimingInfo = true;
var noteIn = "";
var basic_notes = [];
var raw_list = [];
function HandleMIDI(e) {
if (e instanceof NoteOn) {
init = e.toString().indexOf('pitch'); //parses out just the note
fin = e.toString().indexOf('vel'); //still parsing
noteIn = (e.toString().substr(init+10,fin-init-13)); //still parsing
basic_notes.push(noteIn);
Trace(basic_notes);
} else if (e instanceof NoteOff) {
	for (i = 0; i < basic_notes.length; i++) {
		init2 = e.toString().indexOf('pitch'); //parses out just the note
		fin2 = e.toString().indexOf('vel'); //still parsing
		if (basic_notes[i] == (e.toString().substr(init2+10,fin2-init2-13))) {
			basic_notes.splice(i, 1);
			Trace(basic_notes);
			break;
			}
 	}
}

for (tonic in basic_notes){
	var tonic_note = basic_notes[tonic];

	var pattern = [];
	for (note in basic_notes){
		var actual_note = basic_notes[note];

		interval = ((chr_scale.indexOf(actual_note) - chr_scale.indexOf(tonic_note)) + 12 ) % 12;
		pattern.push(interval);  
	}
pattern.sort();
	for (const [key, value] of Object.entries(chord_names)) {
		if (JSON.stringify(value) === JSON.stringify(pattern)) {
		basic_notes.length = 0;
		raw_list.length = 0;
		//Trace(tonic_note);
		//Trace(key);
		var ffffff = (tonic_note + key);
		Trace(ffffff);
					if ((ffffff) == "AMajor") {
					chord = 0;
					} else if((ffffff) == "AMajor7"){
					chord = 1;
					} else if((ffffff) == "AMinor"){
					chord = 2;
					} else if((ffffff) == "AMinor7"){
					chord = 3;
					} else if((ffffff) == "A?"){
					chord = 4;
					} else if((ffffff) == "A#Major"){
					chord = 5;
					} else if((ffffff) == "A#Major7"){
					chord = 6;
					} else if((ffffff) == "A#Minor"){
					chord = 7;
					} else if((ffffff) == "A#Minor7"){
					chord = 8;
					} else if((ffffff) == "A#?"){
					chord = 9;
					} else if((ffffff) == "BMajor"){
					chord = 10;
					} else if((ffffff) == "BMajor7"){
					chord = 11;
					} else if((ffffff) == "BMinor"){
					chord = 12;
					} else if((ffffff) == "BMinor7"){
					chord = 13;
					} else if((ffffff) == "B?"){
					chord = 14;
					} else if((ffffff) == "CMajor") {
					chord = 15;
					} else if((ffffff) == "CMajor7"){
					chord = 16;
					} else if((ffffff) == "CMinor"){
					chord = 17;
					} else if((ffffff) == "CMinor7"){
					chord = 18;
					} else if((ffffff) == "C?"){
					chord = 19;
					} else if((ffffff) == "C#Major"){
					chord = 20;
					} else if((ffffff) == "C#Major7"){
					chord = 21;
					} else if((ffffff) == "C#Minor"){
					chord = 22;
					} else if((ffffff) == "C#Minor7"){
					chord = 23;
					} else if((ffffff) == "C#?"){
					chord = 24;
					} else if((ffffff) == "DMajor"){
					chord = 25;
					} else if((ffffff) == "DMajor7"){
					chord = 26;
					} else if((ffffff) == "DMinor"){
					chord = 27;
					} else if((ffffff) == "DMinor7"){
					chord = 28;
					} else if((ffffff) == "D?"){
					chord = 29;
					} else if((ffffff) == "D#Major"){
					chord = 30;
					} else if((ffffff) == "D#Major7"){
					chord = 31;
					} else if((ffffff) == "D#Minor"){
					chord = 32;
					} else if((ffffff) == "D#Minor7"){
					chord = 33;
					} else if((ffffff) == "D#?"){
					chord = 34;
					} else if((ffffff) == "EMajor"){
					chord = 35;
					} else if((ffffff) == "EMajor7"){
					chord = 36;
					} else if((ffffff) == "EMinor"){
					chord = 37;
					} else if((ffffff) == "EMinor7"){
					chord = 38;
					} else if((ffffff) == "E?"){
					chord = 39;
					} else if((ffffff) == "FMajor"){
					chord = 40;
					} else if((ffffff) == "FMajor7"){
					chord = 41;
					} else if((ffffff) == "FMinor"){
					chord = 42;
					} else if((ffffff) == "FMinor7"){
					chord = 43;
					} else if((ffffff) == "F?"){
					chord = 44;
					} else if((ffffff) == "F#Major"){
					chord = 45;
					} else if((ffffff) == "F#Major7"){
					chord = 46;
					} else if((ffffff) == "F#Minor"){
					chord = 47;
					} else if((ffffff) == "F#Minor7"){
					chord = 48;
					} else if((ffffff) == "F#?"){
					chord = 49;
					} else if((ffffff) == "GMajor"){
					chord = 50;
					} else if((ffffff) == "GMajor7"){
					chord = 51;
					} else if((ffffff) == "GMinor"){
					chord = 52;
					} else if((ffffff) == "GMinor7"){
					chord = 53;
					} else if((ffffff) == "G?"){
					chord = 54;
					} else if((ffffff) == "G#Major"){
					chord = 55;
					} else if((ffffff) == "G#Major7"){
					chord = 56;
					} else if((ffffff) == "G#Minor"){
					chord = 57;
					} else if((ffffff) == "G#Minor7"){
					chord = 58;
					} else if((ffffff) == "G#?"){
					chord = 59;
					} else if((ffffff) == "Nerd"){
					chord = 60;
					} else {
					Trace(ffffff);
					basic_notes = [];
					break;}

			var info = GetTimingInfo();
			var chunkstart = (Math.ceil(info.blockStartBeat));
			var column = 0;
			//loop for as many times as there are columns in the chord
			for (diagramColumn = 0; diagramColumn < (all_chords[chord].length); diagramColumn++) {
				var column = column + 0.125;
				for (diagramNote = 0; diagramNote < all_chords[chord][diagramColumn].length; diagramNote++) {
					var noteOn = new NoteOn();
					noteOn.pitch = all_chords[chord][diagramColumn][diagramNote];
					noteOn.velocity = 127; 
					noteOn.sendAtBeat((chunkstart) + column);
					
					var noteOff = new NoteOff();
					noteOff.pitch = all_chords[chord][diagramColumn][diagramNote];
					noteOff.velocity = 127; 
					noteOff.sendAtBeat((chunkstart) + column + 0.12);
}					
}
}
}
}
}

	
	





Link to comment
Share on other sites

How are you generating the piano roll graphics?

 

It's a for loop inside a for loop. So far, the array only has the figures for Major, minor, M7 and m7 chords for all 12 notes. Still need to add to the array for the aug and dim etc chords. It's a LOT of work hahaha.

Link to comment
Share on other sites

here is first observation, you don't need to parse the event.toString stuff you are doing before..Scripter has better access directly to the note names. I simplified that here a bit, which makes it a lot easier to read, its part of why I misinterpreted it earlier... So here is that.... looking at the 7ths now, which you say isn't working?

 

var chr_scale = ['A', 'A#', 'B', 'C', 'C#', 'D',
   'D#', 'E', 'F', 'F#', 'G', 'G#'
]

const chord_names = {
   "Major": [0, 4, 7],
   "Minor": [0, 3, 7],
   "Major7": [0, 4, 7, 11],
   "Augmented": [0, 4, 8],
   "Diminished": [0, 3, 6],
   "Diminished7": [0, 3, 6, 9],
   "Half-diminished7": [0, 3, 6, 10],
   "Minor-major7": [0, 3, 7, 11],
   "Augmented7": [0, 4, 8, 10],
   "Augmented major7": [0, 4, 8, 11],
   "Minor7": [0, 3, 7, 10],
   "Major6": [0, 4, 7, 9],
   "Minor6": [0, 3, 7, 9],
   "Dominant7": [0, 4, 7, 10],
   "Sus2": [0, 2, 7],
   "Sus4": [0, 5, 7],
   "Add9": [0, 2, 4, 7]
}
var noteIn = "";
var basic_notes = [];
var raw_list = [];

function HandleMIDI(e) {

   e.send();

   if (e instanceof NoteOn) {
       basic_notes.push(getNoteName(e));
   } 
   
   else if (e instanceof NoteOff) {
       for (i = 0; i < basic_notes.length; i++) {
           if (basic_notes[i] == getNoteName(e)) {
               basic_notes.splice(i, 1);
               Trace(basic_notes);
               break;
           }
       }
   }

   for (var tonic in basic_notes) {
       var tonic_note = basic_notes[tonic];

       var pattern = [];

       for (note in basic_notes) {
           var actual_note = basic_notes[note];
           interval = ((chr_scale.indexOf(actual_note) - chr_scale.indexOf(tonic_note)) + 12) % 12;
           pattern.push(interval);
       }
       
       pattern.sort();
       
       for (const [key, value] of Object.entries(chord_names)) {
           if (JSON.stringify(value) === JSON.stringify(pattern)) {
               Trace(tonic_note);
               Trace(key);
           }
       }
   }
}

function getNoteName(event) {
   var buf = MIDI.noteName(event.pitch);
   return buf.substr(0, buf.length - 1);

}
Link to comment
Share on other sites

Here is the longer version of your script, more readable as the shorter excerpt.

 

var all_chords = [
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [72, 79],
       [72, 79],
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]
   ],
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 72, 79],
       [37, 38, 39, 45, 72, 79],
       [40, 41, 42, 45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [40, 41, 42, 45, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],
       [47, 48, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61, 72, 79],
       [58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61]
   ],
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 59, 61, 72, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 59, 61]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 72, 79],
       [64, 72, 79],
       [65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78]
   ],
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 72, 79],
       [37, 38, 39, 45, 64, 72, 79],
       [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],
       [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [64, 79],
       [64, 79],
       [65, 78]
   ],
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 65, 78],
       [43, 44, 45]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [54, 55, 65, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [40, 41, 42, 45, 54, 55, 65, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 65, 78],
       [49, 50, 51, 52, 53, 54]
   ],
   [
       [59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 65, 78],
       [59, 61]
   ],
   [
       [45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 78],
       [43, 44, 45, 59, 61]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 79],
       [64, 79],
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]
   ],
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61]
   ],
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 59, 61]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 72, 79],
       [64, 72, 79],
       [64, 72, 79]
   ],
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 72, 79],
       [37, 38, 39, 45, 64, 72, 79],
       [40, 41, 42, 45, 64, 72, 79],
       [43, 44, 45]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [40, 41, 42, 45, 54, 55, 64, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],
       [47, 48, 54, 55, 64, 72, 79],
       [49, 50, 51, 52, 53, 54]
   ],
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [72, 79],
       [72, 79],
       [72, 79]
   ],
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 72, 79],
       [37, 38, 39, 45, 72, 79],
       [40, 41, 42, 45, 72, 79],
       [43, 44, 45]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [40, 41, 42, 45, 54, 55, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],
       [47, 48, 54, 55, 72, 79],
       [49, 50, 51, 52, 53, 54]
   ],
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61, 72, 79],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61]
   ],
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 59, 61, 72, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 72, 79],
       [43, 44, 45, 59, 61]
   ],
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [64, 79],
       [64, 79],
       [64, 72, 79],
       [65, 66, 67, 68, 69, 70, 71, 72]
   ],
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 64, 72, 79],
       [43, 44, 45, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 64, 79],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 79],
       [37, 38, 39, 45, 54, 55, 64, 79],
       [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [43, 44, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54]
   ],
   [
       [53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 64, 72, 79],
       [49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 72, 79],
       [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [59, 61]
   ],
   [
       [45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 72, 79],
       [43, 44, 45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],
       [37, 38, 39, 45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],
       [43, 44, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [53, 54, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
   [
       [58, 59, 60, 61, 62, 74, 75, 76, 77, 78, 79],
       [58, 60, 62, 78],
       [65],
       [58, 59, 60, 61, 62, 76],
       [60, 62, 64, 65, 66, 67, 68, 69, 70, 75],
       [58, 59, 61, 66, 70, 73, 74, 75, 76, 77, 78, 79],
       [66, 70],
       [58, 59, 60, 61, 62, 66, 70, 73, 74, 75, 76, 77, 78, 79]
   ]
]
var tonky = "";
var chr_scale = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']

const chord_names = {
   "Major": [0, 4, 7],
   "Minor": [0, 3, 7],
   "Major7": [0, 4, 7, 11],
   "Augmented": [0, 4, 8],
   "Diminished": [0, 3, 6],
   "Diminished7": [0, 3, 6, 9],
   "Half-diminished7": [0, 3, 6, 10],
   "Minor-major7": [0, 3, 7, 11],
   "Augmented7": [0, 4, 8, 10],
   "Augmented major7": [0, 4, 8, 11],
   "Minor7": [0, 3, 7, 10],
   "Major6": [0, 4, 7, 9],
   "Minor6": [0, 3, 7, 9],
   "Dominant7": [0, 4, 7, 10],
   "Sus2": [0, 2, 7],
   "Sus4": [0, 5, 7],
   "Add9": [0, 2, 4, 7]
}
//var chord = 1;
var ffffff = "hoo";
var basic_notes = [];
var raw_list = [];
var NeedsTimingInfo = true;
var noteIn = "";
var basic_notes = [];
var raw_list = [];

function HandleMIDI(e) {
   if (e instanceof NoteOn) {
       basic_notes.push(getNoteName(e));
       Trace(basic_notes);
   } 
   else if (e instanceof NoteOff) {
       for (i = 0; i < basic_notes.length; i++) {
           if (basic_notes[i] == getNoteName(e)) {
               basic_notes.splice(i, 1);
               Trace(basic_notes);
               break;
           }
       }
   }

   for (tonic in basic_notes) {
       var tonic_note = basic_notes[tonic];

       var pattern = [];
       for (note in basic_notes) {
           var actual_note = basic_notes[note];

           interval = ((chr_scale.indexOf(actual_note) - chr_scale.indexOf(tonic_note)) + 12) % 12;
           pattern.push(interval);
       }
       pattern.sort();
       for (const [key, value] of Object.entries(chord_names)) {
           if (JSON.stringify(value) === JSON.stringify(pattern)) {
               basic_notes.length = 0;
               raw_list.length = 0;
               //Trace(tonic_note);
               //Trace(key);
               var ffffff = (tonic_note + key);
               Trace(ffffff);
               if ((ffffff) == "AMajor") {
                   chord = 0;
               } else if ((ffffff) == "AMajor7") {
                   chord = 1;
               } else if ((ffffff) == "AMinor") {
                   chord = 2;
               } else if ((ffffff) == "AMinor7") {
                   chord = 3;
               } else if ((ffffff) == "A?") {
                   chord = 4;
               } else if ((ffffff) == "A#Major") {
                   chord = 5;
               } else if ((ffffff) == "A#Major7") {
                   chord = 6;
               } else if ((ffffff) == "A#Minor") {
                   chord = 7;
               } else if ((ffffff) == "A#Minor7") {
                   chord = 8;
               } else if ((ffffff) == "A#?") {
                   chord = 9;
               } else if ((ffffff) == "BMajor") {
                   chord = 10;
               } else if ((ffffff) == "BMajor7") {
                   chord = 11;
               } else if ((ffffff) == "BMinor") {
                   chord = 12;
               } else if ((ffffff) == "BMinor7") {
                   chord = 13;
               } else if ((ffffff) == "B?") {
                   chord = 14;
               } else if ((ffffff) == "CMajor") {
                   chord = 15;
               } else if ((ffffff) == "CMajor7") {
                   chord = 16;
               } else if ((ffffff) == "CMinor") {
                   chord = 17;
               } else if ((ffffff) == "CMinor7") {
                   chord = 18;
               } else if ((ffffff) == "C?") {
                   chord = 19;
               } else if ((ffffff) == "C#Major") {
                   chord = 20;
               } else if ((ffffff) == "C#Major7") {
                   chord = 21;
               } else if ((ffffff) == "C#Minor") {
                   chord = 22;
               } else if ((ffffff) == "C#Minor7") {
                   chord = 23;
               } else if ((ffffff) == "C#?") {
                   chord = 24;
               } else if ((ffffff) == "DMajor") {
                   chord = 25;
               } else if ((ffffff) == "DMajor7") {
                   chord = 26;
               } else if ((ffffff) == "DMinor") {
                   chord = 27;
               } else if ((ffffff) == "DMinor7") {
                   chord = 28;
               } else if ((ffffff) == "D?") {
                   chord = 29;
               } else if ((ffffff) == "D#Major") {
                   chord = 30;
               } else if ((ffffff) == "D#Major7") {
                   chord = 31;
               } else if ((ffffff) == "D#Minor") {
                   chord = 32;
               } else if ((ffffff) == "D#Minor7") {
                   chord = 33;
               } else if ((ffffff) == "D#?") {
                   chord = 34;
               } else if ((ffffff) == "EMajor") {
                   chord = 35;
               } else if ((ffffff) == "EMajor7") {
                   chord = 36;
               } else if ((ffffff) == "EMinor") {
                   chord = 37;
               } else if ((ffffff) == "EMinor7") {
                   chord = 38;
               } else if ((ffffff) == "E?") {
                   chord = 39;
               } else if ((ffffff) == "FMajor") {
                   chord = 40;
               } else if ((ffffff) == "FMajor7") {
                   chord = 41;
               } else if ((ffffff) == "FMinor") {
                   chord = 42;
               } else if ((ffffff) == "FMinor7") {
                   chord = 43;
               } else if ((ffffff) == "F?") {
                   chord = 44;
               } else if ((ffffff) == "F#Major") {
                   chord = 45;
               } else if ((ffffff) == "F#Major7") {
                   chord = 46;
               } else if ((ffffff) == "F#Minor") {
                   chord = 47;
               } else if ((ffffff) == "F#Minor7") {
                   chord = 48;
               } else if ((ffffff) == "F#?") {
                   chord = 49;
               } else if ((ffffff) == "GMajor") {
                   chord = 50;
               } else if ((ffffff) == "GMajor7") {
                   chord = 51;
               } else if ((ffffff) == "GMinor") {
                   chord = 52;
               } else if ((ffffff) == "GMinor7") {
                   chord = 53;
               } else if ((ffffff) == "G?") {
                   chord = 54;
               } else if ((ffffff) == "G#Major") {
                   chord = 55;
               } else if ((ffffff) == "G#Major7") {
                   chord = 56;
               } else if ((ffffff) == "G#Minor") {
                   chord = 57;
               } else if ((ffffff) == "G#Minor7") {
                   chord = 58;
               } else if ((ffffff) == "G#?") {
                   chord = 59;
               } else if ((ffffff) == "Nerd") {
                   chord = 60;
               } else {
                   Trace(ffffff);
                   basic_notes = [];
                   break;
               }

               var info = GetTimingInfo();
               var chunkstart = (Math.ceil(info.blockStartBeat));
               var column = 0;
               //loop for as many times as there are columns in the chord
               for (diagramColumn = 0; diagramColumn < (all_chords[chord].length); diagramColumn++) {
                   var column = column + 0.125;
                   for (diagramNote = 0; diagramNote < all_chords[chord][diagramColumn].length; diagramNote++) {
                       var noteOn = new NoteOn();
                       noteOn.pitch = all_chords[chord][diagramColumn][diagramNote];
                       noteOn.velocity = 127;
                       noteOn.sendAtBeat((chunkstart) + column);

                       var noteOff = new NoteOff();
                       noteOff.pitch = all_chords[chord][diagramColumn][diagramNote];
                       noteOff.velocity = 127;
                       noteOff.sendAtBeat((chunkstart) + column + 0.12);
                   }
               }
           }
       }
   }
}

function getNoteName(event) {
   var buf = MIDI.noteName(event.pitch);
   return buf.substr(0, buf.length - 1);

}

 

its a pretty clever little script, send it over IAC to another track and get your chord chart. Cool!

 

(note a suggestion you might also consider is looking into meta events in the environment, it may be possible to send a CC event over IAC instead of notes. Then in the environment convert that into meta-events corresponding to chords in the LogicPro score editor. ). Just a thought.

 

So you say you're having problems with 7ths?

Link to comment
Share on other sites

here's a little simplified, just some javascript stuff. There are probably more opportunities for a bit more simplification and cleanup, but for now this is good enough. I'll try to have a look at 7th chords...

 

var NeedsTimingInfo = true;

var tonky = "";
var basic_notes = [];
var raw_list = [];

Event.prototype.noteName = function() {
   var buf = MIDI.noteName(this.pitch);
   return buf.substr(0, buf.length - 1);
};


function HandleMIDI(e) {
   if (e instanceof NoteOn) {
       basic_notes.push(e.noteName());
       Trace(basic_notes);
   } 
   else if (e instanceof NoteOff) {
       for (i = 0; i < basic_notes.length; i++) {
           if (basic_notes[i] == e.noteName()) {
               basic_notes.splice(i, 1);
               Trace(basic_notes);
               break;
           }
       }
   }

   for (tonic in basic_notes) {
       var tonic_note = basic_notes[tonic];

       var pattern = [];
       for (note in basic_notes) {
           var actual_note = basic_notes[note];

           interval = ((chr_scale.indexOf(actual_note) - chr_scale.indexOf(tonic_note)) + 12) % 12;
           pattern.push(interval);
       }
       
       pattern.sort();

       for (const [key, value] of Object.entries(chord_names)) {
           if (JSON.stringify(value) === JSON.stringify(pattern)) {
               basic_notes.length = 0;
               raw_list.length = 0;
               //Trace(tonic_note);
               //Trace(key);
               var chord = (tonic_note + key);
               Trace(chord);

               var info = GetTimingInfo();
               var chunkstart = (Math.ceil(info.blockStartBeat));
               var column = 0;
               //loop for as many times as there are columns in the chord
               for (diagramColumn = 0; diagramColumn < (all_chords[chord].length); diagramColumn++) {
                   var column = column + 0.125;
                   for (diagramNote = 0; diagramNote < all_chords[chord][diagramColumn].length; diagramNote++) {
                       var noteOn = new NoteOn();
                       noteOn.pitch = all_chords[chord][diagramColumn][diagramNote];
                       noteOn.velocity = 127;
                       noteOn.sendAtBeat((chunkstart) + column);

                       var noteOff = new NoteOff();
                       noteOff.pitch = all_chords[chord][diagramColumn][diagramNote];
                       noteOff.velocity = 127;
                       noteOff.sendAtBeat((chunkstart) + column + 0.12);
                   }
               }
           }
       }
   }
}


var chr_scale = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']

const chord_names = {
   "Major": [0, 4, 7],
   "Minor": [0, 3, 7],
   "Major7": [0, 4, 7, 11],
   "Augmented": [0, 4, 8],
   "Diminished": [0, 3, 6],
   "Diminished7": [0, 3, 6, 9],
   "Half-diminished7": [0, 3, 6, 10],
   "Minor-major7": [0, 3, 7, 11],
   "Augmented7": [0, 4, 8, 10],
   "Augmented major7": [0, 4, 8, 11],
   "Minor7": [0, 3, 7, 10],
   "Major6": [0, 4, 7, 9],
   "Minor6": [0, 3, 7, 9],
   "Dominant7": [0, 4, 7, 10],
   "Sus2": [0, 2, 7],
   "Sus4": [0, 5, 7],
   "Add9": [0, 2, 4, 7]
};

var all_chords = {
"AMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [72, 79],
       [72, 79],
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]
   ],
"AMajor7" :     
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 72, 79],
       [37, 38, 39, 45, 72, 79],
       [40, 41, 42, 45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],

"AMinor" :     
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"AMinor7" :     
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [40, 41, 42, 45, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"A?" : 
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],
       [47, 48, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"A#Major" :     
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61, 72, 79],
       [58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61]
   ],
"A#Major7" :     
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 59, 61, 72, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 59, 61]
   ],
"A#Minor" :     
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"A#Minor7" :     
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"A#?" :
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"BMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 72, 79],
       [64, 72, 79],
       [65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78]
   ],
"BMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 72, 79],
       [37, 38, 39, 45, 64, 72, 79],
       [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
"BMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"BMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"B?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],
       [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"CMajor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [64, 79],
       [64, 79],
       [65, 78]
   ],
"CMajor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 65, 78],
       [43, 44, 45]
   ],
"CMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [54, 55, 65, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"CMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [40, 41, 42, 45, 54, 55, 65, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"C?" :
   [
       [53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 65, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"C#Major" :
   [
       [59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 65, 78],
       [59, 61]
   ],
"C#Major7" :
   [
       [45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 78],
       [43, 44, 45, 59, 61]
   ],
"C#Minor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"C#Minor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"C#?" :
   [
       [53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"DMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 79],
       [64, 79],
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]
   ],
"DMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
"DMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"DMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"D?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"D#Major" :
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61]
   ],
"D#Major7" :
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 59, 61]
   ],
"D#Minor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"D#Minor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"D#?" :
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"EMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 72, 79],
       [64, 72, 79],
       [64, 72, 79]
   ],
"EMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 72, 79],
       [37, 38, 39, 45, 64, 72, 79],
       [40, 41, 42, 45, 64, 72, 79],
       [43, 44, 45]
   ],
"EMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"EMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [40, 41, 42, 45, 54, 55, 64, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"E?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],
       [47, 48, 54, 55, 64, 72, 79],
       [49, 50, 51, 52, 53, 54]
   ],
"FMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [72, 79],
       [72, 79],
       [72, 79]
   ],
"FMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 72, 79],
       [37, 38, 39, 45, 72, 79],
       [40, 41, 42, 45, 72, 79],
       [43, 44, 45]
   ],
"FMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"FMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [40, 41, 42, 45, 54, 55, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"F?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],
       [47, 48, 54, 55, 72, 79],
       [49, 50, 51, 52, 53, 54]
   ],
"F#Major" :
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61, 72, 79],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61]
   ],
"F#Major7" :
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 59, 61, 72, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 72, 79],
       [43, 44, 45, 59, 61]
   ],
"F#Minor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"F#Minor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"F#?" :
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"GMajor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [64, 79],
       [64, 79],
       [64, 72, 79],
       [65, 66, 67, 68, 69, 70, 71, 72]
   ],
"GMajor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 64, 72, 79],
       [43, 44, 45, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
"GMinor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 64, 79],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"GMinor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 79],
       [37, 38, 39, 45, 54, 55, 64, 79],
       [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [43, 44, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"G?" :
   [
       [53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 64, 72, 79],
       [49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
"G#Major" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 72, 79],
       [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [59, 61]
   ],
"G#Major7" :
   [
       [45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 72, 79],
       [43, 44, 45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
"G#Minor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"G#Minor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],
       [37, 38, 39, 45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],
       [43, 44, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"G#?" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [53, 54, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"Nerd" :
   [
       [58, 59, 60, 61, 62, 74, 75, 76, 77, 78, 79],
       [58, 60, 62, 78],
       [65],
       [58, 59, 60, 61, 62, 76],
       [60, 62, 64, 65, 66, 67, 68, 69, 70, 75],
       [58, 59, 61, 66, 70, 73, 74, 75, 76, 77, 78, 79],
       [66, 70],
       [58, 59, 60, 61, 62, 66, 70, 73, 74, 75, 76, 77, 78, 79]
   ]
};
Link to comment
Share on other sites

Looks like the pattern.sort() method you are calling is sorting alphateticaslly rather then numerically so 11 comes before 4 and 7 and thus it never matches the 7th chords.

 

In order to sort an array numerically you have to create a number sorting function to use, like this:

 

function sortNumber(a, b) {
 return a - b;
}

 

Then you call pattern.sort like this:

 

 pattern.sort(sortNumber);
 

 

The end result will be this:

 

chords.thumb.jpg.e89164a8a819647b83de1178a9f6c6d4.jpg

 

here is the complete code:

 

var NeedsTimingInfo = true;

var tonky = "";
var basic_notes = [];
var raw_list = [];

Event.prototype.noteName = function() {
   var buf = MIDI.noteName(this.pitch);
   return buf.substr(0, buf.length - 1);
};

function HandleMIDI(e) {
   if (e instanceof NoteOn) {
       basic_notes.push(e.noteName());
   } 
   else if (e instanceof NoteOff) {
       for (i = 0; i < basic_notes.length; i++) {
           if (basic_notes[i] == e.noteName()) {
               basic_notes.splice(i, 1);
               break;
           }
       }
   }
   
   for (tonic in basic_notes) {
       var tonic_note = basic_notes[tonic];

       var pattern = [];
       for (note in basic_notes) {
           var actual_note = basic_notes[note];
           interval = ((chr_scale.indexOf(actual_note) - chr_scale.indexOf(tonic_note)) + 12) % 12;
           pattern.push(interval);
       }
       
       pattern.sort(sortNumber);
       
       for (const [key, value] of Object.entries(chord_names)) {
           if (JSON.stringify(value) === JSON.stringify(pattern)) {
               basic_notes.length = 0;
               raw_list.length = 0;
               var chord = (tonic_note + key);

               var info = GetTimingInfo();
               var chunkstart = (Math.ceil(info.blockStartBeat));
               var column = 0;
               //loop for as many times as there are columns in the chord
               for (diagramColumn = 0; diagramColumn < (all_chords[chord].length); diagramColumn++) {
                   var column = column + 0.125;
                   for (diagramNote = 0; diagramNote < all_chords[chord][diagramColumn].length; diagramNote++) {
                       var noteOn = new NoteOn();
                       noteOn.pitch = all_chords[chord][diagramColumn][diagramNote];
                       noteOn.velocity = 127;
                       noteOn.sendAtBeat((chunkstart) + column);

                       var noteOff = new NoteOff();
                       noteOff.pitch = all_chords[chord][diagramColumn][diagramNote];
                       noteOff.velocity = 127;
                       noteOff.sendAtBeat((chunkstart) + column + 0.12);
                   }
               }
           }
       }
   }
}

function sortNumber(a, b) {
 return a - b;
}

var chr_scale = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']

const chord_names = {
   "Major": [0, 4, 7],
   "Minor": [0, 3, 7],
   "Major7": [0, 4, 7, 11],
   "Augmented": [0, 4, 8],
   "Diminished": [0, 3, 6],
   "Diminished7": [0, 3, 6, 9],
   "Half-diminished7": [0, 3, 6, 10],
   "Minor-major7": [0, 3, 7, 11],
   "Augmented7": [0, 4, 8, 10],
   "Augmented major7": [0, 4, 8, 11],
   "Minor7": [0, 3, 7, 10],
   "Major6": [0, 4, 7, 9],
   "Minor6": [0, 3, 7, 9],
   "Dominant7": [0, 4, 7, 10],
   "Sus2": [0, 2, 7],
   "Sus4": [0, 5, 7],
   "Add9": [0, 2, 4, 7]
};

var all_chords = {
"AMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [72, 79],
       [72, 79],
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]
   ],
"AMajor7" :     
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 72, 79],
       [37, 38, 39, 45, 72, 79],
       [40, 41, 42, 45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],

"AMinor" :     
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"AMinor7" :     
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [40, 41, 42, 45, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"A?" : 
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],
       [47, 48, 54, 55, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"A#Major" :     
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61, 72, 79],
       [58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61]
   ],
"A#Major7" :     
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 59, 61, 72, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 59, 61]
   ],
"A#Minor" :     
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"A#Minor7" :     
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"A#?" :
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"BMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 72, 79],
       [64, 72, 79],
       [65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78]
   ],
"BMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 72, 79],
       [37, 38, 39, 45, 64, 72, 79],
       [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
"BMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"BMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"B?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],
       [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"CMajor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [64, 79],
       [64, 79],
       [65, 78]
   ],
"CMajor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 65, 78],
       [43, 44, 45]
   ],
"CMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [54, 55, 65, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"CMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [40, 41, 42, 45, 54, 55, 65, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"C?" :
   [
       [53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 65, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"C#Major" :
   [
       [59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 65, 78],
       [59, 61]
   ],
"C#Major7" :
   [
       [45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 78],
       [43, 44, 45, 59, 61]
   ],
"C#Minor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"C#Minor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"C#?" :
   [
       [53, 54, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"DMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 79],
       [64, 79],
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]
   ],
"DMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45]
   ],
"DMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"DMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 79],
       [40, 41, 42, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"D?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54]
   ],
"D#Major" :
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61]
   ],
"D#Major7" :
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 59, 61]
   ],
"D#Minor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"D#Minor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"D#?" :
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"EMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [64, 72, 79],
       [64, 72, 79],
       [64, 72, 79]
   ],
"EMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 64, 72, 79],
       [37, 38, 39, 45, 64, 72, 79],
       [40, 41, 42, 45, 64, 72, 79],
       [43, 44, 45]
   ],
"EMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 64, 72, 79],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"EMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 64, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [40, 41, 42, 45, 54, 55, 64, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"E?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 64, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 72, 79],
       [47, 48, 54, 55, 64, 72, 79],
       [49, 50, 51, 52, 53, 54]
   ],
"FMajor" :
   [
       [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [72, 79],
       [72, 79],
       [72, 79]
   ],
"FMajor7" :
   [
       [45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 72, 79],
       [37, 38, 39, 45, 72, 79],
       [40, 41, 42, 45, 72, 79],
       [43, 44, 45]
   ],
"FMinor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [54, 55, 72, 79],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"FMinor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 72, 79],
       [40, 41, 42, 45, 54, 55, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54]
   ],
"F?" :
   [
       [53, 54, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 72, 79],
       [47, 48, 54, 55, 72, 79],
       [49, 50, 51, 52, 53, 54]
   ],
"F#Major" :
   [
       [59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61, 72, 79],
       [58, 59, 60, 61, 62, 72, 79],
       [59, 61]
   ],
"F#Major7" :
   [
       [45, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 59, 61, 72, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 72, 79],
       [43, 44, 45, 59, 61]
   ],
"F#Minor" :
   [
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"F#Minor7" :
   [
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [37, 38, 39, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 72, 79],
       [40, 41, 42, 45, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [43, 44, 45, 48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"F#?" :
   [
       [53, 54, 59, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [54, 55, 58, 59, 60, 61, 62, 72, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 72, 79],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"GMajor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [64, 79],
       [64, 79],
       [64, 72, 79],
       [65, 66, 67, 68, 69, 70, 71, 72]
   ],
"GMajor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 64, 79],
       [37, 38, 39, 45, 64, 79],
       [40, 41, 42, 45, 64, 72, 79],
       [43, 44, 45, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
"GMinor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 64, 79],
       [54, 55, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [54, 55, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"GMinor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 48, 49, 50, 51, 52, 53, 54, 64, 79],
       [37, 38, 39, 45, 54, 55, 64, 79],
       [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 64, 72, 79],
       [43, 44, 45, 54, 55, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54]
   ],
"G?" :
   [
       [53, 54, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [54, 55, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 64, 79],
       [47, 48, 54, 55, 64, 72, 79],
       [49, 50, 51, 52, 53, 54, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
"G#Major" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [59, 61, 64, 79],
       [58, 59, 60, 61, 62, 64, 79],
       [59, 61, 64, 72, 79],
       [58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [59, 61]
   ],
"G#Major7" :
   [
       [45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 58, 59, 60, 61, 62, 64, 79],
       [37, 38, 39, 45, 59, 61, 64, 79],
       [40, 41, 42, 45, 58, 59, 60, 61, 62, 64, 72, 79],
       [43, 44, 45, 59, 61, 65, 66, 67, 68, 69, 70, 71, 72]
   ],
"G#Minor" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],
       [54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"G#Minor7" :
   [
       [45, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [45, 48, 49, 50, 51, 52, 53, 54, 59, 61, 64, 79],
       [37, 38, 39, 45, 54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 42, 45, 48, 49, 50, 51, 52, 53, 54, 55, 59, 61, 64, 72, 79],
       [43, 44, 45, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [48, 49, 50, 51, 52, 53, 54, 59, 61]
   ],
"G#?" :
   [
       [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78],
       [53, 54, 59, 61, 64, 79],
       [54, 55, 58, 59, 60, 61, 62, 64, 79],
       [40, 41, 44, 45, 46, 47, 54, 55, 59, 61, 64, 72, 79],
       [47, 48, 54, 55, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71, 72],
       [49, 50, 51, 52, 53, 54, 59, 61]
   ],
"Nerd" :
   [
       [58, 59, 60, 61, 62, 74, 75, 76, 77, 78, 79],
       [58, 60, 62, 78],
       [65],
       [58, 59, 60, 61, 62, 76],
       [60, 62, 64, 65, 66, 67, 68, 69, 70, 75],
       [58, 59, 61, 66, 70, 73, 74, 75, 76, 77, 78, 79],
       [66, 70],
       [58, 59, 60, 61, 62, 66, 70, 73, 74, 75, 76, 77, 78, 79]
   ]
};
Link to comment
Share on other sites

ps - look into using meta event 60. That will add text objects to the score. This could possibly be used to add chord symbols to the score page instead of through recording to a region with the fancy code you got from python. But scripted would have to send some CC over IAC..and then when receiving it, convert that back to the meta event. There might be a different meta event that directly hits the score chord grid, but I don't know what it is, and LogicPro information about all meta events possible is hard to find,..
Link to comment
Share on other sites

First of all, the cleanup with the all_chords array was astonishing. It cut the size of the script in half. That's a trick I'll never forget.

 

My only remaining issue, outside of creating graphics for all the chord types, is that it seems note ons are read from bottom to top as the piano roll is viewed. So I have to put the 7 on the bottom of the chord in the piano roll. If it's not, as it iterates through the possible patterns, as soon as it hits a triad, it assumes it found the chord without further comparisons.

 

1431216236_ScreenShot2020-01-08at4_43_45AM.png.746f0fae3985c131952cb28c9c49415e.png

 

1302048823_ScreenShot2020-01-08at4_43_01AM.png.578484e9052baab2b3836966edc94540.png

 

Would I be incorrect thinking the pattern could be called through a function so all 3 intervals are present for comparison rather than the 2 in a triad? My only issue with that is having the HandleMIDI() called from within another function.

 

Oh yeah, and I had to fix the Major7s in the array, as they're actually Dominant7s... oops.

Link to comment
Share on other sites

You should not call handleMidi directly. You can create a sub function that is called both by handle midi and anywhere else you want.

 

As far as how the chord detection works in that script I will try to take a closer look at it later. It’s certainly doable it’s just a matter of how it keeps track of things. You can use global variables to track values across multiple calls to handlemidi. I didn’t try that hard to understand how that nested for loop works exactly it was a little difficult to follow; but I’m sure it can be done.

 

Also note the chord symbols can happen AFTER the notes of the chord which is probably not desireable. That’s because it doesn’t know what the chord is until I guess the chord is released.

Link to comment
Share on other sites

  • 3 years later...

Hey guys, I don't know if anyone is still on here, but I'm using the complete code for the Chord Analysis and I'm getting an error on Line 47 (for (diagramColumn = 0; diagramColumn < (all_chords[chord].length); diagramColumn++) {) when recording the chords on an empty track. I'm not good with Scripter and was looking for some assistance with this. I also provided a screenshot show you guys on what I'm having trouble with...

Screen Shot 2023-02-21 at 11.18.49 PM.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...