Skip to content

Commit

Permalink
Update sonic-weave dependency
Browse files Browse the repository at this point in the history
Adapt to API changes.
Fix a misspelled prop.

SonicWeave changelog:
- Fix ternary `x if y else z` associativity
- Implement vector broadcasting `x where y else z`
- Implement some() and every()
- Admit record literals at the start of expressions
- Make both `fun 3/2` and `3/2 fun` legal syntax for `fun(3/2)`
- Add shape params to random and randomCents
- Dedicate degree symbol to edosteps
- Apply vector/record broadcasting rules to most operators and built-ins
- Implement vor, vand and vnot vectorizing versions of boolean "or/and/not"
  • Loading branch information
frostburn committed Apr 30, 2024
1 parent c80dcd7 commit fe8129b
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 45 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 {@}\" --",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModifyScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/ApproximateByRatios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/CoalesceDuplicates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/modification/ConvertType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions src/components/modals/modification/EnumerateScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/EqualizeScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/ExpandScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/MergeOffsets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/RandomVariance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/RepeatScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/RotateScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/StretchScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/TakeSubset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/modification/TemperScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 11 additions & 10 deletions src/stores/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +21,8 @@ import {
StatementVisitor,
ExpressionVisitor,
builtinNode,
repr
repr,
getGlobalVisitor
} from 'sonic-weave'
import {
APP_TITLE,
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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) {
Expand Down Expand Up @@ -484,7 +485,7 @@ export const useScaleStore = defineStore('scale', () => {
whiteIndices,
whiteModeOffset,
// Methods
getVisitors,
getUserScopeVisitor,
computeScale,
getFrequency,
colorForIndex,
Expand Down
9 changes: 3 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
getSourceVisitor,
Interval,
parseAST,
repr,
StatementVisitor
repr
} from 'sonic-weave'

/**
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/views/VirtualKeyboardView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
></VirtualKeyboard>
Expand Down

0 comments on commit fe8129b

Please sign in to comment.