working out some harmony logic

This commit is contained in:
Mikayla Dobson
2022-05-09 19:31:12 -05:00
parent 4e095c2af6
commit a96fc8e278
3 changed files with 66 additions and 1 deletions

64
js/harmonyUtil.js Normal file
View File

@@ -0,0 +1,64 @@
import { extractPitchset } from "./toneGeneration.js";
// interval definitions:
const intervals = {
0: "unison",
1: "minor second",
2: "major second",
3: "minor third",
4: "major third",
5: "perfect fourth",
6: "tritone"
// all intervals beyond this invert to one of the previous intervals
}
// helper functions
const transposePitches = (pitchNames, interval) => {
let transposed = [];
pitchNames.forEach(pitch => transposed.push((pitch + interval) % 12));
return transposed;
}
const findVector = (pitches) => {
let sorted = pitches.sort((x,y) => x - y);
// sorted = sorted.filter((num, idx) => {
// return sorted.indexOf(num) === idx;
// });
// finds each interval and logs it as a duple
let intervalClasses = [];
for (let i = 0; i < sorted.length; i++) {
let j = i+1;
// does not allow out of range values in the proceeding loop
if (j >= sorted.length) {
break;
}
do {
let thing = (sorted[j] - sorted[i]) % 6
if (!(intervalClasses.includes(thing))) {
intervalClasses.push(thing);
}
j++;
} while (j < sorted.length);
}
intervalClasses = intervalClasses.sort((x,y) => x-y);
return intervalClasses;
}
// analysis
let dMajor = extractPitchset(["D", "F#", "A", "D"]);
const eMajor = transposePitches(dMajor, 2);
console.log(eMajor);
console.log('');
let dMajVector = findVector(dMajor);
console.log(dMajVector);
let complexVector = findVector([0,3,4,7,8,11]);
console.log(complexVector);
let splitThird = findVector([0,3,4,7]);
console.log(splitThird);

View File

@@ -28,7 +28,7 @@ export const extractPitchset = (pitches) => {
pitchset.sort((a,b) => a < b); pitchset.sort((a,b) => a < b);
console.log(pitchset); console.log(pitchset);
// return pitchset;
} }
// no tritones // no tritones

View File

@@ -1,5 +1,6 @@
{ {
"name": "tone", "name": "tone",
"type": "module",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "app.js", "main": "app.js",