From 4b9fbdfa3663df975a76ef71b6078aa9e07b151d Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Thu, 12 May 2022 13:19:39 -0500 Subject: [PATCH] repairs to file system --- app.js | 3 -- index.html | 5 --- src/audioUtil.js | 11 ++++-- src/harmonyUtil.js | 48 +----------------------- src/vector_logic/evaluateVector.js | 2 +- src/vector_logic/getProceduralPitches.js | 34 +++++++++++++++++ src/vector_logic/getRandomPitches.js | 29 ++++++++++++++ 7 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 src/vector_logic/getProceduralPitches.js create mode 100644 src/vector_logic/getRandomPitches.js diff --git a/app.js b/app.js index bbb610c..aab2115 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,3 @@ -import { pitchsets } from "./src/harmonyUtil.js"; -import { extractPitchset } from "./src/vector_logic/extractPitchset.js"; - // initialize four synth voices const soprano = new Tone.Synth().toDestination(); const alto = new Tone.Synth().toDestination(); diff --git a/index.html b/index.html index 3a9dfbe..09e22de 100644 --- a/index.html +++ b/index.html @@ -124,10 +124,5 @@ - - - - - \ No newline at end of file diff --git a/src/audioUtil.js b/src/audioUtil.js index 97feba5..39c74c4 100644 --- a/src/audioUtil.js +++ b/src/audioUtil.js @@ -1,6 +1,7 @@ import { soundChord } from "../app.js"; -import { getRandomPitches } from "./harmonyUtil.js"; +import { getRandomPitches } from "./vector_logic/getRandomPitches.js"; import { extractPitchset } from "./vector_logic/extractPitchset.js"; +import { getProceduralPitches } from "./vector_logic/getProceduralPitches.js"; // initial test: generate a single, random chord export const fullRandomChord = () => { @@ -11,6 +12,10 @@ export const fullRandomChord = () => { return pitchset; } -export const evaluatedChord = () => { - return fullRandomChord(); +export const evaluatedChord = (prevPitches = ["C3", "G3", "C4", "G4"]) => { + let pitches = getProceduralPitches(prevPitches); + soundChord(pitches); + let pitchset = extractPitchset(pitches); + + return pitchset; } \ No newline at end of file diff --git a/src/harmonyUtil.js b/src/harmonyUtil.js index bd01f6b..696320b 100644 --- a/src/harmonyUtil.js +++ b/src/harmonyUtil.js @@ -1,13 +1,9 @@ -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"]; export const tenorTones = ["G4", "F#4", "F4", "E4", "D4", "C4", "B3", "Bb3", "A3", "G3", "F3", "E3", "D3", "C3"]; export const bassTones = ["C2", "D2", "E2", "F2", "G2", "A2", "Bb2", "B2", "C3", "D3", "E3", "F3", "G3"]; -export const pitchsets = [sopranoTones, altoTones, tenorTones, bassTones]; +export const pitchsets = [bassTones, tenorTones, altoTones, sopranoTones]; export const musicalPitches = ['A', "Bb", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]; @@ -29,45 +25,3 @@ const transposePitches = (pitchNames, interval) => { pitchNames.forEach(pitch => transposed.push((pitch + interval) % 12)); return transposed; } - -export const getRandomPitches = () => { - // pitches stored in Tone.js string format - let pitches = []; - let formattedPitches = []; - - for (let voice of pitchsets) { - // finds a random index, excluding any which may already exist in the array - let index; - let pitch; - let formattedPitch; - - // loops until four distinct chord members are received - while (formattedPitches.length <= pitchsets.indexOf(voice)) { - index = Math.floor(Math.random() * 100) % voice.length; - pitch = voice[index]; - - formattedPitch = extractPitchName(pitch); - if (!formattedPitches.includes(formattedPitch)) { - formattedPitches.push(formattedPitch); - pitches.push(pitch); - } - } - } - - console.log(formattedPitches); - 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/vector_logic/evaluateVector.js b/src/vector_logic/evaluateVector.js index 035c4b2..db32ff6 100644 --- a/src/vector_logic/evaluateVector.js +++ b/src/vector_logic/evaluateVector.js @@ -1,4 +1,4 @@ -import { getRandomPitches } from "../harmonyUtil.js"; +import { getRandomPitches } from './getRandomPitches.js'; import { extractPitchset } from "./extractPitchset.js"; import { findVector } from "./findVector.js"; diff --git a/src/vector_logic/getProceduralPitches.js b/src/vector_logic/getProceduralPitches.js new file mode 100644 index 0000000..0a542f1 --- /dev/null +++ b/src/vector_logic/getProceduralPitches.js @@ -0,0 +1,34 @@ +import { pitchsets } from "../harmonyUtil.js"; +import { extractPitchName } from "./extractPitchName.js"; + +// an additional method based on the structure of getRandomPitches, +// but taking some principles of music theory into account. +export const getProceduralPitches = (prevPitches) => { + // prevPitches is passed in to ensure there is no linear dissonance within voices + let pitches = []; + let formattedPitches = []; + + for (let voice of pitchsets) { + let index; + let formattedPitch; + + while (pitches.length <= pitchsets.indexOf(voice)) { + // the first section of this while loop is more free. + index = Math.floor(Math.random() * 100) % voice.length; + formattedPitch = extractPitchName(voice[index]); + + // this initial condition will apply only to the bass voice, + if (!pitches.length) { + pitches.push(voice[index]); + } else { + // now we need some repeating logic for the remaining four voices + while (pitches.length !== (pitchsets.indexOf(voice) + 1)) { + pitches.push(pitchsets.indexOf(voice)); + } + } + } + } + + console.log(pitches); + return pitches; +} diff --git a/src/vector_logic/getRandomPitches.js b/src/vector_logic/getRandomPitches.js new file mode 100644 index 0000000..a041b44 --- /dev/null +++ b/src/vector_logic/getRandomPitches.js @@ -0,0 +1,29 @@ +import { pitchsets } from "../harmonyUtil.js"; +import { extractPitchName } from "./extractPitchName.js"; + +export const getRandomPitches = () => { + // pitches stored in Tone.js string format + let pitches = []; + let formattedPitches = []; + + for (let voice of pitchsets) { + // finds a random index, excluding any which may already exist in the array + let index; + let formattedPitch; + + // loops until four distinct chord members are received + while (formattedPitches.length <= pitchsets.indexOf(voice)) { + index = Math.floor(Math.random() * 100) % voice.length; + + formattedPitch = extractPitchName(voice[index]); + if (!formattedPitches.includes(formattedPitch)) { + formattedPitches.push(formattedPitch); + pitches.push(voice[index]); + } + } + } + + console.log(formattedPitches); + console.log(pitches); + return pitches; +}