Skip to content

Commit

Permalink
Update sonic-weave dependency
Browse files Browse the repository at this point in the history
Adapt code to handle possible irrational values.

SonicWeave changelog:
* Fix formatting of huge quantities
* Clarify distinction between radical and real quantities
* Make ups abstract (only affecting tempering, no cent shimmer)
  • Loading branch information
frostburn committed Apr 17, 2024
1 parent 5dfdbf1 commit 4bc849d
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 77 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.12",
"version": "3.0.0-beta.13",
"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.14",
"sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.17",
"sw-synth": "^0.1.0",
"temperaments": "^0.5.3",
"vue": "^3.3.4",
Expand Down
4 changes: 2 additions & 2 deletions src/analysis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Interval, TimeMonzo } from 'sonic-weave'
import { Interval, TimeMonzo, TimeReal } from 'sonic-weave'
import { circleDistance, mmod, valueToCents } from 'xen-dev-utils'

const EPSILON = 1e-6
Expand Down Expand Up @@ -446,7 +446,7 @@ export function varietySignature(matrix: Interval[][]) {
return result
}
for (let i = 0; i < matrix[0].length; ++i) {
const variants: TimeMonzo[] = [matrix[0][i].value]
const variants: (TimeMonzo | TimeReal)[] = [matrix[0][i].value]
search: for (let j = 1; j < matrix.length; ++j) {
const monzo = matrix[j][i].value
for (const variant of variants) {
Expand Down
12 changes: 8 additions & 4 deletions src/components/JustIntonationLattice.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useJiLatticeStore } from '@/stores/ji-lattice'
import { spanLattice } from 'ji-lattice'
import { type Interval } from 'sonic-weave'
import { TimeMonzo, type Interval } from 'sonic-weave'
import { computed, nextTick, reactive, ref, watch } from 'vue'
import { dot } from 'xen-dev-utils'
Expand All @@ -23,9 +23,13 @@ const monzos = computed(() => {
const result: number[][] = []
for (const interval of props.relativeIntervals) {
const value = interval.value.clone()
value.numberOfComponents = numComponents
const monzo = interval.value.primeExponents.map((pe) => pe.valueOf())
result.push(monzo)
if (value instanceof TimeMonzo) {
value.numberOfComponents = numComponents
const monzo = value.primeExponents.map((pe) => pe.valueOf())
result.push(monzo)
} else {
result.push(Array(numComponents).fill(0))
}
}
return result
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/generation/ConcordanceShell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function generate(shell = true, expand = true) {
}
let postfix = `\\${modal.largeDivisions}`
if (modal.equave.compare(OCTAVE)) {
postfix += `<${linear(modal.equave).toString()}>`
postfix += `ed ${linear(modal.equave).toString()}`
}
for (const [degree, label] of data) {
source += `${degree}${postfix} "${label}"\n`
Expand Down
4 changes: 2 additions & 2 deletions src/components/modals/generation/RankTwo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { expandCode, gapKeyColors, parseCents, setAndReportValidity } from '@/ut
import ScaleLineInput from '@/components/ScaleLineInput.vue'
import { useRank2Store } from '@/stores/tempering'
import { useStateStore } from '@/stores/state'
import { Interval, timeMonzoAs } from 'sonic-weave'
import { Interval, intervalValueAs } from 'sonic-weave'
import { useScaleStore } from '@/stores/scale'
const state = useStateStore()
Expand Down Expand Up @@ -84,7 +84,7 @@ watch(
function flipGenerator() {
const g = rank2.generator
const value = g.value.inverse().reduce(rank2.period.value)
rank2.generator = new Interval(value, g.domain, timeMonzoAs(value, g.node), g)
rank2.generator = new Interval(value, g.domain, 0, intervalValueAs(value, g.node), g)
rank2.generatorString = rank2.generator.toString()
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/generation/SpanLattice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useLatticeStore } from '@/stores/tempering'
import { setAndReportValidity } from '@/utils'
import { useStateStore } from '@/stores/state'
import { arrayToString, expandCode, parseInterval } from '@/utils'
import { Interval, timeMonzoAs } from 'sonic-weave'
import { Interval, intervalValueAs } from 'sonic-weave'
const emit = defineEmits(['update:source', 'update:scaleName', 'cancel'])
Expand Down Expand Up @@ -60,9 +60,9 @@ function flip(index: number) {
const b = lattice.basis[index]
const domain = b.domain
const generator = b.value.inverse().reduce(lattice.equave.value)
const node = timeMonzoAs(generator, b.node)
const node = intervalValueAs(generator, b.node)
const newBasis = [...lattice.basis]
newBasis.splice(index, 1, new Interval(generator, domain, node, b))
newBasis.splice(index, 1, new Interval(generator, domain, 0, node, b))
lattice.basisString = newBasis.map((gen) => gen.toString()).join(' ')
}
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 @@ -39,7 +39,7 @@ function modify(expand = true) {
let postfix = `\\${modal.largeDivisions}`
const equave = scale.relativeIntervals[scale.relativeIntervals.length - 1]
if (equave.compare(OCTAVE)) {
postfix += `<${linear(equave).toString()}>`
postfix += `ed ${linear(equave).toString()}`
}
scale.sourceText = degrees.map((d) => `${d}${postfix}`).join('\n')
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/modals/modification/MergeOffsets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Modal from '@/components/ModalDialog.vue'
import { useModalStore } from '@/stores/modal'
import { useScaleStore } from '@/stores/scale'
import { arrayToString } from '@/utils'
import type { Interval } from 'sonic-weave'
import { ref, watch } from 'vue'
const emit = defineEmits(['done', 'cancel'])
Expand All @@ -17,7 +18,7 @@ watch(
)
function modify(expand = true) {
scale.sourceText += `\nmergeOffset(${arrayToString(modal.offsets)}, '${modal.overflowType}')`
scale.sourceText += `\nmergeOffset(${arrayToString(modal.offsets as Interval[])}, '${modal.overflowType}')`
if (expand) {
const { visitor, defaults } = scale.getVisitors()
scale.sourceText = visitor.expand(defaults)
Expand Down
6 changes: 2 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ export const MIDI_NOTE_COLORS = [
// Some often used intervals
export const OCTAVE = new Interval(
TimeMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
'linear',
{ type: 'FractionLiteral', numerator: 2n, denominator: 1n }
'linear'
)
export const FIFTH = new Interval(
TimeMonzo.fromFraction('3/2', DEFAULT_NUMBER_OF_COMPONENTS),
'linear',
{ type: 'FractionLiteral', numerator: 3n, denominator: 2n }
'linear'
)
export const THIRD = new Interval(
TimeMonzo.fromFraction('5/4', DEFAULT_NUMBER_OF_COMPONENTS),
Expand Down
34 changes: 7 additions & 27 deletions src/exporters/__tests__/korg.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { KorgExporter, KorgModels, KorgExporterError } from '../korg'

import { getTestData } from './test-data'
import { Scale } from '../../scale'
import { Interval, TimeMonzo } from 'sonic-weave'
import { Interval, TimeReal } from 'sonic-weave'

describe('Korg exporters', () => {
it('can export a scale encountered while debugging issue #393', async () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Korg exporters', () => {

it('throws error if 12-note octave tuning is selected, but equave is not 2/1', () => {
const params = getTestData("Korg 'logue exporter unit test v0.0.0")
params.relativeIntervals.push(new Interval(TimeMonzo.fromCents(100.0, 3), 'logarithmic'))
params.relativeIntervals.push(new Interval(TimeReal.fromCents(100.0), 'logarithmic'))
params.sourceText += '\n100.'
const ratios = params.relativeIntervals.map((i) => i.value.valueOf())
params.scale = new Scale(ratios, 440, 69)
Expand All @@ -101,20 +101,12 @@ describe('Korg exporters', () => {

it('throws error if 12-note octave tuning is selected, but scale contains an interval that is below unison', () => {
const params = getTestData("Korg 'logue exporter unit test v0.0.0")
params.relativeIntervals.splice(
0,
0,
new Interval(TimeMonzo.fromCents(-500.0, 3), 'logarithmic')
)
params.relativeIntervals.splice(0, 0, new Interval(TimeReal.fromCents(-500.0), 'logarithmic'))
params.sourceText = '-500.\n' + params.sourceText

// Make sure there's 12 notes in the test scale
while (params.relativeIntervals.length < 12) {
params.relativeIntervals.splice(
0,
0,
new Interval(TimeMonzo.fromCents(100.0, 3), 'logarithmic')
)
params.relativeIntervals.splice(0, 0, new Interval(TimeReal.fromCents(100.0), 'logarithmic'))
params.sourceText += '100.\n' + params.sourceText
}
const ratios = params.relativeIntervals.map((i) => i.value.valueOf())
Expand All @@ -127,19 +119,11 @@ describe('Korg exporters', () => {

it('throws error if 12-note octave tuning is selected, but scale contains an interval that is greater than an octave', () => {
const params = getTestData("Korg 'logue exporter unit test v0.0.0")
params.relativeIntervals.splice(
0,
0,
new Interval(TimeMonzo.fromCents(1300.0, 3), 'logarithmic')
)
params.relativeIntervals.splice(0, 0, new Interval(TimeReal.fromCents(1300.0), 'logarithmic'))

// Make sure there's 12 notes in the test scale
while (params.relativeIntervals.length < 12) {
params.relativeIntervals.splice(
0,
0,
new Interval(TimeMonzo.fromCents(100.0, 3), 'logarithmic')
)
params.relativeIntervals.splice(0, 0, new Interval(TimeReal.fromCents(100.0), 'logarithmic'))
params.sourceText += '100.\n' + params.sourceText
}
const ratios = params.relativeIntervals.map((i) => i.value.valueOf())
Expand All @@ -155,11 +139,7 @@ describe('Korg exporters', () => {

// Make sure there's 12 notes in the test scale
while (params.relativeIntervals.length < 12) {
params.relativeIntervals.splice(
0,
0,
new Interval(TimeMonzo.fromCents(100.0, 3), 'logarithmic')
)
params.relativeIntervals.splice(0, 0, new Interval(TimeReal.fromCents(100.0), 'logarithmic'))
params.sourceText += '100.\n' + params.sourceText
}
const ratios = params.relativeIntervals.map((i) => i.value.valueOf())
Expand Down
17 changes: 9 additions & 8 deletions src/exporters/__tests__/test-data.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Interval, TimeMonzo, getSourceVisitor, parseAST, relative } from 'sonic-weave'
import { Interval, TimeMonzo, TimeReal, getSourceVisitor, parseAST, relative } from 'sonic-weave'
import type { ExporterParams } from '../base'
import { UNIX_NEWLINE, WINDOWS_NEWLINE } from '../../constants'
import { Scale } from '../../scale'
import { Fraction } from 'xen-dev-utils'

export function getTestData(appTitle: string) {
const absoluteC5 = new Interval(TimeMonzo.fromFractionalFrequency(528, 3), 'logarithmic', {
const absoluteC5 = new Interval(TimeMonzo.fromFractionalFrequency(528, 3), 'logarithmic', 0, {
type: 'AbsoluteFJS',
pitch: {
type: 'AbsolutePitch',
nominal: 'C',
accidentals: [],
octave: 5n
octave: 5
},
ups: 0,
lifts: 0,
Expand All @@ -24,7 +24,7 @@ export function getTestData(appTitle: string) {
const relativeC5 = relative.bind(ev)(absoluteC5)

const relativeIntervals = [
new Interval(TimeMonzo.fromEqualTemperament('100/1200', 2, 3), 'logarithmic', {
new Interval(TimeMonzo.fromEqualTemperament('100/1200', 2, 3), 'logarithmic', 0, {
type: 'CentsLiteral',
sign: '',
whole: 100n,
Expand All @@ -34,6 +34,7 @@ export function getTestData(appTitle: string) {
new Interval(
TimeMonzo.fromEqualTemperament(new Fraction(4, 5), new Fraction(2), 3),
'logarithmic',
0,
{
type: 'NedjiLiteral',
numerator: 4,
Expand All @@ -42,25 +43,25 @@ export function getTestData(appTitle: string) {
equaveDenominator: null
}
),
new Interval(TimeMonzo.fromFraction(new Fraction(5, 3), 3), 'linear', {
new Interval(TimeMonzo.fromFraction(new Fraction(5, 3), 3), 'linear', 0, {
type: 'FractionLiteral',
numerator: 5n,
denominator: 3n
}),
new Interval(TimeMonzo.fromValue(Math.E / 2, 3), 'linear', {
new Interval(TimeReal.fromValue(Math.E / 2), 'linear', 0, {
type: 'DecimalLiteral',
sign: '',
whole: 1n,
fractional: '3591409142295225',
flavor: 'r',
exponent: null
}),
new Interval(TimeMonzo.fromFraction(new Fraction(81, 80), 3).pow(5), 'linear', {
new Interval(TimeMonzo.fromFraction(new Fraction(81, 80), 3).pow(5), 'linear', 0, {
type: 'FractionLiteral',
numerator: 3486784401n,
denominator: 3276800000n
}),
new Interval(TimeMonzo.fromFraction(2, 3), 'linear', {
new Interval(TimeMonzo.fromFraction(2, 3), 'linear', 0, {
type: 'FractionLiteral',
numerator: 2n,
denominator: 1n
Expand Down
7 changes: 4 additions & 3 deletions src/exporters/reaper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseExporter } from '@/exporters/base'
import { Interval, timeMonzoAs } from 'sonic-weave'
import { Interval, TimeReal, intervalValueAs } from 'sonic-weave'
import { mmod, valueToCents } from 'xen-dev-utils'

export default class ReaperExporter extends BaseExporter {
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class ReaperExporter extends BaseExporter {
const interval = intervals[mmod(index - 1, intervals.length)]
const numEquaves = Math.floor((index - 1) / intervals.length)
const value = interval.value.mul(equave.pow(numEquaves))
if (interval.value.cents) {
if (value instanceof TimeReal) {
if (interval.domain === 'linear') {
file += value.valueOf().toFixed(digits).replace('.', ',')
} else {
Expand All @@ -68,7 +68,8 @@ export default class ReaperExporter extends BaseExporter {
file += new Interval(
value,
interval.domain,
timeMonzoAs(value, interval.node),
0,
intervalValueAs(value, interval.node),
interval
).toString()
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/historical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const useHistoricalStore = defineStore('historical', () => {
const monzo = generator.value.value
const g = monzo.valueOf()
let multiGenExponent = 1
if (!monzo.cents) {
if (monzo instanceof TimeMonzo) {
multiGenExponent = monzo.primeExponents.reduce(
(denom, component) => lcm(component.d, denom),
1
Expand Down
12 changes: 8 additions & 4 deletions src/stores/ji-lattice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineStore } from 'pinia'
import { kraigGrady9, type LatticeOptions, scottDakota24, primeRing72, align } from 'ji-lattice'
import { LOG_PRIMES, mmod } from 'xen-dev-utils'
import { computedAndError } from '@/utils'
import { parseChord } from 'sonic-weave'
import { TimeMonzo, parseChord } from 'sonic-weave'

export const useJiLatticeStore = defineStore('ji-lattice', () => {
// Kraig Grady's coordinates only go up to 23-limit, but it was the default in Scale Workshop 2.
Expand Down Expand Up @@ -58,9 +58,13 @@ export const useJiLatticeStore = defineStore('ji-lattice', () => {
const result: number[][] = []
for (const interval of edges.value) {
const value = interval.value.clone()
value.numberOfComponents = numComponents
const monzo = interval.value.primeExponents.map((pe) => pe.valueOf())
result.push(monzo)
if (value instanceof TimeMonzo) {
value.numberOfComponents = numComponents
const monzo = value.primeExponents.map((pe) => pe.valueOf())
result.push(monzo)
} else {
result.push(Array(numComponents).fill(0))
}
}
return result
})
Expand Down
Loading

0 comments on commit 4bc849d

Please sign in to comment.