state management
This commit is contained in:
@@ -113,12 +113,14 @@
|
|||||||
<button id="reset-lfos">Reset LFO values to default</button>
|
<button id="reset-lfos">Reset LFO values to default</button>
|
||||||
<button id="rand-chord">Full random chord</button>
|
<button id="rand-chord">Full random chord</button>
|
||||||
<button id="eval-chord">Evaluated chord</button>
|
<button id="eval-chord">Evaluated chord</button>
|
||||||
|
<button id="next-chord">Get next chord (console)</button>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<!-- Tone.js library -->
|
<!-- Tone.js library -->
|
||||||
<script type="module" src="https://unpkg.com/tone@14.7.77/build/Tone.js"></script>
|
<script type="module" src="https://unpkg.com/tone@14.7.77/build/Tone.js"></script>
|
||||||
<!-- internal scripts -->
|
<!-- 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/styleUtils.js"></script>
|
||||||
<script type="module" src="./src/inputHandling.js"></script>
|
<script type="module" src="./src/inputHandling.js"></script>
|
||||||
<script type="module" src="./src/harmonyUtil.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"]) => {
|
export const evaluatedChord = (prevPitches = ["C3", "G3", "C4", "G4"]) => {
|
||||||
let pitches = getProceduralPitches(prevPitches);
|
let pitches = getProceduralPitches(prevPitches);
|
||||||
soundChord(pitches);
|
if (pitches) soundChord(pitches);
|
||||||
let pitchset = extractPitchset(pitches);
|
let pitchset = extractPitchset(pitches);
|
||||||
|
|
||||||
return pitchset;
|
return pitchset;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { audioTest } from '../app.js';
|
import { audioTest } from '../app.js';
|
||||||
import { fullRandomChord, evaluatedChord } from './audioUtil.js';
|
import { fullRandomChord, evaluatedChord } from './audioUtil.js';
|
||||||
|
import { sonorities, getNextSonority } from './pitch_generation/sonorityList.js';
|
||||||
|
|
||||||
// slider variables referring to DOM
|
// slider variables referring to DOM
|
||||||
export const sopranoVol = document.getElementById('soprano-vol');
|
export const sopranoVol = document.getElementById('soprano-vol');
|
||||||
@@ -76,3 +77,6 @@ randChord.onclick = fullRandomChord;
|
|||||||
|
|
||||||
const evalChord = document.getElementById('eval-chord');
|
const evalChord = document.getElementById('eval-chord');
|
||||||
evalChord.onclick = evaluatedChord;
|
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 { extractPitchName } from "../data_conversions/extractPitchName.js";
|
||||||
import { getRandomIndex } from "./getRandomPitches.js";
|
import { getRandomIndex } from "./getRandomPitches.js";
|
||||||
import { melodicGeneration } from './melodicGeneration.js';
|
import { melodicGeneration } from './melodicGeneration.js';
|
||||||
|
import { sonorityList } from "./sonorityList.js";
|
||||||
|
|
||||||
// iterator to prevent stack overflow
|
// variables to handle recursive logic
|
||||||
let callCount = 0;
|
let callCount = 0;
|
||||||
|
|
||||||
export const getProceduralPitches = () => {
|
export const getProceduralPitches = () => {
|
||||||
|
let result;
|
||||||
callCount++;
|
callCount++;
|
||||||
|
|
||||||
if (callCount >= 10) {
|
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 a dissonance is found, the function is called recursively, and its value returned
|
||||||
if (isDissonant) {
|
if (isDissonant) {
|
||||||
let newPitches = getProceduralPitches();
|
let newPitches = getProceduralPitches();
|
||||||
return newPitches;
|
result = newPitches;
|
||||||
// otherwise, the original value itself is returned
|
// otherwise, the original value itself is returned
|
||||||
} else {
|
} else {
|
||||||
console.log(`call count: ${callCount}`);
|
console.log(`call count: ${callCount}`);
|
||||||
callCount = 0;
|
callCount = 0;
|
||||||
console.log(pitches);
|
|
||||||
|
|
||||||
let { isMelodic, nextPitches } = melodicGeneration(pitches);
|
let newValue = melodicGeneration(pitches);
|
||||||
|
sonorityList(pitches, newValue);
|
||||||
if (nextPitches) return nextPitches;
|
|
||||||
|
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
|
// 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
|
// returns a boolean which triggers a recursive call if the interval received is out of expected values
|
||||||
|
|
||||||
|
let callCount = 0;
|
||||||
export const melodicGeneration = (prevPitches) => {
|
export const melodicGeneration = (prevPitches) => {
|
||||||
|
let result;
|
||||||
|
|
||||||
// direction: boolean; true refers to ascending motion; false refers to descending motion
|
// direction: boolean; true refers to ascending motion; false refers to descending motion
|
||||||
let direction;
|
let direction;
|
||||||
let isMelodic = true;
|
let isMelodic = true;
|
||||||
@@ -84,9 +87,12 @@ export const melodicGeneration = (prevPitches) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isMelodic) {
|
if (!isMelodic) {
|
||||||
let newMelodicPitches = melodicGeneration(prevPitches);
|
callCount++;
|
||||||
return newMelodicPitches;
|
result = melodicGeneration(prevPitches);
|
||||||
} else {
|
} 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