-
Notifications
You must be signed in to change notification settings - Fork 312
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
Conversation
audioPlayer.ts
を新規作成しaudio.ts
の一部機能を移転audioPlayer.ts
を新規作成しaudio.ts
の一部機能を移転
@y-chan さんに当たっていますがお忙しそうなので僕がレビューしたいと思います! |
Co-authored-by: Hiroshiba <[email protected]>
`PLAYLIST`をAUDIOS`に `STOP_AUDIO`の引数名を変更
568d933
to
5fa4201
Compare
Co-authored-by: Hiroshiba <[email protected]>
今更ですが、レビューありがとうございます! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
申し訳ありません、あと少しかなと思って自分で微調整してマージしようかなと思って色々細かくコメントしていたのですが、ちょっと改修しておいた方が良さそうな点を発見しました。
(nowPlayingAudioKeys
がnowPlayingContinuouslyAudioKey
含まれなくなった点です。)
ちょっと提案なのですが、AudioPlayerに移動するだけのプルリクエストにしていただくことは可能でしょうか・・・?
というのもレビューする際に移動、移動だけであれば簡単なのですが、一緒に引数の追加や機能の分解や実装の変更があると同じ動作をしているのかをチェックするのが結構大変だったりしてしまうためです。
(ということをドキュメントに書いておくべきでした、大変申し訳ないです。。)
ここの考え方に関して何か参考資料がないかと思ってちょっと探してみました。
https://google-engineering-practices.translation.shuuji3.xyz/review/developer/small-cls.html#refactoring
多分このプルリクエストは↓3つが行われていて、可能であればそれぞれ分けてのプルリクエストだと非常に嬉しいなと・・・・・・!
- audioPlayerの移転
- 名称変更・一部getter化のリファクタリング
- 連続再生ロジックの変更
本来であればリファクタリングはサクサク行えるものだと思うのですが、エディタはテストがほとんど進んでおらず、かつ連続再生回りはe2eテストも行いづらいため、どうしても丁寧にレビューを行う必要があるという感じです・・・。
最初に気づくべきでした、本当に申し訳ないです 🙇
beforePlayFn, | ||
}: { | ||
audioKeys: AudioKey[]; | ||
beforePlayFn: (audioKey: AudioKey) => Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
単語省略はできる限り避けた方がよかったりします。
参考:https://qiita.com/alt_yamamoto/items/25eda376e6b947208996#%E5%8D%98%E8%AA%9E%E3%82%92%E7%9C%81%E7%95%A5%E3%81%99%E3%82%8B
(個人的には略し方が人それぞれで振動するので、だったら略さない方がいいかなという思いです)
); | ||
} | ||
}, | ||
action(_, { nowPlayingAudioKey }: { nowPlayingAudioKey: AudioKey }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(これは全く問題ないかもなのですが)
現在再生中以外のものでストップさせたいものがないので、nowPlaying
は冗長かもとちょっと思いました。
・・・という説明は結構言い訳みたいな感じになっています。
というのも、多分audioKey
でも問題なくて、PLAY_AUDIO
はそうなっているから揃えるためにaudioKey
にした方が良さそうだけど、「良さそう」以上の理由を探してこうなりました・・・。
dispatch("SHOW_ALERT_DIALOG", { | ||
title: "再生エラー", | ||
message: | ||
"再生デバイスが見つかりませんでした。設定 / オプション から再生デバイスを設定しなおしてみてください。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
エラーが出た時の案内は、確かに解決策が具体的な方が良いのですが、設定の場所って変わりうるんですよね・・・。
そうなった時むしろこれを書いていた方が混乱するのですが、良い解決策は思いつきませんでした・・・。
とりあえずオプションの場所はあまり変わらなさそうなので、一旦大丈夫そう。(どうすればいいんですかね。。。)
const bufStartPoint = state.audioPlayStartPoint; | ||
const currentAudioKey = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufとcurrentで、やってることが同じだけど表記が揺れてそうです。
正直currentは何かおかしいんですが、まあちょっとそっちに寄せるのが良さそう?
(ChatGPTに聞いたところ、backupやoriginalの提案がありました https://chat.openai.com/share/701a5fb7-dc5d-46df-b1b0-fed9442fd62b )
} | ||
PREPARE_AND_PLAY_AUDIO_CONTINUOUSLY: { | ||
action: createUILockAction( | ||
async ({ commit, dispatch, state }, { audioKey }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多分audioKey
指定は使われない気がします。
複数選択範囲を連続再生するなどの場合はaudioKeysが渡されるので。
別のとこでも書いたかもなのですが、後々使うかもしれない機能は結局使わないことが大半(この場合だと消していいのかもパッとわからない)ので実装しない方が多分良いかなと!
PLAY_AUDIOS: { | ||
mutation(state, { audioKey }: { audioKey: AudioKey }) { | ||
state.nowPlayingContinuouslyAudioKey = audioKey; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あ、こちら解決してないかもです!
https://github.com/VOICEVOX/voicevox/pull/1492/files#r1293824232
正直なところ、やっていることがPLAY_AUDIOS
と関係なく、nowPlayingContinuouslyAudioKey
の設定をやっているので、以前(SET_NOW_PLAYING_CONTINUOUSLY
)と同様に別の関数にしてあげるのが良いのかなと思いました。
nowPlayingAudioKeys: AudioKey[]; | ||
nowPlayingContinuouslyAudioKey?: AudioKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今気づいたのですが、通常の再生と連続再生で保存されるAudioKeyの場所が異なることになってそうです。
つまり、今までは連続再生している時にもnowPlayingAudioKeys
に該当する制御変数が変化していたのですが、この設計だと別々になっているので、連続再生中はnowPlayingAudioKeys
が空っぽという予測しづらい状況になっていそうです。
nowPlayingContinuouslyAudioKey
をやめ、以前と同様にnowPlayingAudioKeys
と連続再生中かどうかの制御変数に戻すのはどうでしょう。
あるいは両方とも_
をつけてプライベートっぽい変数名にし、必要な情報はゲッター関数にしてしまうとかでしょうか。
(多分将来の連続再生などの設計も見越した上での変更だったと思うのですが、その実装がないのでこの変更で行けるかわからないこともあり、とりあえず戻す方向に倒したいかもです。申し訳ない。。。)
STOP_AUDIOS: { | ||
mutation(state) { | ||
state.nowPlayingContinuouslyAudioKey = undefined; | ||
}, | ||
action({ state, commit, dispatch }) { | ||
const nowPlayingAudioKey = state.nowPlayingContinuouslyAudioKey; | ||
if (nowPlayingAudioKey !== undefined) { | ||
dispatch("STOP_AUDIO", { nowPlayingAudioKey }); | ||
} | ||
commit("STOP_AUDIOS"); | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
関数の名称とやっている内容が乖離していそうです。
多分PLAY_AUDIOS
との対象だからこの名称だと思うのですが、複数のオーディオの停止などと混同されそうです。
対象的にさせるのであれば、元の名称の「連続再生を開始する」「連続再生を停止する」の方が分かりやすいかもです。
PR周りに関してのガイドはあまり読めていなかった感じがあるので、ちょっとこの機会に色々記事を読んでみました。前は右から左に抜けてたんですが、ちゃんと読めるようになってました! |
ありがとうございます。文章化していただけると助かります |
@thiramisu 了解です!!
目標と対応する手段列挙とかがいいのかな?とか思いました! |
PRを分けられればその方が良さそうというのはなんとなく分かりました! #1492 (comment) const audioElements: Record<AudioKey, HTMLAudioElement> = {}; を const audioElement = new Audio(); としてしまうことで何か所か単純化できる気がしました。再生中の音声が高々一つになるので、そこら辺の実装を省けそうかなと。結構レビューしていただいた範囲も変更が必要そうなので、そこはアレなんですが…。 |
@thiramisu
こちらに関しても賛成です。 |
ちょっと再構成するのに新しいブランチから始めた方がやりやすそうなので、申し訳ないんですが一旦このPRはcloseさせていただこうかと思います。 |
承知しました!! |
内容
HTMLAudioElement
に関連する処理をaudioPlayer.ts
に移動します。ユーザー視点での変更はありません。
関連 Issue
ref #1475
上記の一環です。