Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta 21 #673

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions src/components/modals/generation/HistoricalScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ function generate(expand = true) {
) {
emit('update:baseFrequency', FREQUENCY_C)
emit('update:baseMidiNote', MIDI_NOTE_C)
source += `\nlabel([${KEY_COLORS_C.join(', ')}])`
source += `\n[${KEY_COLORS_C.join(', ')}]`
const labels: string[] = []
for (let i = 0; i < historical.size; ++i) {
labels[mmod(7 * (i - historical.down) - 1, historical.size)] = JSON.stringify(
spineLabel(i - historical.down)
)
}
source += `\nlabel([${labels.join(', ')}])`
source += `\n[${labels.join(', ')}]`
}
if (expand) {
source = expandCode(source)
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/generation/RankTwo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function generate(expand = true) {
} else {
up = size - n - rank2.down
}
labelString = `\nlabel([${colors.join(', ')}])`
labelString = `\n[${colors.join(', ')}]`
}
const source = `rank2(${rank2.generator.toString()}, ${up}, ${down}, ${rank2.period.toString()}, ${n})${labelString}`
emit('update:scaleName', `Rank 2 temperament (${rank2.generatorString}, ${rank2.periodString})`)
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
6 changes: 3 additions & 3 deletions src/presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ragabhairavi": {
"name": "Raga Bhairavi",
"source": "eulerGenus(135, 5)\n$[5] = 16/15\nsort()\nlabel([black, white, black, black, white, black, black, white])\n",
"source": "eulerGenus(135, 5)\n$[5] = 16/15\nsort()\n[black, white, black, black, white, black, black, white]\n",
"categories": ["traditional", "just intonation"]
},
"ragakafi": {
Expand Down Expand Up @@ -134,7 +134,7 @@
},
"pythagorean": {
"name": "Pythagorean",
"source": "[3^i rdc 2 white for i of [-2..4]] ['F', 'C', 'G', 'D', 'A', 'E', 'B']\n[3^i rdc 2 black for i of [-7..-3]] ['G♭', 'D♭', 'A♭', 'E♭', 'B♭']\nsort()\n",
"source": "(3^[-2..4] rdc 2) white ['F', 'C', 'G', 'D', 'A', 'E', 'B']\n(3^[-7..-3] rdc 2) black ['G♭', 'D♭', 'A♭', 'E♭', 'B♭']\nsort()\n",
"categories": ["traditional", "just intonation"],
"baseMidiNote": 67,
"baseFrequency": 391
Expand Down Expand Up @@ -238,7 +238,7 @@
},
"22orwell9": {
"name": "22edo orwell[9]",
"source": "rank2(7/6, 4, 4)\nlabel([black, white, black, white, white, black, white, black, white])\n22@\n",
"source": "rank2(7/6, 4, 4)\n[black, white, black, white, white, black, white, black, white]\n22@\n",
"categories": ["MOS", "equal temperament"]
},
"22pajara12": {
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
Loading