From ceb253e4e12c5dd5bcf0504e8fe9d880803df575 Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Sun, 19 May 2024 10:07:10 +0300 Subject: [PATCH] Store lattice intervals in the database ref #698 --- package-lock.json | 4 ++-- package.json | 2 +- src/stores/__tests__/scale.spec.ts | 3 ++- src/stores/scale.ts | 13 +++++++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index a1ec8b22..31062541 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scale-workshop", - "version": "3.0.0-beta.29", + "version": "3.0.0-beta.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "scale-workshop", - "version": "3.0.0-beta.29", + "version": "3.0.0-beta.30", "dependencies": { "isomorphic-qwerty": "^0.0.2", "ji-lattice": "^0.0.3", diff --git a/package.json b/package.json index a0920983..40eb8e46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scale-workshop", - "version": "3.0.0-beta.29", + "version": "3.0.0-beta.30", "scripts": { "dev": "vite", "build": "run-p type-check \"build-only {@}\" --", diff --git a/src/stores/__tests__/scale.spec.ts b/src/stores/__tests__/scale.spec.ts index 661e1a53..14aac5ae 100644 --- a/src/stores/__tests__/scale.spec.ts +++ b/src/stores/__tests__/scale.spec.ts @@ -4,7 +4,7 @@ import { useScaleStore } from '../scale' import { Scale } from '../../scale' import { Interval } from 'sonic-weave' -const SERIALIZED = String.raw`{"scale":{"type":"ScaleWorkshopScale","intervalRatios":[1.148698354997035,1.3195079107728942,1.515716566510398,1.7411011265922482,2],"baseFrequency":261.6255653005987,"baseMidiNote":60,"title":""},"relativeIntervals":[{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[1,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":1,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[2,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":2,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[3,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":3,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[4,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":4,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[1,1],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":5,"d":5,"p":null,"q":null},"t":[]}],"name":"","baseMidiNote":60,"userBaseFrequency":261.63,"autoFrequency":true,"autoColors":"silver","sourceText":"tet(5)","colors":["silver","silver","silver","silver","gray"],"labels":["1\\5","2\\5","3\\5","4\\5","5\\5"],"error":"","warning":"","isomorphicVertical":5,"isomorphicHorizontal":1,"keyboardMode":"isomorphic","equaveShift":0,"degreeShift":0,"pianoMode":"Asdf","accidentalColor":"black","lowAccidentalColor":"maroon","middleAccidentalColor":"navy","highAccidentalColor":"indigo"}` +const SERIALIZED = String.raw`{"scale":{"type":"ScaleWorkshopScale","intervalRatios":[1.148698354997035,1.3195079107728942,1.515716566510398,1.7411011265922482,2],"baseFrequency":261.6255653005987,"baseMidiNote":60,"title":""},"relativeIntervals":[{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[1,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":1,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[2,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":2,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[3,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":3,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[4,5],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":4,"d":5,"p":null,"q":null},"t":[]},{"type":"Interval","v":{"type":"TimeMonzo","t":{"n":0,"d":1},"p":[1,1],"r":{"n":1,"d":1}},"d":1,"s":0,"l":"","n":{"type":"n","n":5,"d":5,"p":null,"q":null},"t":[]}],"latticeIntervals":null,"name":"","baseMidiNote":60,"userBaseFrequency":261.63,"autoFrequency":true,"autoColors":"silver","sourceText":"tet(5)","colors":["silver","silver","silver","silver","gray"],"labels":["1\\5","2\\5","3\\5","4\\5","5\\5"],"error":"","warning":"","isomorphicVertical":5,"isomorphicHorizontal":1,"keyboardMode":"isomorphic","equaveShift":0,"degreeShift":0,"pianoMode":"Asdf","accidentalColor":"black","lowAccidentalColor":"maroon","middleAccidentalColor":"navy","highAccidentalColor":"indigo"}` describe('Scale store', () => { beforeEach(() => { @@ -38,5 +38,6 @@ describe('Scale store', () => { expect(centss[3]).toBeCloseTo(720) expect(centss[4]).toBeCloseTo(960) expect(centss[5]).toBeCloseTo(1200) + expect(scale.latticeIntervals).toHaveLength(5) }) }) diff --git a/src/stores/scale.ts b/src/stores/scale.ts index 3643e5f3..e03f75ca 100644 --- a/src/stores/scale.ts +++ b/src/stores/scale.ts @@ -455,6 +455,7 @@ export const useScaleStore = defineStore('scale', () => { sourceText, scale, relativeIntervals, + latticeIntervals, colors, labels, error, @@ -490,6 +491,11 @@ export const useScaleStore = defineStore('scale', () => { scale: scale.value.toJSON(), relativeIntervals: relativeIntervals.value.map((i) => i.toJSON()) } + if (relativeIntervals.value === latticeIntervals.value) { + result.latticeIntervals = null + } else { + result.latticeIntervals = latticeIntervals.value.map((i) => i.toJSON()) + } for (const [key, value] of Object.entries(LIVE_STATE)) { if (key in result) { continue @@ -506,7 +512,11 @@ export const useScaleStore = defineStore('scale', () => { function fromJSON(data: any) { skipNextRerollWatch = true for (const key in LIVE_STATE) { - LIVE_STATE[key as keyof typeof LIVE_STATE].value = data[key] + if (key === 'latticeIntervals' && !data[key]) { + latticeIntervals.value = data['relativeIntervals'] + } else { + LIVE_STATE[key as keyof typeof LIVE_STATE].value = data[key] + } } id.value = data['id'] uploadedId.value = data['id'] @@ -528,7 +538,6 @@ export const useScaleStore = defineStore('scale', () => { sourcePrefix, latticePermutation, inverseLatticePermutation, - latticeIntervals, latticeColors, latticeLabels, frequencies,