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: audioPlayer.tsを新規作成しaudio.tsの一部機能を移転 #1492

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
51090ba
`audioPlayer.ts`を新規作成し`audio.ts`の一部機能を移転
thiramisu Aug 8, 2023
f20b0b3
一部をcomputed化
thiramisu Aug 8, 2023
44e0e43
不要なPromiseを削除
thiramisu Aug 8, 2023
2e3c382
`NOW_PLAYING_CONTINUOUSLY`の名前を`IS_...`に変更
thiramisu Aug 14, 2023
f6ac612
`AUDIO_CURRENT_TIME`にエラーを吐かせる
thiramisu Aug 14, 2023
7235a62
`FETCH_AND_`を`PLAY_AUDIO_CONTINUOUSLY`の頭に付ける
thiramisu Aug 14, 2023
793f572
保存漏れ分
thiramisu Aug 14, 2023
8477d98
Update src/store/audioPlayer.ts
thiramisu Aug 16, 2023
4610921
変数名・関数名を変更
thiramisu Aug 16, 2023
7abe9c7
漏れを修正
thiramisu Aug 16, 2023
43e1ff9
`WITH_UI_LOCK`版をデフォルトにして統合
thiramisu Aug 16, 2023
72805bd
関数名修正・漏れ修正
thiramisu Aug 16, 2023
96d3d6a
offsetの微量加算を`audio.ts`側に戻す
thiramisu Aug 16, 2023
5fa4201
生成中かの制御を`GENERATE_AUDIO`に移す
thiramisu Aug 17, 2023
048f23b
` LOAD_AUDIO_PLAYER`の名前を`PREPARE_...`に変更し説明を書く
thiramisu Aug 17, 2023
da64047
`PREPARE_...`に合わせて各部を調整
thiramisu Aug 17, 2023
0ea6df9
Revert "生成中かの制御を`GENERATE_AUDIO`に移す"
thiramisu Aug 20, 2023
c86ba4e
`audioPlayer.ts`の`FETCH`を`PREPARE`に
thiramisu Aug 20, 2023
1fdcccd
連続再生をジェネレータからコールバックに変更
thiramisu Aug 20, 2023
bcb57bb
`commit("STOP_AUDIO")`周りの見直し
thiramisu Aug 20, 2023
fb99487
未使用の`UNLOAD_AUDIO_PLAYER`を削除
thiramisu Aug 20, 2023
7709d8b
`console.warn`からwindow.electron.logWarn`に変更
thiramisu Aug 20, 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
12 changes: 7 additions & 5 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ const changeMoraData = (
// audio play
const play = async () => {
try {
await store.dispatch("PLAY_AUDIO", {
await store.dispatch("FETCH_AND_PLAY_AUDIO", {
audioKey: props.activeAudioKey,
});
} catch (e) {
Expand All @@ -513,16 +513,16 @@ const stop = () => {
store.dispatch("STOP_AUDIO", { audioKey: props.activeAudioKey });
};

const nowPlaying = computed(
() => store.state.audioStates[props.activeAudioKey]?.nowPlaying
const nowPlaying = computed(() =>
store.state.nowPlayingAudioKeys.includes(props.activeAudioKey)
);
const nowGenerating = computed(
() => store.state.audioStates[props.activeAudioKey]?.nowGenerating
);

// continuously play
const nowPlayingContinuously = computed(
() => store.state.nowPlayingContinuously
() => store.getters.NOW_PLAYING_CONTINUOUSLY
thiramisu marked this conversation as resolved.
Show resolved Hide resolved
);

const audioDetail = ref<HTMLElement>();
Expand Down Expand Up @@ -584,7 +584,9 @@ watch(nowPlaying, async (newState) => {
// 現在再生されているaudio elementの再生時刻を0.01秒毎に取得(監視)し、
// それに合わせてフォーカスするアクセント句を変えていく
focusInterval = setInterval(() => {
const currentTime = store.getters.ACTIVE_AUDIO_ELEM_CURRENT_TIME;
const currentTime = store.getters.AUDIO_CURRENT_TIME(
props.activeAudioKey
);
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 1; i < accentPhraseOffsets.length; i++) {
if (
currentTime !== undefined &&
Expand Down
15 changes: 8 additions & 7 deletions src/components/DictionaryManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ import { computed, ref, watch } from "vue";
import { QInput } from "quasar";
import AudioAccent from "./AudioAccent.vue";
import { useStore } from "@/store";
import { generateAudioKey } from "@/store/audio";
import { AccentPhrase, UserDictWord } from "@/openapi";
import {
convertHiraToKana,
Expand All @@ -279,7 +280,9 @@ const dictionaryManageDialogOpenedComputed = computed({
});
const uiLocked = ref(false); // ダイアログ内でstore.getters.UI_LOCKEDは常にtrueなので独自に管理
const nowGenerating = ref(false);
const nowPlaying = ref(false);
const nowPlaying = computed(() =>
store.state.nowPlayingAudioKeys.includes(audioKey)
);

const loadingDictState = ref<null | "loading" | "synchronizing">("loading");
const userDict = ref<Record<string, UserDictWord>>({});
Expand Down Expand Up @@ -432,8 +435,7 @@ const changeAccent = async (_: number, accent: number) => {
}
};

const audioElem = new Audio();
audioElem.pause();
const audioKey = generateAudioKey();

const play = async () => {
if (!accentPhrase.value) return;
Expand Down Expand Up @@ -470,12 +472,11 @@ const play = async () => {
}
}
nowGenerating.value = false;
nowPlaying.value = true;
await store.dispatch("PLAY_AUDIO_BLOB", { audioElem, audioBlob: blob });
nowPlaying.value = false;
await store.dispatch("LOAD_AUDIO_PLAYER", { audioKey, blob });
await store.dispatch("PLAY_AUDIO", { audioKey });
};
const stop = () => {
audioElem.pause();
store.dispatch("STOP_AUDIO", { audioKey });
};

// accent phraseにあるaccentと実際に登録するアクセントには差が生まれる
Expand Down
6 changes: 3 additions & 3 deletions src/components/HeaderBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const canUndo = computed(() => store.getters.CAN_UNDO);
const canRedo = computed(() => store.getters.CAN_REDO);
const activeAudioKey = computed(() => store.getters.ACTIVE_AUDIO_KEY);
const nowPlayingContinuously = computed(
() => store.state.nowPlayingContinuously
() => store.getters.NOW_PLAYING_CONTINUOUSLY
);

const undoRedoHotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
Expand Down Expand Up @@ -104,7 +104,7 @@ const redo = () => {
};
const playContinuously = async () => {
try {
await store.dispatch("PLAY_CONTINUOUSLY_AUDIO");
await store.dispatch("PLAY_AUDIO_CONTINUOUSLY_WITH_UI_LOCK", {});
} catch (e) {
let msg: string | undefined;
// FIXME: GENERATE_AUDIO_FROM_AUDIO_ITEMのエラーを変えた場合変更する
Expand All @@ -120,7 +120,7 @@ const playContinuously = async () => {
}
};
const stopContinuously = () => {
store.dispatch("STOP_CONTINUOUSLY_AUDIO");
store.dispatch("STOP_PLAYLIST");
};
const generateAndSaveOneAudio = async () => {
if (activeAudioKey.value == undefined)
Expand Down
Loading