Skip to content

Commit

Permalink
リアクティブにしつつ意図しない反復実行を抑える
Browse files Browse the repository at this point in the history
  • Loading branch information
thiramisu committed Oct 27, 2023
1 parent 3a9da7e commit ab6d626
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/components/AccentPhrase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:style="{ 'grid-column': `${moraIndex * 2 + 1} / span 1` }"
>
<audio-parameter
:ref="addAudioParameterRefs"
ref="pitchAudioParameters"
:mora-index="moraIndex"
:value="mora.pitch"
:ui-locked="uiLocked"
Expand All @@ -55,7 +55,7 @@
<!-- consonant length -->
<audio-parameter
v-if="mora.consonant && mora.consonantLength != undefined"
:ref="addAudioParameterRefs"
ref="consonantAudioParameters"
:mora-index="moraIndex"
:value="mora.consonantLength"
:ui-locked="uiLocked"
Expand All @@ -71,7 +71,7 @@
/>
<!-- vowel length -->
<audio-parameter
:ref="addAudioParameterRefs"
ref="vowelAudioParameters"
:mora-index="moraIndex"
:value="mora.vowelLength"
:ui-locked="uiLocked"
Expand Down Expand Up @@ -220,7 +220,7 @@
</template>

<script setup lang="ts">
import { VNodeRef, computed, onBeforeUpdate, ref } from "vue";
import { computed, ref } from "vue";
import AudioAccent from "./AudioAccent.vue";
import AudioParameter from "./AudioParameter.vue";
import ContextMenu from "./ContextMenu.vue";
Expand Down Expand Up @@ -347,29 +347,34 @@ const isEditableMora = (vowel: string, moraIndex: number) => {
return false;
};
const audioParameterRefs: InstanceType<typeof AudioParameter>[] = [];
const addAudioParameterRefs: VNodeRef = (audioParameterRef) => {
if (audioParameterRef && !(audioParameterRef instanceof Element)) {
const typedaudioParameterRef = audioParameterRef as InstanceType<
typeof AudioParameter
>;
audioParameterRefs.push(typedaudioParameterRef);
}
const pitchAudioParameters = ref<InstanceType<typeof AudioParameter>[]>();
const consonantAudioParameters = ref<InstanceType<typeof AudioParameter>[]>();
const vowelAudioParameters = ref<InstanceType<typeof AudioParameter>[]>();
const isAnyParameterOperating = (
audioParameters: InstanceType<typeof AudioParameter>[] | undefined
) => {
return (
audioParameters?.some?.((audioParameter) => audioParameter.isOperating) ??
false
);
};
onBeforeUpdate(() => {
audioParameterRefs.length = 0;
});
// pan中は当たり判定が消えるため
const isOperatingParameterSlider = computed(() =>
audioParameterRefs.some?.((audioParameter) => audioParameter.isOperating)
);
const isOperatingParameterSlider = computed(() => {
return (
isAnyParameterOperating(pitchAudioParameters.value) ||
isAnyParameterOperating(consonantAudioParameters.value) ||
isAnyParameterOperating(vowelAudioParameters.value)
);
});
const shouldForciblyDisplayValueLabel = computed(
() =>
props.altKeyFlag &&
(hoveredTarget.value != undefined || isOperatingParameterSlider.value)
);
const shouldForciblyDisplayValueLabel = computed(() => {
return (
(hoveredTarget.value != undefined || isOperatingParameterSlider.value) &&
props.altKeyFlag
);
});
const getHoveredText = (mora: Mora, moraIndex: number) => {
if (props.selectedDetail != "length") return mora.text;
Expand Down

0 comments on commit ab6d626

Please sign in to comment.