Skip to content

Commit

Permalink
Store lattice intervals in the database
Browse files Browse the repository at this point in the history
ref #698
  • Loading branch information
frostburn committed May 19, 2024
1 parent 09e5e6a commit ceb253e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 {@}\" --",
Expand Down
3 changes: 2 additions & 1 deletion src/stores/__tests__/scale.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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)
})
})
13 changes: 11 additions & 2 deletions src/stores/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ export const useScaleStore = defineStore('scale', () => {
sourceText,
scale,
relativeIntervals,
latticeIntervals,
colors,
labels,
error,
Expand Down Expand Up @@ -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
Expand All @@ -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']
Expand All @@ -528,7 +538,6 @@ export const useScaleStore = defineStore('scale', () => {
sourcePrefix,
latticePermutation,
inverseLatticePermutation,
latticeIntervals,
latticeColors,
latticeLabels,
frequencies,
Expand Down

0 comments on commit ceb253e

Please sign in to comment.