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

refactor: AccentPhrase.vueを新規作成しAudioDetail.vueからアクセント句のコンポーネントを分離 Part.2 #1569

Merged
merged 57 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
cf192e7
refactor: `AudioDetail.vue`の記述を整理しコメントを追加
thiramisu Sep 16, 2023
0f0a16b
refactor: AccentPhrase.vueを作成
thiramisu Sep 16, 2023
49578dc
refactor(HTML): カット&ペースト
thiramisu Sep 16, 2023
a1b3b5b
refactor(HTML): 元の位置に空のタグを追加
thiramisu Sep 17, 2023
7042ef5
refactor(HTML): 不要になっていたコメントを削除
thiramisu Sep 17, 2023
c000018
style: lintのエラーを減らす
thiramisu Sep 16, 2023
3bcd82d
refactor: `selectedDetail`を定義
thiramisu Sep 16, 2023
9bda003
refactor: `uiLocked`を定義
thiramisu Sep 17, 2023
5d29671
refactor: `shiftKeyFlag`を定義
thiramisu Sep 17, 2023
a302c4c
refactor: 変数・関数をカット&ペースト
thiramisu Sep 17, 2023
ae7b8f2
refactor: コピペ部分の細部を合わせる
thiramisu Sep 17, 2023
0f7d655
refactor: `altKeyFlag`を定義
thiramisu Sep 17, 2023
2f1e01a
refactor: 変数・関数をカット&ペースト
thiramisu Sep 17, 2023
043daa6
refactor: コピペ部分の細部を合わせる
thiramisu Sep 17, 2023
a641416
refactor: 関数をカット&ペースト
thiramisu Sep 17, 2023
340060a
refactor: コピペ部分の細部を合わせる
thiramisu Sep 17, 2023
b1da352
refactor: `pronunciationByPhrase`を`pronunciation`として単体に
thiramisu Sep 17, 2023
9572651
refactor: `accentPhrase`と`index`を定義
thiramisu Sep 17, 2023
11b35aa
refactor(index): `accentPhraseIndex`を置き換え
thiramisu Sep 17, 2023
9c77525
refactor(index): 不要な記述を削除
thiramisu Sep 17, 2023
218af7f
style: 改行を調整
thiramisu Sep 17, 2023
dea84bf
refactor(isLast): 定義して置き換え
thiramisu Sep 17, 2023
b0693c1
refactor(isLast): 不要な記述を削除し整理
thiramisu Sep 17, 2023
3580138
refactor: `AudioParameter`関連の記述をシンプルに
thiramisu Sep 17, 2023
80aa652
refactor: importを調整
thiramisu Sep 17, 2023
d5ed3b2
refactor(scss): カット&ペースト
thiramisu Sep 17, 2023
93c0450
refactor(scss): 中身を整理
thiramisu Sep 17, 2023
6f9248f
refactor(scss): 必要な宣言を移動orコピペ
thiramisu Sep 17, 2023
6ebad2c
refactor(scss): 不要そうに見える記述を削除
thiramisu Sep 17, 2023
ea11898
refactor(audioKey): 定義
thiramisu Sep 17, 2023
0df05f0
refactor(audioKey): 名前を合わせる
thiramisu Sep 17, 2023
f6c5426
refactor(lastPitches): 定義
thiramisu Sep 17, 2023
90f87ad
refactor(lastPitches): 不要な記述を削除
thiramisu Sep 17, 2023
777a621
refactor: 単体アクセント句の読み変更のアルゴリズムを改善
thiramisu Sep 19, 2023
8279b73
refactor: `accentHoveredInfo`を`isAccentHovered`としてシンプルに
thiramisu Sep 17, 2023
c96c11a
refactor: `pitchHoveredInfo`を`hoveredPitchMoraIndex`としてシンプルに
thiramisu Sep 17, 2023
e74cee7
refactor: `lengthHoveredInfo`から`accentPhraseIndex`を削除
thiramisu Sep 17, 2023
0a7e858
refactor: 不要な記述を削除
thiramisu Sep 17, 2023
cc86f0b
style: 見た目を調整
thiramisu Sep 17, 2023
2127ffa
refactor: 引数の不要なオプション化をやめる
thiramisu Sep 17, 2023
d6ab5fe
refactor: `isAccentHovered`と`hoveredPitchMoraIndex`をまとめる
thiramisu Sep 17, 2023
e679649
refactor: `hoveredMoraIndex`と`lengthHoveredInfo.moraIndex`をまとめる
thiramisu Sep 17, 2023
ec77564
refactor: `lengthHoveredInfo`を`lengthHoveredType`としてシンプルに
thiramisu Sep 17, 2023
1143b43
refactor: 不要な記述を削除
thiramisu Sep 17, 2023
17eb37e
refactor: 不要な記述を削除
thiramisu Sep 17, 2023
e867c3d
Merge branch 'main' into separate-accent-phrase-vue
thiramisu Sep 19, 2023
aec94fe
refactor: `<context-menu>`を移動
thiramisu Sep 19, 2023
3d1cbd6
refactor: 不要なscss変数を削除
thiramisu Sep 19, 2023
d2f00b2
Merge branch 'main' into separate-accent-phrase-vue
thiramisu Sep 21, 2023
33ade97
refactor: `handleChangePronounce`の挙動を改善
thiramisu Sep 21, 2023
3739935
refactor: `handleChangePronounce`をさらに微調整
thiramisu Sep 21, 2023
eeac881
refactor(lengthHoveredPhonemeType): 変数名を調整
thiramisu Sep 21, 2023
872acd6
refactor: gオプションを追加
thiramisu Sep 21, 2023
9a8838b
Revert: 別PRで送る予定の分を元に戻す
thiramisu Sep 21, 2023
921ed0a
review: `lengthHoveredPhonemeType`の位置を移動
thiramisu Sep 22, 2023
b03a10a
refactor: `isHovered`では表せていなかった処理の複雑さを名前とコメントで補強
thiramisu Sep 22, 2023
5fff259
Update src/components/AccentPhrase.vue
Hiroshiba Sep 23, 2023
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
122 changes: 36 additions & 86 deletions src/components/AccentPhrase.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<context-menu :menudata="contextMenudata" />
<!-- スライダーここから -->
<!-- アクセント項目のスライダー -->
<template v-if="selectedDetail === 'accent'">
Expand All @@ -20,7 +21,6 @@
>
<audio-parameter
:mora-index="moraIndex"
:accent-phrase-index="index"
:value="mora.pitch"
:ui-locked="uiLocked"
:min="minPitch"
Expand All @@ -46,7 +46,6 @@
<audio-parameter
v-if="mora.consonant && mora.consonantLength != undefined"
:mora-index="moraIndex"
:accent-phrase-index="index"
:value="mora.consonantLength"
:ui-locked="uiLocked"
:min="minMoraLength"
Expand All @@ -61,7 +60,6 @@
<!-- vowel length -->
<audio-parameter
:mora-index="moraIndex"
:accent-phrase-index="index"
:value="mora.vowelLength"
:ui-locked="uiLocked"
:min="minMoraLength"
Expand All @@ -84,7 +82,6 @@
<!-- pause length -->
<audio-parameter
:mora-index="accentPhrase.moras.length"
:accent-phrase-index="index"
:value="accentPhrase.pauseMora.vowelLength"
:ui-locked="uiLocked"
:min="0"
Expand Down Expand Up @@ -165,9 +162,11 @@
</template>

<script setup lang="ts">
import { computed, reactive } from "vue";
import { computed, ref } from "vue";
import AudioAccent from "./AudioAccent.vue";
import AudioParameter from "./AudioParameter.vue";
import ContextMenu from "./ContextMenu.vue";
import { MenuItemButton } from "./MenuBar.vue";
import { useStore } from "@/store";
import { AudioKey, MoraDataType } from "@/type/preload";
import { Mora } from "@/openapi/models/Mora";
Expand All @@ -184,12 +183,26 @@ const props =
altKeyFlag: boolean;
}>();

type DetailTypes = "accent" | "pitch" | "length" | "play" | "stop" | "save";
type DetailTypes = "accent" | "pitch" | "length";

const store = useStore();

const uiLocked = computed(() => store.getters.UI_LOCKED);

const contextMenudata = ref<[MenuItemButton]>([
{
type: "button",
label: "削除",
onClick: () => {
store.dispatch("COMMAND_DELETE_ACCENT_PHRASE", {
audioKey: props.audioKey,
accentPhraseIndex: props.index,
});
},
disableWhenUiLocked: true,
},
]);

const pronunciation = computed(() => {
let textString = props.accentPhrase.moras.map((mora) => mora.text).join("");
if (props.accentPhrase.pauseMora) {
Expand All @@ -214,95 +227,41 @@ const handleChangePronounce = (newPronunciation: string) => {
});
};

type hoveredType = "vowel" | "consonant";

type hoveredInfoType = {
accentPhraseIndex: number | undefined;
moraIndex?: number | undefined;
type?: hoveredType;
};

const accentHoveredInfo = reactive<hoveredInfoType>({
accentPhraseIndex: undefined,
});

const pitchHoveredInfo = reactive<hoveredInfoType>({
accentPhraseIndex: undefined,
moraIndex: undefined,
});
const hoveredMoraIndex = ref<number | undefined>(undefined);

const lengthHoveredInfo = reactive<hoveredInfoType>({
accentPhraseIndex: undefined,
moraIndex: undefined,
type: "vowel",
});
const lengthHoveredPhonemeType = ref<"vowel" | "consonant">("vowel");
thiramisu marked this conversation as resolved.
Show resolved Hide resolved

const handleHoverText = (isOver: boolean, moraIndex: number) => {
if (props.selectedDetail == "accent") {
if (isOver) {
accentHoveredInfo.accentPhraseIndex = props.index;
} else {
accentHoveredInfo.accentPhraseIndex = undefined;
}
} else if (props.selectedDetail == "pitch") {
if (isOver) {
pitchHoveredInfo.accentPhraseIndex = props.index;
pitchHoveredInfo.moraIndex = moraIndex;
} else {
pitchHoveredInfo.accentPhraseIndex = undefined;
pitchHoveredInfo.moraIndex = undefined;
}
if (props.selectedDetail == "accent" || props.selectedDetail == "pitch") {
hoveredMoraIndex.value = isOver ? moraIndex : undefined;
}
};

const handleLengthHoverText = (
isOver: boolean,
phoneme: MoraDataType,
phraseIndex: number,
moraIndex?: number
moraIndex: number
) => {
if (phoneme !== "vowel" && phoneme !== "consonant")
throw new Error("phoneme != hoveredType");
lengthHoveredInfo.type = phoneme;
lengthHoveredPhonemeType.value = phoneme;
// the pause and pitch templates don't emit a mouseOver event
if (isOver) {
lengthHoveredInfo.accentPhraseIndex = phraseIndex;
lengthHoveredInfo.moraIndex = moraIndex;
} else {
lengthHoveredInfo.accentPhraseIndex = undefined;
lengthHoveredInfo.moraIndex = undefined;
}
hoveredMoraIndex.value = isOver ? moraIndex : undefined;
};

const unvoicableVowels = ["U", "I", "i", "u"];

const isHovered = (vowel: string, moraIndex: number) => {
let isHover = false;
if (!uiLocked.value) {
if (props.selectedDetail == "accent") {
if (props.index === accentHoveredInfo.accentPhraseIndex) {
isHover = true;
}
} else if (props.selectedDetail == "pitch") {
if (
props.index === pitchHoveredInfo.accentPhraseIndex &&
moraIndex === pitchHoveredInfo.moraIndex &&
unvoicableVowels.includes(vowel)
) {
isHover = true;
}
}
}
return isHover;
};
const isHovered = (vowel: string, moraIndex: number) =>
!uiLocked.value &&
((props.selectedDetail == "accent" && hoveredMoraIndex.value !== undefined) ||
(props.selectedDetail == "pitch" &&
moraIndex === hoveredMoraIndex.value &&
unvoicableVowels.includes(vowel)));
thiramisu marked this conversation as resolved.
Show resolved Hide resolved

const getHoveredText = (mora: Mora, moraIndex: number) => {
if (props.selectedDetail != "length") return mora.text;
if (
props.index === lengthHoveredInfo.accentPhraseIndex &&
moraIndex === lengthHoveredInfo.moraIndex
) {
if (lengthHoveredInfo.type == "vowel") {
if (moraIndex === hoveredMoraIndex.value) {
if (lengthHoveredPhonemeType.value == "vowel") {
return mora.vowel.toUpperCase();
} else {
return mora.consonant?.toUpperCase();
Expand Down Expand Up @@ -335,11 +294,11 @@ const minPitch = 3;
const maxMoraLength = 0.3;
const minMoraLength = 0;
const changeMoraData = (
accentPhraseIndex: number,
moraIndex: number,
data: number,
type: MoraDataType
) => {
const accentPhraseIndex = props.index;
if (!props.altKeyFlag) {
if (type == "pitch") {
lastPitches.value[moraIndex] = data;
Expand Down Expand Up @@ -376,7 +335,7 @@ const handleChangeVoicing = (mora: Mora, moraIndex: number) => {
data = lastPitches.value[moraIndex];
}
}
changeMoraData(props.index, moraIndex, data, "voicing");
changeMoraData(moraIndex, data, "voicing");
}
};
</script>
Expand Down Expand Up @@ -426,15 +385,6 @@ const handleChangeVoicing = (mora: Mora, moraIndex: number) => {
min-width: 20px;
max-width: 20px;
}
.accent-cell {
grid-row: 2 / span 1;
div {
min-width: 20px + 20px;
max-width: 20px + 20px;
display: inline-block;
cursor: pointer;
}
}
.pitch-cell {
grid-row: 1 / span 2;
min-width: 20px;
Expand Down
30 changes: 1 addition & 29 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
]"
@click="setPlayAndStartPoint(accentPhraseIndex)"
>
<context-menu :menudata="accentPhraseMenudata(accentPhraseIndex)" />
<accent-phrase
:audio-key="activeAudioKey"
:accent-phrase="accentPhrase"
Expand Down Expand Up @@ -101,8 +100,6 @@ import {
} from "vue";
import ToolTip from "./ToolTip.vue";
import AccentPhrase from "./AccentPhrase.vue";
import ContextMenu from "./ContextMenu.vue";
import { MenuItemButton } from "./MenuBar.vue";
import { useStore } from "@/store";
import {
AudioKey,
Expand Down Expand Up @@ -193,7 +190,7 @@ const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
setHotkeyFunctions(hotkeyMap, true);

// detail selector
type DetailTypes = "accent" | "pitch" | "length" | "play" | "stop" | "save";
type DetailTypes = "accent" | "pitch" | "length";
const selectedDetail = ref<DetailTypes>("accent");

// accent phrase
Expand Down Expand Up @@ -248,22 +245,6 @@ const setPlayAndStartPoint = (accentPhraseIndex: number) => {
}
};

// accentPhraseIndexごとにcontext-menuの内容を用意する
const accentPhraseMenudata = computed(() => (accentPhraseIndex: number): [
MenuItemButton
] => {
return [
{
type: "button",
label: "削除",
onClick: async () => {
deleteAccentPhrase(accentPhraseIndex);
},
disableWhenUiLocked: true,
},
];
});

watch(accentPhrases, async () => {
activePoint.value = startPoint.value;
// 連続再生時に、最初に選択されていた場所に戻るためにscrollToActivePointを呼ぶ必要があるが、
Expand All @@ -272,13 +253,6 @@ watch(accentPhrases, async () => {
scrollToActivePoint();
});

const deleteAccentPhrase = (phraseIndex: number) => {
store.dispatch("COMMAND_DELETE_ACCENT_PHRASE", {
audioKey: props.activeAudioKey,
accentPhraseIndex: phraseIndex,
});
};

// audio play
const play = async () => {
try {
Expand Down Expand Up @@ -423,8 +397,6 @@ onUnmounted(() => {
<style scoped lang="scss">
@use '@/styles/colors' as colors;

$pitch-label-height: 24px;

.tip-tweakable-slider-by-scroll {
position: absolute;
right: 4px;
Expand Down
13 changes: 2 additions & 11 deletions src/components/AudioParameter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { MoraDataType } from "@/type/preload";
const props = withDefaults(
defineProps<{
value: number;
accentPhraseIndex: number;
moraIndex: number;
uiLocked: boolean;
min?: number;
Expand All @@ -72,7 +71,6 @@ const emit =
defineEmits<{
(
e: "changeValue",
accentPhraseIndex: number,
moraIndex: number,
newValue: number,
type: MoraDataType
Expand All @@ -81,13 +79,12 @@ const emit =
e: "mouseOver",
isOver: boolean,
type: MoraDataType,
accentPhraseIndex: number,
moraIndex: number
): void;
}>();

const changeValue = (newValue: number, type: MoraDataType = props.type) =>
emit("changeValue", props.accentPhraseIndex, props.moraIndex, newValue, type);
emit("changeValue", props.moraIndex, newValue, type);

const previewSlider = previewSliderHelper({
modelValue: () => props.value,
Expand Down Expand Up @@ -120,13 +117,7 @@ const clipPathComputed = computed((): string => {
const handleMouseHover = (isOver: boolean) => {
valueLabel.visible = isOver;
if (props.type == "consonant" || props.type == "vowel") {
emit(
"mouseOver",
isOver,
props.type,
props.accentPhraseIndex,
props.moraIndex
);
emit("mouseOver", isOver, props.type, props.moraIndex);
}
};

Expand Down