separation of concerns
This commit is contained in:
@@ -9,4 +9,8 @@ export const fullRandomChord = () => {
|
||||
let pitchset = extractPitchset(pitches);
|
||||
|
||||
return pitchset;
|
||||
}
|
||||
|
||||
export const evaluatedChord = () => {
|
||||
return fullRandomChord();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
2
src/vector_logic/extractPitchName.js
Normal file
2
src/vector_logic/extractPitchName.js
Normal file
@@ -0,0 +1,2 @@
|
||||
const regex = /[A-Gb#]/g;
|
||||
export const extractPitchName = (tonePitchName) => tonePitchName.match(regex).join('');
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user