From 4e095c2af69eaf2f6374c821e0463ef6bf9b8590 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Mon, 9 May 2022 17:01:02 -0500 Subject: [PATCH] generates an interval vector --- app.js | 7 +++++-- js/toneGeneration.js | 25 +++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index 096770a..75cf0c8 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,7 @@ -import { sopranoTones, altoTones, tenorTones, bassTones, evaluateHarmony } from "./js/toneGeneration.js"; +import { + sopranoTones, altoTones, tenorTones, bassTones, + extractPitchset, +} from "./js/toneGeneration.js"; const pitchsets = [sopranoTones, altoTones, tenorTones, bassTones]; @@ -47,7 +50,7 @@ export const fullRandomChord = () => { } soundChord(pitches); - evaluateHarmony(pitches); + extractPitchset(pitches); } // set up transport diff --git a/js/toneGeneration.js b/js/toneGeneration.js index ae78816..d5fc2d6 100644 --- a/js/toneGeneration.js +++ b/js/toneGeneration.js @@ -9,17 +9,26 @@ export const bassTones = ["C2", "D2", "E2", "F2", "G2", "A2", "Bb2", "B2", "C3", // this is focused on base-12, something computers understand quite well const musicalPitches = ['A', "Bb", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]; -export const evaluateHarmony = (pitches) => { - let sorted = []; +export const extractPitchset = (pitches) => { + // 1) determine pitch set from given array of pitches + let pitchset = []; + for (let each of pitches) { - let matches = each.match(/(\d+)/); - if (matches) { - sorted.push([each, matches]); - } + // filters numbers from above tones + const str = each; + const regex = /[0-9]/g; + const withoutNums = str.replace(regex, ''); + const pitchNumber = musicalPitches.indexOf(withoutNums); + + // ... so that they may be mapped onto numbers corresponding to the chromatic scale + pitchset.push(pitchNumber); } - sorted = sorted.sort((a,b) => a[1] < b[1]); - console.log(sorted); + // these are sorted from lowest to highest index (something like an interval vector) + pitchset.sort((a,b) => a < b); + console.log(pitchset); + + // } // no tritones