-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.js
More file actions
51 lines (44 loc) · 2.04 KB
/
connect.js
File metadata and controls
51 lines (44 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const HarmonicConnect = require('./hConnect.js');
exports.connect = function (song1, song2) {
//RATIO num chords/max jump --> hight ratio is smooth, low is bold
let boldSmoothValue = document.getElementById('boldSmooth').value;
//Run each modulation --> matrix, each row are the chords of the modulation
//Create 2 vectors with index realtive to a modulation: # of chords, max jump in key
let modMatrix = [];
modMatrix.push(HarmonicConnect.diaMod(song1, song2));
modMatrix.push(HarmonicConnect.pivotChord(song1, song2));
modMatrix.push(HarmonicConnect.noChordModulation(song1, song2));
modMatrix.push(HarmonicConnect.deceptiveCadenceEx(song1, song2));
modMatrix.push(HarmonicConnect.chainModulation(song1, song2));
modMatrix.push(HarmonicConnect.parallelMod(song1, song2));
modMatrix.push(HarmonicConnect.dimSevenDomSeven(song1, song2));
modMatrix.push(HarmonicConnect.enharmonicDominant(song1, song2));
modMatrix.push(HarmonicConnect.enharmonicDimSeven(song1, song2));
console.log('modMatrix:', modMatrix);
let doableMods = modMatrix.filter((mod) => mod.maxJump != 100);
let allZero = true;
for (let i = 0; i < doableMods.length; i++) {
if (doableMods[i].maxJump !== 0) allZero = false;
}
if (allZero) doableMods.forEach((mod) => (mod.maxJump = mod.maxJump + 1));
let ratios = doableMods.map((mod) => mod.maxJump / mod.chords.length);
let maxNorm = Math.max(...ratios);
let ratiosNorm;
if (maxNorm != 0) ratiosNorm = ratios.map((ratio) => ratio / maxNorm);
else {
ratiosNorm = ratios.map((ratio) => ratio);
}
let distances = ratiosNorm.map((ratio) => Math.abs(ratio - boldSmoothValue));
let minIndex = distances.indexOf(Math.min(...distances));
console.log(boldSmoothValue);
console.log(distances);
let harmonicConnectChords = [];
doableMods[minIndex].chords.forEach((chord) => {
let temp = [];
temp.push(chord);
harmonicConnectChords.push(temp);
});
let spanCurrMod = document.getElementById('currentMod');
spanCurrMod.textContent = doableMods[minIndex].name;
return harmonicConnectChords;
};