Skip to content

Commit

Permalink
Make it possible to assign explicit equave in latticeView
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed Jun 6, 2024
1 parent 13d9cce commit a3ed316
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/modals/generation/GeneratorSequence.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function generate(kind: 'expanded' | 'raw' | 'lattice' = 'expanded') {
source += `repeat(${modal.numPeriods})\n`
}
source += 'unshift(pop())\n'
source += 'latticeView()\n'
source += `latticeView(${modal.period})\n`
source += 'sort()\n'
} else {
source = `gs(${arrayToString(modal.generators)}, ${modal.size}`
Expand Down
10 changes: 8 additions & 2 deletions src/stores/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const useScaleStore = defineStore('scale', () => {
const sourceText = ref('')
const relativeIntervals = ref(INTERVALS_12TET)
const latticeIntervals = ref(INTERVALS_12TET)
const latticeEquave = ref<Interval | undefined>(undefined)
const colors = ref(defaultColors(baseMidiNote.value))
const labels = ref(defaultLabels(baseMidiNote.value, accidentalPreference.value))
const error = ref('')
Expand Down Expand Up @@ -293,7 +294,7 @@ export const useScaleStore = defineStore('scale', () => {
syncValues({ accidentalPreference, hasLeftOfZ, gas })

// Extra builtins
function latticeView(this: ExpressionVisitor) {
function latticeView(this: ExpressionVisitor, equave?: Interval) {
const scale = this.currentScale
for (let i = 0; i < scale.length; ++i) {
scale[i] = scale[i].shallowClone()
Expand All @@ -302,8 +303,11 @@ export const useScaleStore = defineStore('scale', () => {
}
const rel = relative.bind(this)
latticeIntervals.value = scale.map((i) => rel(i))

latticeEquave.value = equave
}
latticeView.__doc__ = 'Store the current scale to be displayed in the lattice tab.'
latticeView.__doc__ =
'Store the current scale to be displayed in the lattice tab. Optionally with an explicit equave.'
latticeView.__node__ = builtinNode(latticeView)

function warn(this: ExpressionVisitor, ...args: any[]) {
Expand Down Expand Up @@ -366,6 +370,7 @@ export const useScaleStore = defineStore('scale', () => {
error.value = ''
warning.value = ''
latticeIntervals.value = []
latticeEquave.value = undefined
const globalVisitor = getGlobalScaleWorkshopVisitor()
const visitor = new StatementVisitor(globalVisitor)
visitor.isUserRoot = true
Expand Down Expand Up @@ -457,6 +462,7 @@ export const useScaleStore = defineStore('scale', () => {
scale,
relativeIntervals,
latticeIntervals,
latticeEquave,
colors,
labels,
error,
Expand Down
7 changes: 5 additions & 2 deletions src/views/LatticeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ function inferConfig() {
return
}
let equave = monzos[monzos.length - 1]
if (scale.latticeEquave) {
equave = scale.latticeEquave.value
}
let isFractional = true
let isEqualTemperament = true
for (const monzo of monzos) {
Expand All @@ -121,7 +126,6 @@ function inferConfig() {
}
let equaveIndex = 0
const equave = monzos.pop()!
const { n, d } = equave.toFraction()
if (d === 1 && isPrime(n)) {
equaveIndex = primeLimit(n, true) - 1
Expand All @@ -140,7 +144,6 @@ function inferConfig() {
}
if (isEqualTemperament) {
const equave = monzos.pop()!
if (!equave.isFractional()) {
return
}
Expand Down

0 comments on commit a3ed316

Please sign in to comment.