defining some more harmony utils
This commit is contained in:
12
app.ts
12
app.ts
@@ -4,7 +4,7 @@ import {
|
||||
extractPitchset,
|
||||
} from "./src/toneGeneration.js";
|
||||
|
||||
const pitchsets = [sopranoTones, altoTones, tenorTones, bassTones];
|
||||
const pitchsets: string[][] = [sopranoTones, altoTones, tenorTones, bassTones];
|
||||
|
||||
// initialize four synth voices
|
||||
const soprano = new Tone.Synth().toDestination();
|
||||
@@ -21,7 +21,7 @@ export const audioTest = () => {
|
||||
}
|
||||
|
||||
// allows a chord to be generated with input from another function
|
||||
export const soundChord = (pitches) => {
|
||||
export const soundChord = (pitches: string[]) => {
|
||||
const [s,a,t,b] = pitches;
|
||||
soprano.triggerAttackRelease(s, "8n");
|
||||
alto.triggerAttackRelease(a, "8n");
|
||||
@@ -31,10 +31,10 @@ export const soundChord = (pitches) => {
|
||||
|
||||
// initial test: generate a single, random chord
|
||||
export const fullRandomChord = () => {
|
||||
let pitches = [];
|
||||
let pitches: string[];
|
||||
for (let voice of pitchsets) {
|
||||
// finds a random index, excluding any which may already exist in the array
|
||||
let index;
|
||||
let index: number;
|
||||
|
||||
do {
|
||||
index = Math.floor(Math.random() * 100) % voice.length;
|
||||
@@ -55,9 +55,6 @@ export const fullRandomChord = () => {
|
||||
}
|
||||
|
||||
// set up transport
|
||||
let clock = 0;
|
||||
let slowClock = 0;
|
||||
|
||||
const transportStart = document.getElementById('transport-start');
|
||||
|
||||
const loop = new Tone.Loop((time) => {
|
||||
@@ -69,4 +66,3 @@ loop.probability = 0.8;
|
||||
transportStart.onclick = () => {
|
||||
Tone.Transport.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { extractPitchset } from "./toneGeneration.js";
|
||||
|
||||
// interval definitions:
|
||||
const intervals = {
|
||||
export interface IntervalDef {
|
||||
number: string
|
||||
}
|
||||
|
||||
export const IntervalDefNames = {
|
||||
0: "unison",
|
||||
1: "minor second",
|
||||
2: "major second",
|
||||
@@ -9,7 +13,7 @@ const intervals = {
|
||||
4: "major third",
|
||||
5: "perfect fourth",
|
||||
6: "tritone"
|
||||
// all intervals beyond this invert to one of the previous intervals
|
||||
// ... all intervals beyond this invert to one of the previous intervals
|
||||
}
|
||||
|
||||
// helper functions
|
||||
@@ -48,17 +52,40 @@ const findVector = (pitches: number[]) => {
|
||||
return intervalClasses;
|
||||
}
|
||||
|
||||
export const labelIntervals = (vector: number[]): [number, IntervalDef][] => {
|
||||
let result: [number, IntervalDef][] = [];
|
||||
|
||||
for (let x of vector) {
|
||||
result.push([x, IntervalDefNames[x]]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// analysis
|
||||
let dMajor = extractPitchset(["D", "F#", "A", "D"]);
|
||||
const eMajor = transposePitches(dMajor, 2);
|
||||
console.log(eMajor);
|
||||
console.log('');
|
||||
|
||||
let dMajVector = findVector(dMajor);
|
||||
console.log(dMajVector);
|
||||
/**
|
||||
* sample uses of these functions detailed below:
|
||||
*
|
||||
* @var dMajVector = @function findVector(dMajor);
|
||||
* @param dMajor number[] ( result of earlier call to @function extractPitchset )
|
||||
* ... @returns [0,3,4,5]
|
||||
* this indicates this pitchset contains a unison, a minor third, a major third,
|
||||
* and a perfect fourth (or a corresponding inversion)
|
||||
*
|
||||
* @var complexVector = @function findVector([0,3,4,7,8,11]);
|
||||
* @returns [1,2,3,4,5]
|
||||
*
|
||||
* @var splitThird = @function findVector([0,3,4,7]);
|
||||
* @returns [1,3,4]
|
||||
*
|
||||
* @function labelIntervals
|
||||
* @param vector = number[] corresponding to sorted vector
|
||||
* references @interface IntervalDef to select from @constant IntervalDefNames
|
||||
* @returns an array of duples, each containing a number and an entry from IntervalDef
|
||||
*/
|
||||
|
||||
let complexVector = findVector([0,3,4,7,8,11]);
|
||||
console.log(complexVector);
|
||||
|
||||
let splitThird = findVector([0,3,4,7]);
|
||||
console.log(splitThird);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as harmUtil from './harmonyUtil';
|
||||
|
||||
// we start with a selection of pitches that generally work okay together
|
||||
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"];
|
||||
@@ -11,7 +13,7 @@ const musicalPitches = ['A', "Bb", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G
|
||||
|
||||
export const extractPitchset = (pitches: string[]) => {
|
||||
// 1) determine pitch set from given array of pitches
|
||||
let pitchset: number[];
|
||||
let pitchset: number[] = [];
|
||||
|
||||
for (let each of pitches) {
|
||||
// filters numbers from above tones
|
||||
@@ -32,4 +34,10 @@ export const extractPitchset = (pitches: string[]) => {
|
||||
}
|
||||
|
||||
// no tritones
|
||||
// no minor 2nds or major 7ths
|
||||
// no minor 2nds or major 7ths
|
||||
|
||||
const evaluateVector = (vector: number[]): boolean => {
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "./built",
|
||||
"allowJs": true,
|
||||
"target": "es2016",
|
||||
"target": "es2017",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
|
||||
Reference in New Issue
Block a user