UNPKG

@typedin/music-utilities

Version:

A set of resources and modules I use to develop music applications.

49 lines 1.95 kB
import { spanOver } from "./spanOver.js"; import { intervalBuilders } from "../interval-builders/index.js"; // INFO go see the type declaration // // Key Elements of a Scale: // // Tonic (Root Note) – The starting note that gives the scale its name. // Intervals – The pattern of whole steps (W) and half steps (H) that determine the character of the scale. // Octave Structure – Most scales repeat every octave (e.g., C–D–E–F–G–A–B–C). // Mode or Type – Scales can be major, minor, modal, or exotic, based on their interval patterns. // Number of Notes – Common scales have 5 (pentatonic), 7 (heptatonic), or even 12 (chromatic) notes. export const ScaleBuilder = function (tonic, scaleSchema, number_of_octaves = 1) { this.tonic = tonic; this.scaleSchema = scaleSchema; this.tonicRepetition = true; this.withoutTonicRepetition = () => { this.tonicRepetition = false; return this; }; this.scale = () => { // this create a scale with 7 notes let result = scaleSchema.map((element, index) => { const note = intervalBuilders .find((intervalBuilder) => intervalBuilder.name == element.interval) ?.callable(tonic); return { ...note, order: index + 1, degree: index + 1, function: element.function, }; }); // spanOver creates many scales with the repetition of the tonic // for example: 2 octaves in C Major // we will have 3 tonics if (number_of_octaves > 1) { result = spanOver(result, number_of_octaves); result.pop(); } if (this.tonicRepetition) { result.push({ ...tonic, octave: tonic.octave + number_of_octaves, }); } return result; }; }; //# sourceMappingURL=ScaleBuilder.js.map