Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scale line input #481

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/components/ScaleLineInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ import { ref, watch } from "vue";
const props = defineProps<{
modelValue: string;
defaultValue: Interval;
placeholder?: string;
defaultValue?: Interval;
}>();
const emit = defineEmits(["update:value", "update:modelValue"]);
const element = ref<HTMLInputElement | null>(null);
const defaultValue =
props.defaultValue === undefined
? parseLine(props.modelValue || "1/1", DEFAULT_NUMBER_OF_COMPONENTS)
: props.defaultValue;
const [value, error] = computedAndError(
() => parseLine(props.modelValue, DEFAULT_NUMBER_OF_COMPONENTS),
defaultValue
props.defaultValue
);
watch(value, (newValue) => emit("update:value", newValue), { immediate: true });
watch(error, (newError) => element.value!.setCustomValidity(newError));
watch(
element,
(newElement) => {
if (newElement) {
newElement.setCustomValidity(error.value);
}
},
{ immediate: true }
);
watch(
error,
(newError) => {
if (element.value) {
element.value.setCustomValidity(newError);
}
},
{ immediate: true }
);
</script>

<template>
Expand Down
14 changes: 5 additions & 9 deletions src/components/modals/generation/CombinationProductSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@
import { computed, ref, watch } from "vue";
import Modal from "@/components/ModalDialog.vue";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
import { DEFAULT_NUMBER_OF_COMPONENTS } from "@/constants";
import { OCTAVE } from "@/constants";
import { computedAndError, parseChordInput } from "@/utils";
import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core";
import { Scale } from "scale-workshop-core";
const props = defineProps<{
show: boolean;
}>();
const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]);
const octave = new Interval(
ExtendedMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
"ratio"
);
const factorsString = ref("");
const numElements = ref(2);
const addUnity = ref(false);
const equaveString = ref("2/1");
const equave = ref(octave);
const equave = ref(OCTAVE);
const factorsElement = ref<HTMLInputElement | null>(null);
const [factors, factorsError] = computedAndError(() => {
Expand Down Expand Up @@ -53,7 +48,7 @@ function generate() {
if (addUnity.value) {
name += " with 1/1";
}
if (!equave.value.equals(octave)) {
if (!equave.value.equals(OCTAVE)) {
name += ` over ${equave.value.toString()}`;
}
name += ")";
Expand Down Expand Up @@ -108,6 +103,7 @@ function generate() {
id="equave"
@update:value="equave = $event"
v-model="equaveString"
:defaultValue="OCTAVE"
/>
</div>
</div>
Expand Down
14 changes: 6 additions & 8 deletions src/components/modals/generation/CrossPolytope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
import { ref, watch } from "vue";
import Modal from "@/components/ModalDialog.vue";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
import { DEFAULT_NUMBER_OF_COMPONENTS } from "@/constants";
import { OCTAVE } from "@/constants";
import { computedAndError, parseChordInput } from "@/utils";
import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core";
import { Scale } from "scale-workshop-core";
const props = defineProps<{
show: boolean;
}>();
const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]);
const octave = new Interval(
ExtendedMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
"ratio"
);
const basisString = ref("");
const addUnity = ref(true);
const equaveString = ref("2/1");
const equave = ref(octave);
const equave = ref(OCTAVE);
const basisElement = ref<HTMLInputElement | null>(null);
const [basis, basisError] = computedAndError(() => {
if (!props.show) {
Expand All @@ -41,7 +38,7 @@ function generate() {
if (addUnity.value) {
name += " with 1/1";
}
if (!equave.value.equals(octave)) {
if (!equave.value.equals(OCTAVE)) {
name += ` over ${equave.value.toString()}`;
}
name += ")";
Expand Down Expand Up @@ -85,6 +82,7 @@ function generate() {
id="equave"
@update:value="equave = $event"
v-model="equaveString"
:defaultValue="OCTAVE"
/>
</div>
</div>
Expand Down
10 changes: 3 additions & 7 deletions src/components/modals/generation/EqualTemperament.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { DEFAULT_NUMBER_OF_COMPONENTS } from "@/constants";
import { DEFAULT_NUMBER_OF_COMPONENTS, OCTAVE } from "@/constants";
import { computed, ref, watch } from "vue";
import Modal from "@/components/ModalDialog.vue";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
Expand All @@ -14,14 +14,9 @@ const props = defineProps<{
const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]);
const octave = new Interval(
ExtendedMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
"ratio"
);
const divisions = ref(5);
const equaveString = ref("2/1");
const equave = ref(octave);
const equave = ref(OCTAVE);
const jumpsString = ref("1 1 1 1 1");
const degreesString = ref("1 2 3 4 5");
Expand Down Expand Up @@ -172,6 +167,7 @@ function generate() {
id="equave"
@update:value="equave = $event"
v-model="equaveString"
:defaultValue="OCTAVE"
/>
</div>
</div>
Expand Down
16 changes: 6 additions & 10 deletions src/components/modals/generation/MosScale.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Interval
<script setup lang="ts">
import { DEFAULT_NUMBER_OF_COMPONENTS } from "@/constants";
import { OCTAVE } from "@/constants";
import {
allForEdo,
anyForEdo,
Expand All @@ -19,7 +19,7 @@ import { computed, reactive, ref, watch } from "vue";
import Modal from "@/components/ModalDialog.vue";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
import { clamp, gcd } from "xen-dev-utils";
import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core";
import { Scale } from "scale-workshop-core";
const emit = defineEmits([
"update:scale",
Expand All @@ -28,18 +28,13 @@ const emit = defineEmits([
"cancel",
]);
const octave = new Interval(
ExtendedMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
"ratio"
);
// State required to generate MOS
const numberOfLargeSteps = ref(5);
const numberOfSmallSteps = ref(2);
const sizeOfLargeStep = ref(2);
const sizeOfSmallStep = ref(1);
const up = ref(5);
const equave = ref(octave);
const equave = ref(OCTAVE);
// State for key colors
const colorMethod = ref<"none" | "parent" | "daughter">("none");
Expand Down Expand Up @@ -121,7 +116,7 @@ const hostEd = computed(
safeNumSmall.value * safeSizeSmall.value
);
const ed = computed(() => {
if (equave.value.equals(octave)) {
if (equave.value.equals(OCTAVE)) {
return `${hostEd.value}EDO`;
}
return `${hostEd.value}ED${equaveString.value}`;
Expand Down Expand Up @@ -211,7 +206,7 @@ function generate() {
if (daughter.hardness === "equalized") {
const equaveSteps = steps[steps.length - 1];
name += `${equaveSteps}ED`;
if (equave.value.equals(octave)) {
if (equave.value.equals(OCTAVE)) {
name += "O";
} else {
name += equave.value.toString();
Expand Down Expand Up @@ -323,6 +318,7 @@ function generate() {
id="equave"
@update:value="equave = $event"
v-model="equaveString"
:defaultValue="OCTAVE"
/>
</div>
<div class="control radio-group">
Expand Down
11 changes: 8 additions & 3 deletions src/components/modals/generation/RankTwo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import {
DEFAULT_NUMBER_OF_COMPONENTS,
MAX_INTERACTIVE_SUBGROUP_SIZE,
FIFTH,
OCTAVE,
} from "@/constants";
import {
makeRank2FromVals,
Expand All @@ -21,7 +23,7 @@ import PeriodCircle from "@/components/PeriodCircle.vue";
import { makeState } from "@/components/modals/tempering-state";
import { computedAndError, gapKeyColors } from "@/utils";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
import { ExtendedMonzo, Interval, parseLine, Scale } from "scale-workshop-core";
import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core";
const props = defineProps<{
centsFractionDigits: number;
Expand All @@ -43,9 +45,9 @@ const method = ref<"generator" | "vals" | "commas" | "circle">("generator");
const error = ref("");
const state = makeState(method);
// method: "generator"
const generator = ref(parseLine("3/2", DEFAULT_NUMBER_OF_COMPONENTS));
const generator = ref(FIFTH);
const generatorString = ref("");
const period = ref(parseLine("2/1", DEFAULT_NUMBER_OF_COMPONENTS));
const period = ref(OCTAVE);
const periodString = ref("2/1");
// method: "vals"
const valsString = state.valsString;
Expand Down Expand Up @@ -457,6 +459,7 @@ function generate() {
placeholder="3/2"
v-model="generatorString"
@update:value="generator = $event"
:defaultValue="FIFTH"
/>
<button @click="flipGenerator">Flip to {{ opposite }}</button>
</div>
Expand All @@ -465,8 +468,10 @@ function generate() {
<label for="period">Period</label>
<ScaleLineInput
id="period"
placeholder="2/1"
v-model="periodString"
@update:value="period = $event"
:defaultValue="OCTAVE"
/>
</div>

Expand Down
12 changes: 4 additions & 8 deletions src/components/modals/generation/SpanLattice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { reactive, ref, watch } from "vue";
import Modal from "@/components/ModalDialog.vue";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
import { DEFAULT_NUMBER_OF_COMPONENTS } from "@/constants";
import { DEFAULT_NUMBER_OF_COMPONENTS, OCTAVE } from "@/constants";
import { computedAndError, parseChordInput } from "@/utils";
import { makeState } from "@/components/modals/tempering-state";
import Temperament from "temperaments";
Expand All @@ -20,11 +20,6 @@ const props = defineProps<{
const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]);
const octave = new Interval(
ExtendedMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
"ratio"
);
const method = ref<"generators" | "vals" | "commas">("generators");
const state = makeState(method);
// method: "vals"
Expand All @@ -35,7 +30,7 @@ const commasString = state.commasString;
const basisString = ref("");
const dimensions = reactive<number[]>([]);
const equaveString = ref("2/1");
const equave = ref(octave);
const equave = ref(OCTAVE);
// Generic
const subgroupString = state.subgroupString;
const subgroupError = state.subgroupError;
Expand Down Expand Up @@ -126,7 +121,7 @@ function generate() {
if (basis.value.length === 0) {
name = "Lattice (unison";
}
if (!equave.value.equals(octave)) {
if (!equave.value.equals(OCTAVE)) {
name += ` over ${equave.value.toString()}`;
}
name += ")";
Expand Down Expand Up @@ -215,6 +210,7 @@ function generate() {
id="equave"
@update:value="equave = $event"
v-model="equaveString"
:defaultValue="OCTAVE"
/>
</div>
</div>
Expand Down
14 changes: 6 additions & 8 deletions src/components/modals/generation/SummonOctaplex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
import { ref, watch } from "vue";
import Modal from "@/components/ModalDialog.vue";
import ScaleLineInput from "@/components/ScaleLineInput.vue";
import { DEFAULT_NUMBER_OF_COMPONENTS } from "@/constants";
import { OCTAVE } from "@/constants";
import { computedAndError, parseChordInput } from "@/utils";
import { ExtendedMonzo, Interval, Scale } from "scale-workshop-core";
import { Scale } from "scale-workshop-core";
const props = defineProps<{
show: boolean;
}>();
const emit = defineEmits(["update:scale", "update:scaleName", "cancel"]);
const octave = new Interval(
ExtendedMonzo.fromFraction(2, DEFAULT_NUMBER_OF_COMPONENTS),
"ratio"
);
const basisString = ref("3 5 7 11");
const addUnity = ref(false);
const equaveString = ref("2/1");
const equave = ref(octave);
const equave = ref(OCTAVE);
const basisElement = ref<HTMLInputElement | null>(null);
const [basis, basisError] = computedAndError(() => {
if (!props.show) {
Expand All @@ -41,7 +38,7 @@ function generate() {
if (addUnity.value) {
name += " with 1/1";
}
if (!equave.value.equals(octave)) {
if (!equave.value.equals(OCTAVE)) {
name += ` over ${equave.value.toString()}`;
}
name += ")";
Expand Down Expand Up @@ -83,6 +80,7 @@ function generate() {
id="equave"
@update:value="equave = $event"
v-model="equaveString"
:defaultValue="OCTAVE"
/>
</div>
</div>
Expand Down
Loading