UNPKG

@typedin/music-utilities

Version:

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

56 lines 2.1 kB
import { getNextAlteration, getPreviousAlteration } from "../helpers/index.js"; import { getAlterationForAugmentedInterval } from "./getAlteration.js"; import { getAlterationForPerfectInterval } from "./getAlterationForPerfectInterval.js"; import { getName } from "./getName.js"; import { getNoteOctave } from "./getNoteOctave.js"; const specialCases = { up: ["F"], down: ["B"], }; const notesThatMakeOctaveChange = { up: ["G", "A", "B"], down: ["C", "D", "E"], }; const semitones = { special: { up: 6, down: 6, }, normal: { up: 5, down: 7, }, }; function getAlterationForDiminishedInterval(note, direction, specialCases) { if (direction == "up") { return specialCases[direction].includes(note.name) ? getPreviousAlteration(getPreviousAlteration(note.alteration)) : getPreviousAlteration(note.alteration); } return specialCases[direction].includes(note.name) ? getNextAlteration(getNextAlteration(note.alteration)) : getNextAlteration(note.alteration); } function DiminishedFourth(note, direction = "up") { return { name: getName(note, direction, semitones, specialCases), alteration: getAlterationForDiminishedInterval(note, direction, specialCases), octave: getNoteOctave(note, notesThatMakeOctaveChange[direction], direction), }; } function PerfectFourth(note, direction = "up") { return { name: getName(note, direction, semitones, specialCases), alteration: getAlterationForPerfectInterval(note, direction, specialCases), octave: getNoteOctave(note, notesThatMakeOctaveChange[direction], direction), }; } function AugmentedFourth(note, direction = "up") { return { name: getName(note, direction, semitones, specialCases), alteration: getAlterationForAugmentedInterval(note, direction, specialCases), octave: getNoteOctave(note, notesThatMakeOctaveChange[direction], direction), }; } export { DiminishedFourth, PerfectFourth, AugmentedFourth }; //# sourceMappingURL=Fourth.js.map