state management

This commit is contained in:
Mikayla Dobson
2022-05-15 13:09:56 -05:00
parent 18211524d0
commit ef11406e78
6 changed files with 39 additions and 10 deletions

View File

@@ -113,12 +113,14 @@
<button id="reset-lfos">Reset LFO values to default</button>
<button id="rand-chord">Full random chord</button>
<button id="eval-chord">Evaluated chord</button>
<button id="next-chord">Get next chord (console)</button>
</div>
</main>
<!-- Tone.js library -->
<script type="module" src="https://unpkg.com/tone@14.7.77/build/Tone.js"></script>
<!-- internal scripts -->
<script type="module" src="./src/pitch_generation/sonorityList.js"></script>
<script type="module" src="./src/styleUtils.js"></script>
<script type="module" src="./src/inputHandling.js"></script>
<script type="module" src="./src/harmonyUtil.js"></script>

View File

@@ -14,7 +14,7 @@ export const fullRandomChord = () => {
export const evaluatedChord = (prevPitches = ["C3", "G3", "C4", "G4"]) => {
let pitches = getProceduralPitches(prevPitches);
soundChord(pitches);
if (pitches) soundChord(pitches);
let pitchset = extractPitchset(pitches);
return pitchset;

View File

@@ -1,5 +1,6 @@
import { audioTest } from '../app.js';
import { fullRandomChord, evaluatedChord } from './audioUtil.js';
import { sonorities, getNextSonority } from './pitch_generation/sonorityList.js';
// slider variables referring to DOM
export const sopranoVol = document.getElementById('soprano-vol');
@@ -76,3 +77,6 @@ randChord.onclick = fullRandomChord;
const evalChord = document.getElementById('eval-chord');
evalChord.onclick = evaluatedChord;
const nextChord = document.getElementById('next-chord');
nextChord.onclick = getNextSonority;

View File

@@ -2,11 +2,13 @@ import { pitchsets, musicalPitches } from "../harmonyUtil.js";
import { extractPitchName } from "../data_conversions/extractPitchName.js";
import { getRandomIndex } from "./getRandomPitches.js";
import { melodicGeneration } from './melodicGeneration.js';
import { sonorityList } from "./sonorityList.js";
// iterator to prevent stack overflow
// variables to handle recursive logic
let callCount = 0;
export const getProceduralPitches = () => {
let result;
callCount++;
if (callCount >= 10) {
@@ -53,15 +55,17 @@ export const getProceduralPitches = () => {
// if a dissonance is found, the function is called recursively, and its value returned
if (isDissonant) {
let newPitches = getProceduralPitches();
return newPitches;
result = newPitches;
// otherwise, the original value itself is returned
} else {
console.log(`call count: ${callCount}`);
callCount = 0;
console.log(pitches);
let { isMelodic, nextPitches } = melodicGeneration(pitches);
if (nextPitches) return nextPitches;
let newValue = melodicGeneration(pitches);
sonorityList(pitches, newValue);
result = newValue;
}
if (result) return result;
}

View File

@@ -6,7 +6,10 @@ import { musicalPitches, pitchsets } from '../harmonyUtil.js';
// reads the pitch of the previous sonority and determines appropriate melodic movement for the soprano
// returns a boolean which triggers a recursive call if the interval received is out of expected values
let callCount = 0;
export const melodicGeneration = (prevPitches) => {
let result;
// direction: boolean; true refers to ascending motion; false refers to descending motion
let direction;
let isMelodic = true;
@@ -84,9 +87,12 @@ export const melodicGeneration = (prevPitches) => {
}
if (!isMelodic) {
let newMelodicPitches = melodicGeneration(prevPitches);
return newMelodicPitches;
callCount++;
result = melodicGeneration(prevPitches);
} else {
return newPitches;
callCount = 0;
result = newPitches;
}
return result;
}

View File

@@ -0,0 +1,13 @@
export const sonorities = [];
export const sonorityList = (result) => {
if (!sonorities.includes(result)) sonorities.push(result);
console.log(sonorities);
return sonorities;
}
export const getNextSonority = () => {
console.log(sonorities);
return sonorities;
}