From 04d26d852926e7d484bf5dc112eeb2f9122bbbd0 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Tue, 10 May 2022 11:47:45 -0500 Subject: [PATCH] defined a function which identifies dissonance in a vector --- app.ts | 25 ------------------------- index.html | 1 + src/audioUtils.ts | 5 +++-- src/inputHandling.ts | 3 ++- src/styleUtils.ts | 2 +- src/toneGeneration.ts | 16 +++------------- 6 files changed, 10 insertions(+), 42 deletions(-) diff --git a/app.ts b/app.ts index 7e2856f..c8b0f95 100644 --- a/app.ts +++ b/app.ts @@ -25,31 +25,6 @@ export const soundChord = (pitches: string[]) => { bass.triggerAttackRelease(b, "8n"); } -// initial test: generate a single, random chord -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 { - index = Math.floor(Math.random() * 100) % voice.length; - } while (pitches.includes(voice[index])); - - pitches.push(voice[index]); - console.log(voice[index]); - } - - for (let i = 0; i < pitches.length; i++) { - if (pitches[i] === pitches[i+1]) { - console.log("CAUGHT"); - } - } - - soundChord(pitches); - extractPitchset(pitches); -} - // set up transport const transportStart = document.getElementById('transport-start'); diff --git a/index.html b/index.html index c99b8c0..89ac1e5 100644 --- a/index.html +++ b/index.html @@ -123,5 +123,6 @@ + \ No newline at end of file diff --git a/src/audioUtils.ts b/src/audioUtils.ts index 325e69d..b8314f2 100644 --- a/src/audioUtils.ts +++ b/src/audioUtils.ts @@ -9,10 +9,11 @@ export const fullRandomChord = () => { let index: number; do { + if (!pitches) pitches = []; index = Math.floor(Math.random() * 100) % voice.length; - } while (pitches.includes(voice[index])); + } while (pitches.includes(voice[index]) ?? false); - pitches.push(voice[index]); + pitches ? pitches.push(voice[index]) : pitches = [voice[index]]; console.log(voice[index]); } diff --git a/src/inputHandling.ts b/src/inputHandling.ts index 23a9c74..6b31b0b 100644 --- a/src/inputHandling.ts +++ b/src/inputHandling.ts @@ -1,4 +1,5 @@ -import { audioTest, fullRandomChord } from '../app.js'; +import { audioTest } from '../app.js'; +import { fullRandomChord } from './audioUtils.js'; // slider variables referring to DOM export const sopranoVol = document.getElementById('soprano-vol'); diff --git a/src/styleUtils.ts b/src/styleUtils.ts index 8231e4c..94e17bb 100644 --- a/src/styleUtils.ts +++ b/src/styleUtils.ts @@ -1,4 +1,4 @@ -import * as Tone from 'tone'; +import * as Tone from "tone"; export const startButton = document.getElementById("start-tone"); export const synthButton = document.getElementById("synth-button"); diff --git a/src/toneGeneration.ts b/src/toneGeneration.ts index 76a2cb7..94959b3 100644 --- a/src/toneGeneration.ts +++ b/src/toneGeneration.ts @@ -1,5 +1,3 @@ -import { findVector, IntervalDefNames, musicalPitches } from './harmonyUtil'; - // we start with a selection of pitches that generally work okay together const sopranoTones = ["B5", "A5", "G5", "F#5", "F5", "E5", "D5", "C5", "B4", "Bb4", "A4", "G4", "F#4", "F4", "E4"]; const altoTones = ["E5", "D5", "C5", "B4", "Bb4", "A4", "G4", "F#4", "F4", "E4", "D4", "C4", "B3", "Bb3", "A3", "G3"]; @@ -17,16 +15,8 @@ export const pitchsets: string[][] = [sopranoTones, altoTones, tenorTones, bassT * no minor 2nds or major 7ths */ -export const evaluateVector = (vector: number[]): boolean => { - let result: boolean; +export const evaluateVector = (vector: number[]): boolean => ((vector.includes(1) || vector.includes(6))); - for (let x of vector) { - if (x === 1 || x === 6) { - result = false; - return; - } else { - result = true; - } - } - return result; +export const rejectDissonance = (vector: number[]) => { + }