UNPKG

moment-of-symmetry

Version:

Moment of Symmetry (MOS) musical scale generation and analysis for Javascript

89 lines 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findAllMosInEdo = exports.mosInEdoWithDaughter = exports.mosInEdoWithParent = exports.mosInEdo = void 0; const pattern_1 = require("../core/pattern"); const index_1 = require("../index"); /** * Generate a MOS scale in a specific EDO */ function mosInEdo(edo, largeSteps, smallSteps, options) { var _a, _b; if (edo <= 0) { throw new Error('EDO must be positive'); } if (largeSteps < 0 || smallSteps < 0) { throw new Error('Number of steps must be non-negative'); } const sizeOfLargeStep = (_a = options === null || options === void 0 ? void 0 : options.sizeOfLargeStep) !== null && _a !== void 0 ? _a : Math.floor(edo / (largeSteps + smallSteps)); const sizeOfSmallStep = (_b = options === null || options === void 0 ? void 0 : options.sizeOfSmallStep) !== null && _b !== void 0 ? _b : Math.floor(edo / (largeSteps + smallSteps)); return (0, pattern_1.createMosScale)(largeSteps, smallSteps, { ...options, sizeOfLargeStep, sizeOfSmallStep, }); } exports.mosInEdo = mosInEdo; /** * Generate a MOS scale in a specific EDO with parent relationship */ function mosInEdoWithParent(edo, largeSteps, smallSteps, options) { const scale = mosInEdo(edo, largeSteps, smallSteps, options); const parentMap = (0, index_1.mosWithParent)(largeSteps, smallSteps, { ...options, period: edo, }); return { ...scale, parentMap, }; } exports.mosInEdoWithParent = mosInEdoWithParent; /** * Generate a MOS scale in a specific EDO with daughter relationship */ function mosInEdoWithDaughter(edo, largeSteps, smallSteps, options) { const scale = mosInEdo(edo, largeSteps, smallSteps, options); const daughterMap = (0, index_1.mosWithDaughter)(largeSteps, smallSteps, { ...options, period: edo, }); return { ...scale, daughterMap, }; } exports.mosInEdoWithDaughter = mosInEdoWithDaughter; /** * Find all valid MOS scales in a specific EDO */ function findAllMosInEdo(edo, minSize = 2, maxSize, maxHardness) { if (edo <= 0) { throw new Error('EDO must be positive'); } if (minSize < 2) { throw new Error('Minimum size must be at least 2'); } const result = []; maxSize = maxSize !== null && maxSize !== void 0 ? maxSize : edo; for (let largeSteps = 1; largeSteps <= maxSize; largeSteps++) { for (let smallSteps = 1; smallSteps <= maxSize - largeSteps; smallSteps++) { if (largeSteps + smallSteps < minSize) { continue; } try { const scale = mosInEdo(edo, largeSteps, smallSteps); if (!maxHardness || scale.sizeOfLargeStep / scale.sizeOfSmallStep <= maxHardness) { result.push(scale); } } catch (error) { // Skip invalid scales continue; } } } return result; } exports.findAllMosInEdo = findAllMosInEdo; //# sourceMappingURL=index.js.map