diff --git a/package-lock.json b/package-lock.json index 99929ea0..569e0a97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scale-workshop", - "version": "3.0.0-beta.20", + "version": "3.0.0-beta.21", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "scale-workshop", - "version": "3.0.0-beta.20", + "version": "3.0.0-beta.21", "dependencies": { "isomorphic-qwerty": "^0.0.2", "ji-lattice": "^0.0.3", @@ -14,7 +14,7 @@ "moment-of-symmetry": "^0.4.2", "pinia": "^2.1.7", "qs": "^6.12.0", - "sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.29", + "sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.30", "sw-synth": "^0.1.0", "temperaments": "^0.5.3", "values.js": "^2.1.1", @@ -5467,8 +5467,8 @@ } }, "node_modules/sonic-weave": { - "version": "0.0.29", - "resolved": "git+ssh://git@github.com/xenharmonic-devs/sonic-weave.git#52afbd7d95faf3ae1c2ce33708456c35877828b5", + "version": "0.0.30", + "resolved": "git+ssh://git@github.com/xenharmonic-devs/sonic-weave.git#0f86d831eefdb5c5e77f6918b75b9e7e4fc50ae2", "license": "MIT", "dependencies": { "moment-of-symmetry": "^0.4.2", diff --git a/package.json b/package.json index 056cef22..65b048c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scale-workshop", - "version": "3.0.0-beta.20", + "version": "3.0.0-beta.21", "scripts": { "dev": "vite", "build": "run-p type-check \"build-only {@}\" --", @@ -21,7 +21,7 @@ "moment-of-symmetry": "^0.4.2", "pinia": "^2.1.7", "qs": "^6.12.0", - "sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.29", + "sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.30", "sw-synth": "^0.1.0", "temperaments": "^0.5.3", "values.js": "^2.1.1", diff --git a/src/components/ModifyScale.vue b/src/components/ModifyScale.vue index bc0931e0..1d76350e 100644 --- a/src/components/ModifyScale.vue +++ b/src/components/ModifyScale.vue @@ -109,7 +109,7 @@ function closeModals() { } function expandAndQuit() { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) scale.computeScale() emit('done') diff --git a/src/components/modals/modification/ApproximateByHarmonics.vue b/src/components/modals/modification/ApproximateByHarmonics.vue index 6d2d5aba..bd99929a 100644 --- a/src/components/modals/modification/ApproximateByHarmonics.vue +++ b/src/components/modals/modification/ApproximateByHarmonics.vue @@ -31,7 +31,7 @@ const error = computed(() => { function modify(expand = true) { scale.sourceText += `\ntoHarmonics(${modal.largeInteger})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/ApproximateByRatios.vue b/src/components/modals/modification/ApproximateByRatios.vue index ff84e4d4..5f9cec86 100644 --- a/src/components/modals/modification/ApproximateByRatios.vue +++ b/src/components/modals/modification/ApproximateByRatios.vue @@ -115,7 +115,7 @@ function modifyAndAdvance() { function modify(expand = true) { if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/ApproximateBySubharmonics.vue b/src/components/modals/modification/ApproximateBySubharmonics.vue index 943c9b79..1e5226c9 100644 --- a/src/components/modals/modification/ApproximateBySubharmonics.vue +++ b/src/components/modals/modification/ApproximateBySubharmonics.vue @@ -23,7 +23,7 @@ const error = computed(() => { function modify(expand = true) { scale.sourceText += `\ntoSubharmonics(${modal.largeInteger})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/CoalesceDuplicates.vue b/src/components/modals/modification/CoalesceDuplicates.vue index 855efaf9..1be5db55 100644 --- a/src/components/modals/modification/CoalesceDuplicates.vue +++ b/src/components/modals/modification/CoalesceDuplicates.vue @@ -12,7 +12,7 @@ const scale = useScaleStore() function modify(expand = true) { scale.sourceText += `\ncoalesce(${centString(modal.tolerance)}, '${modal.coalescingAction}', ${modal.preserveBoundary})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/ConvertType.vue b/src/components/modals/modification/ConvertType.vue index 340f7f0f..de006d36 100644 --- a/src/components/modals/modification/ConvertType.vue +++ b/src/components/modals/modification/ConvertType.vue @@ -23,7 +23,7 @@ onMounted(() => { function modify(expand = false) { scale.sourceText += '\n' if (modal.type === 'decimal') { - scale.sourceText += `interval => decimal(interval, ${myDecimalFractionDigits.value})` + scale.sourceText += `interval => interval lest decimal(interval, ${myDecimalFractionDigits.value})` } else if (modal.type === 'fraction') { if (modal.fractionTolerance || modal.preferredNumerator || modal.preferredEtEquaveDenominator) { scale.sourceText += `interval => interval lest fraction(interval, ${modal.fractionTolerance ? centString(modal.fractionTolerance) : 'niente'}, ${modal.preferredNumerator}, ${modal.preferredDenominator})` @@ -33,12 +33,12 @@ function modify(expand = false) { } else if (modal.type === 'nedji') { scale.sourceText += `interval => interval lest nedji(interval, ${modal.preferredEtNumerator}, ${modal.preferredEtDenominator}, ${modal.preferredEtEquaveNumerator}, ${modal.preferredEtEquaveDenominator})` } else if (modal.type === 'cents') { - scale.sourceText += `interval => cents(interval, ${myCentsFractionDigits.value})` + scale.sourceText += `interval => interval lest cents(interval, ${myCentsFractionDigits.value})` } else { scale.sourceText += `interval => interval lest ${modal.type}(interval)` } if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/EnumerateScale.vue b/src/components/modals/modification/EnumerateScale.vue index 24f1d867..74aa4268 100644 --- a/src/components/modals/modification/EnumerateScale.vue +++ b/src/components/modals/modification/EnumerateScale.vue @@ -8,7 +8,7 @@ const scale = useScaleStore() function overtonal() { scale.sourceText += ';elevate();simplify;map(repr)' - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() const overtones = visitor.currentScale.map(i => i.label) visitor.currentScale.length = 0 scale.sourceText = visitor.expand(defaults) @@ -22,7 +22,7 @@ function overtonal() { function undertonal() { scale.sourceText += ';reflect();elevate();simplify;map(repr)' - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() const undertones = visitor.currentScale.map(i => i.label) visitor.currentScale.length = 0 scale.sourceText = visitor.expand(defaults) @@ -36,7 +36,7 @@ function undertonal() { function retroversion() { scale.sourceText += ';retrovert();elevate();simplify;map(repr)' - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() const tones = visitor.currentScale.map(i => i.label) visitor.currentScale.length = 0 scale.sourceText = visitor.expand(defaults) @@ -50,7 +50,7 @@ function retroversion() { function revposition() { scale.sourceText += ';revpose();elevate();simplify;map(repr)' - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() const tones = visitor.currentScale.map(i => i.label) visitor.currentScale.length = 0 scale.sourceText = visitor.expand(defaults) diff --git a/src/components/modals/modification/EqualizeScale.vue b/src/components/modals/modification/EqualizeScale.vue index b5547c79..9cbea8c9 100644 --- a/src/components/modals/modification/EqualizeScale.vue +++ b/src/components/modals/modification/EqualizeScale.vue @@ -29,7 +29,7 @@ function modify(expand = true) { if (modal.errorModel === 'rooted') { scale.sourceText += `\nequalize(${modal.largeDivisions})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } } else { diff --git a/src/components/modals/modification/ExpandScale.vue b/src/components/modals/modification/ExpandScale.vue index a3fe5eea..39ed99c8 100644 --- a/src/components/modals/modification/ExpandScale.vue +++ b/src/components/modals/modification/ExpandScale.vue @@ -15,7 +15,7 @@ function modify() { if (modal.bleach) { scale.sourceText += ';bleach' } - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) scale.computeScale() emit('done') diff --git a/src/components/modals/modification/MergeOffsets.vue b/src/components/modals/modification/MergeOffsets.vue index c96cd124..84f78029 100644 --- a/src/components/modals/modification/MergeOffsets.vue +++ b/src/components/modals/modification/MergeOffsets.vue @@ -20,7 +20,7 @@ watch( function modify(expand = true) { scale.sourceText += `\nmergeOffset(${arrayToString(modal.offsets as Interval[])}, '${modal.overflowType}')` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/RandomVariance.vue b/src/components/modals/modification/RandomVariance.vue index 456f7e3f..d61e182a 100644 --- a/src/components/modals/modification/RandomVariance.vue +++ b/src/components/modals/modification/RandomVariance.vue @@ -25,7 +25,7 @@ const equave = computed(() => { function modify(expand = true) { scale.sourceText += `\nrandomVariance(${centString(modal.varianceAmount)}, ${modal.varyEquave})\ninterval => cents(interval, ${state.centsFractionDigits})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/RepeatScale.vue b/src/components/modals/modification/RepeatScale.vue index 0b03d7c9..52c2cbfc 100644 --- a/src/components/modals/modification/RepeatScale.vue +++ b/src/components/modals/modification/RepeatScale.vue @@ -11,7 +11,7 @@ const scale = useScaleStore() function modify(expand = true) { scale.sourceText += `\nrepeat(${modal.numRepeats})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/RotateScale.vue b/src/components/modals/modification/RotateScale.vue index f99f48ce..6a0da943 100644 --- a/src/components/modals/modification/RotateScale.vue +++ b/src/components/modals/modification/RotateScale.vue @@ -11,7 +11,7 @@ const scale = useScaleStore() function modify(expand = true) { scale.sourceText += `\nrotate(${modal.newUnison + 1})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/StretchScale.vue b/src/components/modals/modification/StretchScale.vue index 72a6dda3..2ebafaf7 100644 --- a/src/components/modals/modification/StretchScale.vue +++ b/src/components/modals/modification/StretchScale.vue @@ -16,7 +16,7 @@ const state = useStateStore() function modify(expand = true) { scale.sourceText += `\nstretch(${decimalString(modal.stretchAmount)})\ninterval => cents(interval, ${state.centsFractionDigits})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/TakeSubset.vue b/src/components/modals/modification/TakeSubset.vue index 5bcdd94e..055e20f8 100644 --- a/src/components/modals/modification/TakeSubset.vue +++ b/src/components/modals/modification/TakeSubset.vue @@ -38,7 +38,7 @@ function modify(expand = true) { subset.sort((a, b) => a - b) scale.sourceText += `\nsubset(${arrayToString(subset)})` if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/components/modals/modification/TemperScale.vue b/src/components/modals/modification/TemperScale.vue index 3457f814..e3fe9eb2 100644 --- a/src/components/modals/modification/TemperScale.vue +++ b/src/components/modals/modification/TemperScale.vue @@ -68,7 +68,7 @@ function modify(expand = true) { scale.sourceText += `\nPrimeMapping(${mapping.map((c) => c.toFixed(state.centsFractionDigits)).join(', ')})` } if (expand) { - const { visitor, defaults } = scale.getVisitors() + const { visitor, defaults } = scale.getUserScopeVisitor() scale.sourceText = visitor.expand(defaults) } scale.computeScale() diff --git a/src/stores/scale.ts b/src/stores/scale.ts index abb9146a..d576df51 100644 --- a/src/stores/scale.ts +++ b/src/stores/scale.ts @@ -10,7 +10,6 @@ import { defineStore } from 'pinia' import { computed, ref, watch } from 'vue' import { Fraction, mmod, mtof } from 'xen-dev-utils' import { - getSourceVisitor, parseAST, relative, Interval, @@ -22,7 +21,8 @@ import { StatementVisitor, ExpressionVisitor, builtinNode, - repr + repr, + getGlobalVisitor } from 'sonic-weave' import { APP_TITLE, @@ -307,7 +307,7 @@ export const useScaleStore = defineStore('scale', () => { warn.__node__ = builtinNode(warn) // Local helpers - function getGlobalVisitor() { + function getGlobalScaleWorkshopVisitor() { // Inject global variables const _ = Interval.fromInteger(baseMidiNote.value) const baseFreq = new Interval( @@ -323,7 +323,7 @@ export const useScaleStore = defineStore('scale', () => { latticeView, warn } - const visitor = getSourceVisitor(true, extraBuiltins) + const visitor = getGlobalVisitor(true, extraBuiltins) visitor.rootContext!.gas = gas.value // Declare base nominal and unison frequency @@ -336,10 +336,10 @@ export const useScaleStore = defineStore('scale', () => { } // Methods - function getVisitors() { - const globalVisitor = getGlobalVisitor() - const visitor = new StatementVisitor(globalVisitor) - visitor.isUserRoot = true + function getUserScopeVisitor() { + const globalVisitor = getGlobalScaleWorkshopVisitor() + const visitor = new StatementVisitor(globalVisitor); + visitor.isUserRoot = true; const defaults = visitor.rootContext!.clone() defaults.gas = gas.value @@ -361,8 +361,9 @@ export const useScaleStore = defineStore('scale', () => { error.value = '' warning.value = '' latticeIntervals.value = [] - const globalVisitor = getGlobalVisitor() + const globalVisitor = getGlobalScaleWorkshopVisitor() const visitor = new StatementVisitor(globalVisitor) + visitor.isUserRoot = true; const ast = parseAST(sourceText.value) let userDeclaredPitch = false for (const statement of ast.body) { @@ -484,7 +485,7 @@ export const useScaleStore = defineStore('scale', () => { whiteIndices, whiteModeOffset, // Methods - getVisitors, + getUserScopeVisitor, computeScale, getFrequency, colorForIndex, diff --git a/src/utils.ts b/src/utils.ts index fc5a5bb7..fc4fe9f8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,8 +5,7 @@ import { getSourceVisitor, Interval, parseAST, - repr, - StatementVisitor + repr } from 'sonic-weave' /** @@ -60,10 +59,8 @@ export function splitText(text: string) { } export function expandCode(source: string) { - const globalVisitor = getSourceVisitor() - const defaults = globalVisitor.rootContext!.clone() - const visitor = new StatementVisitor(globalVisitor) - visitor.isUserRoot = true + const visitor = getSourceVisitor() + const defaults = visitor.rootContext!.clone() const ast = parseAST(source) for (const statement of ast.body) { const interupt = visitor.visit(statement) diff --git a/src/views/VirtualKeyboardView.vue b/src/views/VirtualKeyboardView.vue index 32685447..32c99e98 100644 --- a/src/views/VirtualKeyboardView.vue +++ b/src/views/VirtualKeyboardView.vue @@ -49,7 +49,7 @@ type NoteOnCallback = (index: number) => NoteOff :centss="scale.centss" :labelMap="scale.labelForIndex" :showLabel="state.showKeyboardLabel" - :showCent="state.showKeyboardCents" + :showCents="state.showKeyboardCents" :showRatio="state.showKeyboardRatio" :showFrequency="state.showKeyboardFrequency" >