Skip to content

Commit

Permalink
Make it possible to create non-integer equal temperaments as cETs
Browse files Browse the repository at this point in the history
ref #326
  • Loading branch information
frostburn committed Dec 16, 2022
1 parent 863b04d commit a4069b0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/components/ScaleBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ async function doImport(importerKey: ImporterKey, event: Event) {

<EqualTemperamentModal
:show="showEqualTemperamentModal"
:centsFractionDigits="centsFractionDigits"
:decimalFractionDigits="decimalFractionDigits"
@update:scaleName="emit('update:scaleName', $event)"
@update:scale="
showEqualTemperamentModal = false;
Expand Down
63 changes: 49 additions & 14 deletions src/components/modals/generation/EqualTemperament.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { splitText } from "@/components/modals/tempering-state";
import { clamp } from "xen-dev-utils";
import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core";
const props = defineProps<{
centsFractionDigits: number;
decimalFractionDigits: number;
}>();
const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]);
const octave = new Interval(
Expand All @@ -24,6 +29,10 @@ const degreesString = ref("1 2 3 4 5");
const jumpsElement = ref<HTMLTextAreaElement | null>(null);
const degreesElement = ref<HTMLTextAreaElement | null>(null);
const singleStepOnly = computed(
() => divisions.value !== Math.round(divisions.value)
);
const safeScaleSize = computed(() =>
Math.round(clamp(1, 1024, divisions.value))
);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}
</script>

Expand Down

0 comments on commit a4069b0

Please sign in to comment.