state management
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
13
src/pitch_generation/sonorityList.js
Normal file
13
src/pitch_generation/sonorityList.js
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user