From 77411822c7055627352aa9cd077b4baeb53e3e94 Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Sun, 1 Jan 2023 19:43:40 +0200 Subject: [PATCH] Upgrade temperaments dependency for lightweight algorithms for large subgroups ref #397 --- src/__tests__/tempering.spec.ts | 33 +++++++- src/components/modals/generation/RankTwo.vue | 9 ++- .../modals/modification/TemperScale.vue | 77 +++++++++++++++---- src/constants.ts | 7 ++ src/tempering.ts | 12 +++ 5 files changed, 119 insertions(+), 19 deletions(-) diff --git a/src/__tests__/tempering.spec.ts b/src/__tests__/tempering.spec.ts index 9e600a0f..d36c2029 100644 --- a/src/__tests__/tempering.spec.ts +++ b/src/__tests__/tempering.spec.ts @@ -7,9 +7,40 @@ import { makeRank2FromVals, mosPatternsRank2FromCommas, mosPatternsRank2FromVals, + toPrimeMapping, } from "../tempering"; -import { arraysEqual, Fraction, valueToCents } from "xen-dev-utils"; +import { + arraysEqual, + Fraction, + PRIME_CENTS, + valueToCents, +} from "xen-dev-utils"; import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core"; +import { Subgroup } from "temperaments"; +import { DEFAULT_NUMBER_OF_COMPONENTS } from "../constants"; + +describe("Prime map converter", () => { + it("does (almost) nothing in 5-limit JI", () => { + const fiveLimit = PRIME_CENTS.slice(0, 3); + const mapping = toPrimeMapping(fiveLimit, new Subgroup(5)); + expect(mapping[0]).toBeCloseTo(fiveLimit[0]); + expect(mapping[1]).toBeCloseTo(fiveLimit[1]); + expect(mapping[2]).toBeCloseTo(fiveLimit[2]); + expect(mapping.length).toBe(DEFAULT_NUMBER_OF_COMPONENTS); + expect(mapping[3]).toBeCloseTo(PRIME_CENTS[3]); + }); + + it("converts a mapping in 2.3.13/5 to 2.3.5.7.11.13...", () => { + const original = [1200, 1901, 1654]; + const mapping = toPrimeMapping(original, new Subgroup("2.3.13/5")); + expect(mapping[0]).toBeCloseTo(1200); + expect(mapping[1]).toBeCloseTo(1901); + expect(mapping[3]).toBeCloseTo(PRIME_CENTS[3]); + expect(mapping[4]).toBeCloseTo(PRIME_CENTS[4]); + expect(mapping[5] - mapping[2]).toBeCloseTo(1654); + expect(mapping[6]).toBeCloseTo(PRIME_CENTS[6]); + }); +}); describe("Temperament Mapping", () => { it("calculates POTE meantone", () => { diff --git a/src/components/modals/generation/RankTwo.vue b/src/components/modals/generation/RankTwo.vue index a1dd4dba..36934f2c 100644 --- a/src/components/modals/generation/RankTwo.vue +++ b/src/components/modals/generation/RankTwo.vue @@ -1,5 +1,8 @@