several problems to solve -- project structure better defined

This commit is contained in:
Mikayla Dobson
2022-05-11 12:35:58 -05:00
parent e28b2176ee
commit e25324aec2
8 changed files with 69 additions and 52 deletions

View File

@@ -112,6 +112,7 @@
<button id="mute-all">Mute all oscillators</button>
<button id="reset-lfos">Reset LFO values to default</button>
<button id="rand-chord">Full random chord</button>
<button id="eval-chord">Evaluated chord</button>
</div>
</main>

View File

@@ -1,38 +1,28 @@
import { soundChord } from '../app.js';
import { pitchsets } from "./harmonyUtil.js";
import { getRandomPitches } from "./harmonyUtil.js";
import { evaluateVector } from "./vector_logic/evaluateVector.js";
import { evaluateVector, rejectDissonance } from "./vector_logic/evaluateVector.js";
import { findVector } from "./vector_logic/findVector.js";
import { extractPitchset } from "./vector_logic/extractPitchset.js";
export const fullRandomChord = () => {
let pitches: string[];
for (let voice of pitchsets) {
// finds a random index, excluding any which may already exist in the array
let index: number;
do {
if (!pitches) pitches = [];
index = Math.floor(Math.random() * 100) % voice.length;
} while (pitches.includes(voice[index]) ?? false);
pitches ? pitches.push(voice[index]) : pitches = [voice[index]];
console.log(voice[index]);
}
for (let i = 0; i < pitches.length; i++) {
if (pitches[i] === pitches[i+1]) {
console.log("CAUGHT");
}
}
let pitches: string[] = getRandomPitches();
soundChord(pitches);
let pitchValues: number[] = extractPitchset(pitches);
pitchValues = findVector(pitchValues);
let evaluated = evaluateVector(pitchValues);
console.log(pitches);
console.log(evaluated);
return evaluated;
}
export const evaluatedChord = () => {
let pitches: string[] = getRandomPitches();
let pitchNums: number[] = extractPitchset(pitches);
let firstVector = findVector(pitchNums);
let finalVector = rejectDissonance(firstVector);
if (finalVector !== firstVector) console.log('caught');
soundChord(pitches);
}

View File

@@ -32,6 +32,7 @@ const transposePitches = (pitches: number[], interval: number) => {
return transposed;
}
// quality-of-life tool for debugging
export const labelIntervals = (vector: number[]): [number, IntervalDef][] => {
let result: [number, IntervalDef][] = [];
@@ -42,23 +43,28 @@ export const labelIntervals = (vector: number[]): [number, IntervalDef][] => {
return result;
}
/**
* sample uses of these functions detailed below:
*
* @var dMajVector = @function findVector(dMajor);
* @param dMajor number[] ( result of earlier call to @function extractPitchset )
* ... @returns [0,3,4,5]
* this indicates this pitchset contains a unison, a minor third, a major third,
* and a perfect fourth (or a corresponding inversion)
*
* @var complexVector = @function findVector([0,3,4,7,8,11]);
* @returns [1,2,3,4,5]
*
* @var splitThird = @function findVector([0,3,4,7]);
* @returns [1,3,4]
*
* @function labelIntervals
* @param vector = number[] corresponding to sorted vector
* references @interface IntervalDef to select from @constant IntervalDefNames
* @returns an array of duples, each containing a number and an entry from IntervalDef
*/
// iterates through each voice's pitchset, and selects a random pitch from each
export const getRandomPitches = (): string[] => {
let pitches: string[];
for (let voice of pitchsets) {
// will store a random index
let index: number;
const regex = /[0-9]/g;
// repeat this iteration until it returns a number not already included in the list
do {
if (!pitches) pitches = [];
index = Math.floor(Math.random() * 100) % voice.length;
console.log(`${voice[0]}: ${index}`);
} while (pitches.includes(voice[index]));
// if pitches is not already initialized to an empty array, do so; otherwise, push the received value
pitches ? pitches.push(voice[index]) : pitches = [voice[index]];
console.log(voice[index]);
}
return pitches;
}

View File

@@ -1,5 +1,5 @@
import { audioTest } from '../app.js';
import { fullRandomChord } from './audioUtils.js';
import { evaluatedChord, fullRandomChord } from './audioUtils.js';
// slider variables referring to DOM
export const sopranoVol = document.getElementById('soprano-vol');
@@ -73,3 +73,6 @@ synthButton.onclick = audioTest;
const randChord = document.getElementById('rand-chord');
randChord.onclick = fullRandomChord;
const evalChord = document.getElementById('eval-chord');
evalChord.onclick = evaluatedChord;

View File

@@ -1,7 +1,21 @@
import { getRandomPitches } from "../harmonyUtil.js";
import { extractPitchset } from "./extractPitchset.js";
import { findVector } from "./findVector.js";
export const evaluateVector = (vector: number[]): boolean => {
return ((vector.includes(1) || vector.includes(6)));
}
export const rejectDissonance = (vector: number[]) => {
return;
export const rejectDissonance = (pitchset: number[]) => {
const vector = findVector(pitchset);
// returns the pitchset and its vector if evaluateVector returns true,
if (evaluateVector(vector)) return vector;
// and recursively calls the function otherwise.
if (!evaluateVector(vector)) {
let newPitches: string[] = getRandomPitches();
let newPitchset: number[] = extractPitchset(newPitches);
rejectDissonance(newPitchset);
};
}

View File

@@ -1,6 +1,6 @@
import { musicalPitches } from "../harmonyUtil.js";
export const extractPitchset = (pitches: string[]) => {
export const extractPitchset = (pitches: string[]): number[] => {
// 1) determine pitch set from given array of pitches
let pitchset: number[] = [];

View File

@@ -1,8 +1,5 @@
export const findVector = (pitches: number[]) => {
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: number[] = [];
@@ -24,5 +21,6 @@ export const findVector = (pitches: number[]) => {
}
intervalClasses = intervalClasses.sort((x,y) => x-y);
return intervalClasses;
}

View File

@@ -0,0 +1,5 @@
export const vectorToPitches = (vector: number[]): string[] => {
return [''];
}