cleaning up some code

This commit is contained in:
Mikayla Dobson
2022-05-15 12:14:17 -05:00
parent cc6acfcd46
commit fe5aa39539
3 changed files with 8 additions and 35 deletions

View File

@@ -59,7 +59,7 @@ export const getProceduralPitches = () => {
console.log(`call count: ${callCount}`); console.log(`call count: ${callCount}`);
callCount = 0; callCount = 0;
console.log(pitches); console.log(pitches);
melodicGeneration(pitches); let next = melodicGeneration(pitches);
return pitches; return pitches;
} }
} }

View File

@@ -1,3 +1,3 @@
import { melodicGeneration } from "./melodicGeneration.js"; import { melodicGeneration } from "./melodicGeneration.js";
melodicGeneration(['C3', 'G3', 'A3', 'E5']); melodicGeneration(['C3', 'G3', 'A3', 'G5']);

View File

@@ -6,18 +6,11 @@ import { musicalPitches, pitchsets } from '../harmonyUtil.js';
// reads the pitch of the previous sonority and determines appropriate melodic movement for the soprano // reads the pitch of the previous sonority and determines appropriate melodic movement for the soprano
// returns a boolean which triggers a recursive call if the interval received is out of expected values // returns a boolean which triggers a recursive call if the interval received is out of expected values
let callCount = 0;
export const melodicGeneration = (prevPitches) => { export const melodicGeneration = (prevPitches) => {
console.clear();
callCount++;
// direction: boolean; true refers to ascending motion; false refers to descending motion // direction: boolean; true refers to ascending motion; false refers to descending motion
let direction; let direction;
let isMelodic = true; let isMelodic = true;
const preferredMotion = [0,1,2,3,4,12]; const preferredMotion = [0,1,2,3,4,12];
const sopranoLength = pitchsets[3].length;
let newPitches = getRandomPitches(); let newPitches = getRandomPitches();
@@ -37,19 +30,13 @@ export const melodicGeneration = (prevPitches) => {
let interval = pitchNumOne - pitchNumTwo; let interval = pitchNumOne - pitchNumTwo;
console.log(prevSoprano, newSoprano);
console.log(pitchNumOne, pitchNumTwo);
// when the octave number is the same // when the octave number is the same
if (octaveOne === octaveTwo) { if (octaveOne === octaveTwo) {
console.log("OCTAVE: same");
if (pitchNumOne === pitchNumTwo) { if (pitchNumOne === pitchNumTwo) {
interval = 0; interval = 0;
} else if (pitchNumTwo === 0) { } else if (pitchNumTwo === 0) {
interval = 12 - pitchNumOne; interval = 12 - pitchNumOne;
} else if (pitchNumOne > pitchNumTwo) { } else if (pitchNumOne > pitchNumTwo) {
console.log("WRAP");
interval = pitchNumTwo - pitchNumOne; interval = pitchNumTwo - pitchNumOne;
} else if (pitchNumOne < pitchNumTwo) { } else if (pitchNumOne < pitchNumTwo) {
interval *= -1; interval *= -1;
@@ -58,7 +45,6 @@ export const melodicGeneration = (prevPitches) => {
// when the first octave number is higher // when the first octave number is higher
if (octaveOne > octaveTwo) { if (octaveOne > octaveTwo) {
console.log('OCTAVE: first is higher');
if (pitchNumOne === pitchNumTwo) { if (pitchNumOne === pitchNumTwo) {
interval = 0; interval = 0;
} else if (pitchNumTwo === 0) { } else if (pitchNumTwo === 0) {
@@ -67,31 +53,23 @@ export const melodicGeneration = (prevPitches) => {
const wrapperCheckOne = (pitchNumOne + 9) % 12; const wrapperCheckOne = (pitchNumOne + 9) % 12;
const wrapperCheckTwo = (pitchNumTwo + 9) % 12; const wrapperCheckTwo = (pitchNumTwo + 9) % 12;
console.log("---------------"); if (interval !== (wrapperCheckOne - wrapperCheckTwo)) {
console.log("PROBLEMS HERE"); interval *= -1;
console.log(`interval: ${interval}`); } else {
console.log(`adjusted pitch idx of first pitch: ${wrapperCheckOne}`);
console.log(`adjusted pitch idx of second pitch: ${wrapperCheckTwo}`);
console.log("---------------");
interval = pitchNumTwo - pitchNumOne - 12; interval = pitchNumTwo - pitchNumOne - 12;
}
} else if (pitchNumOne < pitchNumTwo) { } else if (pitchNumOne < pitchNumTwo) {
console.log("caught");
interval = (interval + 12) * -1; interval = (interval + 12) * -1;
} else { } else {
console.log("NO CONDITION APPLIES"); console.log("NO CONDITION APPLIES");
} }
// when the second octave number is higher // when the second octave number is higher
} else if (octaveOne < octaveTwo) { } else if (octaveOne < octaveTwo) {
console.log('OCTAVE: second is higher');
if (pitchNumOne > pitchNumTwo) { if (pitchNumOne > pitchNumTwo) {
console.log("WRAP");
interval = 12 - Math.abs(interval); interval = 12 - Math.abs(interval);
} else if (pitchNumOne < pitchNumTwo) { } else if (pitchNumOne < pitchNumTwo) {
interval *= -1; interval *= -1;
} else if (pitchNumTwo === 0) { } else if (pitchNumTwo === 0) {
console.log("Edge case: pitch two = 0");
interval = (12 - pitchNumOne) + 12; interval = (12 - pitchNumOne) + 12;
} }
} }
@@ -105,10 +83,5 @@ export const melodicGeneration = (prevPitches) => {
isMelodic = false; isMelodic = false;
} }
console.log(`interval: ${interval}`); return isMelodic;
console.log(`direction: ${direction ? 'ascending' : 'descending'}`);
console.log(`isMelodic: ${isMelodic}`);
console.log(`melody call count: ${callCount}`);
callCount = 0;
} }