working on procedural gen
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { pitchsets } from "../harmonyUtil.js";
|
import { pitchsets, musicalPitches } from "../harmonyUtil.js";
|
||||||
import { extractPitchName } from "./extractPitchName.js";
|
import { extractPitchName } from "./extractPitchName.js";
|
||||||
|
import { getRandomIndex } from "./getRandomPitches.js";
|
||||||
|
|
||||||
// an additional method based on the structure of getRandomPitches,
|
// an additional method based on the structure of getRandomPitches,
|
||||||
// but taking some principles of music theory into account.
|
// but taking some principles of music theory into account.
|
||||||
@@ -14,7 +15,7 @@ export const getProceduralPitches = (prevPitches) => {
|
|||||||
|
|
||||||
while (pitches.length <= pitchsets.indexOf(voice)) {
|
while (pitches.length <= pitchsets.indexOf(voice)) {
|
||||||
// the first section of this while loop is more free.
|
// 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]);
|
formattedPitch = extractPitchName(voice[index]);
|
||||||
|
|
||||||
// this initial condition will apply only to the bass voice,
|
// this initial condition will apply only to the bass voice,
|
||||||
@@ -23,7 +24,26 @@ export const getProceduralPitches = (prevPitches) => {
|
|||||||
} else {
|
} else {
|
||||||
// now we need some repeating logic for the remaining four voices
|
// now we need some repeating logic for the remaining four voices
|
||||||
while (pitches.length !== (pitchsets.indexOf(voice) + 1)) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { pitchsets } from "../harmonyUtil.js";
|
import { pitchsets } from "../harmonyUtil.js";
|
||||||
import { extractPitchName } from "./extractPitchName.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 = () => {
|
export const getRandomPitches = () => {
|
||||||
// pitches stored in Tone.js string format
|
// pitches stored in Tone.js string format
|
||||||
let pitches = [];
|
let pitches = [];
|
||||||
@@ -13,7 +16,7 @@ export const getRandomPitches = () => {
|
|||||||
|
|
||||||
// loops until four distinct chord members are received
|
// loops until four distinct chord members are received
|
||||||
while (formattedPitches.length <= pitchsets.indexOf(voice)) {
|
while (formattedPitches.length <= pitchsets.indexOf(voice)) {
|
||||||
index = Math.floor(Math.random() * 100) % voice.length;
|
index = getRandomIndex(voice);
|
||||||
|
|
||||||
formattedPitch = extractPitchName(voice[index]);
|
formattedPitch = extractPitchName(voice[index]);
|
||||||
if (!formattedPitches.includes(formattedPitch)) {
|
if (!formattedPitches.includes(formattedPitch)) {
|
||||||
|
|||||||
80
src/vector_logic/helper.js
Normal file
80
src/vector_logic/helper.js
Normal file
@@ -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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user