From fa8a12128ba24bcbc77c9327ee37142fb3de815f Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Thu, 12 May 2022 14:32:51 -0500 Subject: [PATCH] working on procedural gen --- src/vector_logic/getProceduralPitches.js | 26 +++++++- src/vector_logic/getRandomPitches.js | 5 +- src/vector_logic/helper.js | 80 ++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 src/vector_logic/helper.js diff --git a/src/vector_logic/getProceduralPitches.js b/src/vector_logic/getProceduralPitches.js index 0a542f1..bd9c5e6 100644 --- a/src/vector_logic/getProceduralPitches.js +++ b/src/vector_logic/getProceduralPitches.js @@ -1,5 +1,6 @@ -import { pitchsets } from "../harmonyUtil.js"; +import { pitchsets, musicalPitches } from "../harmonyUtil.js"; import { extractPitchName } from "./extractPitchName.js"; +import { getRandomIndex } from "./getRandomPitches.js"; // an additional method based on the structure of getRandomPitches, // but taking some principles of music theory into account. @@ -14,7 +15,7 @@ export const getProceduralPitches = (prevPitches) => { while (pitches.length <= pitchsets.indexOf(voice)) { // the first section of this while loop is more free. - index = Math.floor(Math.random() * 100) % voice.length; + index = getRandomIndex(voice); formattedPitch = extractPitchName(voice[index]); // this initial condition will apply only to the bass voice, @@ -23,7 +24,26 @@ export const getProceduralPitches = (prevPitches) => { } else { // now we need some repeating logic for the remaining four voices while (pitches.length !== (pitchsets.indexOf(voice) + 1)) { - pitches.push(pitchsets.indexOf(voice)); + index = getRandomIndex(voice); + pitches.push(voice[index]); + + + for (let i = 0; i < pitches.length; i++) { + let numVals = []; + + for (let j = i; j < i + 2; j++) { + console.log(pitches[j]); + let extracted = extractPitchName(pitches[j]); + numVals.push(musicalPitches.indexOf(extracted) + 1); + } + + let difference = Math.abs(numVals.reduce((x,y) => x - y)); + if (difference === 1 || difference === 6) { + pitches.pop(); + } else { + continue; + } + } } } } diff --git a/src/vector_logic/getRandomPitches.js b/src/vector_logic/getRandomPitches.js index a041b44..fb31de6 100644 --- a/src/vector_logic/getRandomPitches.js +++ b/src/vector_logic/getRandomPitches.js @@ -1,6 +1,9 @@ import { pitchsets } from "../harmonyUtil.js"; import { extractPitchName } from "./extractPitchName.js"; +// helper function for assigning a random index for a given voice's pitchset +export const getRandomIndex = (voice) => Math.floor(Math.random() * 100) % voice.length; + export const getRandomPitches = () => { // pitches stored in Tone.js string format let pitches = []; @@ -13,7 +16,7 @@ export const getRandomPitches = () => { // loops until four distinct chord members are received while (formattedPitches.length <= pitchsets.indexOf(voice)) { - index = Math.floor(Math.random() * 100) % voice.length; + index = getRandomIndex(voice); formattedPitch = extractPitchName(voice[index]); if (!formattedPitches.includes(formattedPitch)) { diff --git a/src/vector_logic/helper.js b/src/vector_logic/helper.js new file mode 100644 index 0000000..77fd2d9 --- /dev/null +++ b/src/vector_logic/helper.js @@ -0,0 +1,80 @@ +import { pitchsets, musicalPitches } from '../harmonyUtil.js'; +import { extractPitchName } from './extractPitchName.js'; +import { getRandomIndex } from './getRandomPitches.js'; + +const iteratePitchsets = () => { + let pitches = []; + let result = []; + + const tryNewPitch = () => { + result = []; + + for (let voice of pitchsets) { + let idx = getRandomIndex(voice); + let pitchNum = musicalPitches.indexOf(extractPitchName(voice[idx])); + + pitches.push([pitchNum, voice[idx]]); + } + + console.log(pitches); + + for (let i = 0; i < pitches.length; i++) { + for (let j = i; j < pitches.length; j++) { + let difference = Math.abs(pitches[i][0] - pitches[j][0]); + if (difference === 1 || difference === 6) { + result.push(["BAD", [i, j], pitches[i], pitches[j]]); + } else { + result.push(["GOOD", [i, j], pitches[i], pitches[j]]); + } + } + } + console.log(result); + } + + tryNewPitch(); + + for (let entry in result) { + if (entry[0] === "BAD") { + iteratePitchsets(); + } + } + + console.log(pitches); +} + +iteratePitchsets(); + + + +function twoPointIteration() { + let caught = false; + let data = [1,2,3,4,5,6]; + + for (let i = 0; i < data.length; i++) { + console.log(data[i]); + for (let j = 0; j < data.length; j++) { + if (data[i] === data[j]) continue; + + let difference = Math.abs(data[j] - data[i]); + + if (difference === 3) { + difference = "caught: 3"; + } + + console.log([difference, [data[i], data[j]]]); + } + + console.log('next'); + } + + return caught; +} + +function selfReferentialPointer() { + for (let i = 0; i < 5; i++) { + console.log(`i: ${i}`); + for (let j = i; j < i+2; j++) { + console.log(`jjjjjjj: ${j % 3}`); + } + } +}