diff --git a/src/components/ScaleBuilder.vue b/src/components/ScaleBuilder.vue index 3c0ce3d3..9d28ddcd 100644 --- a/src/components/ScaleBuilder.vue +++ b/src/components/ScaleBuilder.vue @@ -535,6 +535,8 @@ async function doImport(importerKey: ImporterKey, event: Event) { (); + const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]); const octave = new Interval( @@ -24,6 +29,10 @@ const degreesString = ref("1 2 3 4 5"); const jumpsElement = ref(null); const degreesElement = ref(null); +const singleStepOnly = computed( + () => divisions.value !== Math.round(divisions.value) +); + const safeScaleSize = computed(() => Math.round(clamp(1, 1024, divisions.value)) ); @@ -52,10 +61,15 @@ watch(degrees, (newValue) => { }); function updateFromDivisions() { - jumpsString.value = Array(safeScaleSize.value).fill("1").join(" "); - degreesString.value = [...Array(safeScaleSize.value).keys()] - .map((k) => (k + 1).toString()) - .join(" "); + if (singleStepOnly.value) { + jumpsString.value = ""; + degreesString.value = ""; + } else { + jumpsString.value = Array(safeScaleSize.value).fill("1").join(" "); + degreesString.value = [...Array(safeScaleSize.value).keys()] + .map((k) => (k + 1).toString()) + .join(" "); + } } function updateFromJumps() { @@ -87,16 +101,37 @@ function updateFromDegrees() { } function generate() { - // Implicit use of safeScaleSize. Note that small subsets of huge EDOs cause no issues. - const scale = Scale.fromEqualTemperamentSubset(degrees.value, equave.value); - // Obtain effective divisions from the scale just generated. - const effectiveDivisions = - scale.getInterval(0).options.preferredEtDenominator; - emit( - "update:scaleName", - `${effectiveDivisions} equal divisions of ${equave.value.toString()}` - ); - emit("update:scale", scale); + const lineOptions = { + centsFractionDigits: props.centsFractionDigits, + decimalFractionDigits: props.decimalFractionDigits, + }; + if (singleStepOnly.value) { + const stepCents = equave.value.totalCents() / divisions.value; + const scale = Scale.fromIntervalArray([ + new Interval( + ExtendedMonzo.fromCents(stepCents, DEFAULT_NUMBER_OF_COMPONENTS), + "cents", + undefined, + lineOptions + ), + ]); + emit("update:scaleName", `${scale.equave.name} cET`); + emit("update:scale", scale); + } else { + // Implicit use of safeScaleSize. Note that small subsets of huge EDOs cause no issues. + const scale = Scale.fromEqualTemperamentSubset( + degrees.value, + equave.value.mergeOptions(lineOptions) + ); + // Obtain effective divisions from the scale just generated. + const effectiveDivisions = + scale.getInterval(0).options.preferredEtDenominator; + emit( + "update:scaleName", + `${effectiveDivisions} equal divisions of ${equave.value.toString()}` + ); + emit("update:scale", scale); + } }