From 998b0fb5be74f2e5bab9d7275917a964b591b5d3 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Thu, 12 May 2022 12:26:22 -0500 Subject: [PATCH] separation of concerns --- src/audioUtil.js | 4 ++++ src/harmonyUtil.js | 21 ++++++++++++++++--- src/helper.js | 30 ---------------------------- src/inputHandling.js | 5 ++++- src/vector_logic/extractPitchName.js | 2 ++ src/vector_logic/extractPitchset.js | 4 ++-- 6 files changed, 30 insertions(+), 36 deletions(-) delete mode 100644 src/helper.js create mode 100644 src/vector_logic/extractPitchName.js diff --git a/src/audioUtil.js b/src/audioUtil.js index fb97911..97feba5 100644 --- a/src/audioUtil.js +++ b/src/audioUtil.js @@ -9,4 +9,8 @@ export const fullRandomChord = () => { let pitchset = extractPitchset(pitches); return pitchset; +} + +export const evaluatedChord = () => { + return fullRandomChord(); } \ No newline at end of file diff --git a/src/harmonyUtil.js b/src/harmonyUtil.js index eca3e0d..bd01f6b 100644 --- a/src/harmonyUtil.js +++ b/src/harmonyUtil.js @@ -1,4 +1,6 @@ import { extractPitchset } from "./vector_logic/extractPitchset.js"; +import { evaluateVector } from "./vector_logic/evaluateVector.js"; +import { extractPitchName } from "./vector_logic/extractPitchName.js"; export const sopranoTones = ["B5", "A5", "G5", "F#5", "F5", "E5", "D5", "C5", "B4", "Bb4", "A4", "G4", "F#4", "F4", "E4"]; export const altoTones = ["E5", "D5", "C5", "B4", "Bb4", "A4", "G4", "F#4", "F4", "E4", "D4", "C4", "B3", "Bb3", "A3", "G3"]; @@ -36,15 +38,15 @@ export const getRandomPitches = () => { for (let voice of pitchsets) { // finds a random index, excluding any which may already exist in the array let index; - const regex = /[A-Gb#]/g; let pitch; let formattedPitch; // loops until four distinct chord members are received - while (formattedPitches.length < 4) { + while (formattedPitches.length <= pitchsets.indexOf(voice)) { index = Math.floor(Math.random() * 100) % voice.length; pitch = voice[index]; - formattedPitch = pitch.match(regex).join(''); + + formattedPitch = extractPitchName(pitch); if (!formattedPitches.includes(formattedPitch)) { formattedPitches.push(formattedPitch); pitches.push(pitch); @@ -56,3 +58,16 @@ export const getRandomPitches = () => { console.log(pitches); return pitches; } + +// an additional method based on the structure of the method above, +// but taking principles of music theory into account. +export const getProceduralPitches = () => { + let pitches = []; + let formattedPitches = []; + + for (let voice of pitchsets) { + let index; + let pitch; + let formattedPitch; + } +} diff --git a/src/helper.js b/src/helper.js deleted file mode 100644 index f7a7b7e..0000000 --- a/src/helper.js +++ /dev/null @@ -1,30 +0,0 @@ -import { pitchsets } from "./harmonyUtil.js"; - -let index; -let pitch; -let formattedPitch = 'caught'; -let regex = /[A-Gb#]/g; - -let pitches = []; -let formattedPitches = []; - -// index = Math.floor(Math.random() * 100) % pitchsets[0].length; - -// const toParse = pitchsets[0][index]; -// const parsed = toParse.match(regex).join(''); -// console.log(parsed); - -for (let voice of pitchsets) { - while (formattedPitches.length < 4) { - index = Math.floor(Math.random() * 100) % voice.length; - pitch = voice[index]; - formattedPitch = pitch.match(regex).join(''); - if (!formattedPitches.includes(formattedPitch)) { - formattedPitches.push(formattedPitch); - pitches.push(pitch); - } - } -} - -console.log(formattedPitches) -console.log(pitches); \ No newline at end of file diff --git a/src/inputHandling.js b/src/inputHandling.js index 3effa91..d2dfaff 100644 --- a/src/inputHandling.js +++ b/src/inputHandling.js @@ -1,5 +1,5 @@ import { audioTest } from '../app.js'; -import { fullRandomChord } from './audioUtil.js'; +import { fullRandomChord, evaluatedChord } from './audioUtil.js'; // slider variables referring to DOM export const sopranoVol = document.getElementById('soprano-vol'); @@ -65,3 +65,6 @@ synthButton.onclick = audioTest; const randChord = document.getElementById('rand-chord'); randChord.onclick = fullRandomChord; + +const evalChord = document.getElementById('eval-chord'); +evalChord.onclick = evaluatedChord; diff --git a/src/vector_logic/extractPitchName.js b/src/vector_logic/extractPitchName.js new file mode 100644 index 0000000..016d63a --- /dev/null +++ b/src/vector_logic/extractPitchName.js @@ -0,0 +1,2 @@ +const regex = /[A-Gb#]/g; +export const extractPitchName = (tonePitchName) => tonePitchName.match(regex).join(''); diff --git a/src/vector_logic/extractPitchset.js b/src/vector_logic/extractPitchset.js index 33b74a8..62c9b1e 100644 --- a/src/vector_logic/extractPitchset.js +++ b/src/vector_logic/extractPitchset.js @@ -1,4 +1,5 @@ import { musicalPitches } from '../harmonyUtil.js'; +import { extractPitchName } from './extractPitchName.js'; // converts pitches in Tone.js string format to base-12 number pitchsets export const extractPitchset = (pitches) => { @@ -8,8 +9,7 @@ export const extractPitchset = (pitches) => { for (let each of pitches) { // filters numbers from above tones const str = each; - const regex = /[0-9]/g; - const withoutNums = str.replace(regex, ''); + const withoutNums = extractPitchName(str); const pitchNumber = musicalPitches.indexOf(withoutNums); // ... so that they may be mapped onto numbers corresponding to the chromatic scale