Skip to content

Commit

Permalink
Implement soft limits to approximation numerators and denominators
Browse files Browse the repository at this point in the history
ref #544
  • Loading branch information
frostburn committed Feb 13, 2024
1 parent 551aa18 commit b927880
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/modals/modification/ApproximateByHarmonics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import Modal from '@/components/ModalDialog.vue'
import type { Scale } from 'scale-workshop-core'
import { useModalStore } from '@/stores/modal'
import { computed } from 'vue'
import { centsToValue } from 'xen-dev-utils'
const props = defineProps<{
scale: Scale
Expand All @@ -11,6 +13,14 @@ const emit = defineEmits(['update:scale', 'cancel'])
const modal = useModalStore()
const maxDenominator = computed(() => {
let maxCents = 0
for (let i = 0; i < props.scale.size; ++i) {
maxCents = Math.max(Math.abs(props.scale.getCents(i)))
}
return Math.floor(Number.MAX_SAFE_INTEGER / centsToValue(maxCents))
})
function modify() {
emit('update:scale', props.scale.approximateHarmonics(modal.largeInteger))
}
Expand All @@ -29,6 +39,7 @@ function modify() {
id="approximate-harmonics-denominator"
type="number"
min="1"
:max="maxDenominator"
class="control"
v-model="modal.largeInteger"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function modify() {
id="approximate-subharmonics-numerator"
type="number"
min="1"
:max="Number.MAX_SAFE_INTEGER"
class="control"
v-model="modal.largeInteger"
/>
Expand Down

0 comments on commit b927880

Please sign in to comment.