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: gridInfoではなくnumMeasuresをinjectするようにする #2605

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sigprogramming
Copy link
Contributor

内容

SequencerGridnumMeasures(小節数)のほかにgridWidthgridHeightを受け取るようになっていますが、gridWidthnumMeasuresに依存しているので、ストーリーブックでどちらか一方のみ変更するとSequencerGridが壊れます。

なので、numMeasuresのみ渡して、gridWidthSequencerGrid内で算出するようにします。
gridHeightもinjectするほど(共通化が必要なほど)複雑ではないので、これもSequencerGrid内で算出するようにします。
SequencerGridSpacerの方も、SequencerGridと同様に変更します)

また、numMeasuresはシーケンサーでのみ使用されているので、domainのgetNumMeasuresとstoreのSEQUENCER_NUM_MEASURESは削除して、ScoreSequencer内で算出するようにします。
(書き出し時に使用するようになるかもしれませんが、そのときにstore.getterにするのが良いかなと思います)

その他

@sigprogramming sigprogramming requested a review from a team as a code owner March 8, 2025 08:30
@sigprogramming sigprogramming requested review from Hiroshiba and removed request for a team March 8, 2025 08:30
@voicevox-preview-pages
Copy link

voicevox-preview-pages bot commented Mar 8, 2025

🚀 プレビュー用ページを作成しました 🚀

更新時点でのコミットハッシュ:52700c3

Copy link
Member

@Hiroshiba Hiroshiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

単一の情報源から各コンポーネントが必要な情報をどこで計算するべきか、かなり悩みますね 😇 😇 😇
@romot-co さんともどこかで議論した記憶。。そして同じように答えは出なかった。。


各計算結果をprovideすると、各引数に整合性が生じてStorybookでテストしづらい。(今のmainブランチ)
各コンポーネントで計算すると、複数箇所で同じ処理を書かないといけない。(このブルリク)

解決策としてはたぶんこうかな~~~と

  • どちらにせよ単一の情報源からそのコンポーネントが必要な情報を計算する関数を切り出す
  • 計算結果をprovideするなら
    • 全計算をルートコンポーネントで行ってprovide
    • Storybook内で必要最低限の関数を実行
    • 👍 同じ計算を2度行わない
    • 🤔 実際のコードとStorybookのコードがずれうる
  • コンポーネント内で計算するなら
    • 単一の情報源をprovideし、コンポーネントには必要な情報のみ引数渡しする
    • 各コンポーネント内で必要最低限の関数を実行
    • 👍 Storybookが簡単
    • 🤔 同じ計算を行う

このどっちかなのかな~~~と思いました!!!
どっちが良いかはぶっちゃけ結論出せてないです。。。
一旦考え聞けると!!(よかった @sevenc-nanashi さんも)

Comment on lines +25 to +41
const endMeasureNumber = computed(() => numMeasures.value + 1);

const endTicks = computed(() => {
return measureNumberToTick(
endMeasureNumber.value,
timeSignatures.value,
tpqn.value,
);
});

const gridWidth = computed(() => {
return tickToBaseX(endTicks.value, tpqn.value) * zoomX.value;
});

const gridHeight = computed(() => {
return getKeyBaseHeight() * getNumKeys() * zoomY.value;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コードがコピペになっているのが気になりました!
https://github.com/sigprogramming/voicevox/blob/52700c33c963878c99e863f49d8d5bc1eeb0a1e4/src/components/Sing/SequencerGridSpacer.vue#L25-L41
https://github.com/sigprogramming/voicevox/blob/52700c33c963878c99e863f49d8d5bc1eeb0a1e4/src/components/Sing/SequencerGrid/Presentation.vue#L136-L153
この辺り多分整合性取れなくなりうるので、provideで与えるかどうかともかく、DRY原則に従って共通化していくのが良いかなと思いました!

ちなみにgridWidthを以前共通化を提案したときのコメントはこんな感じでした。
#2472 (comment)

@@ -3,15 +3,42 @@
</template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ただのコメントです)

このコンポーネント今思ったらなくせそうですね!!
widhtとheight指定してdiv作ってるだけなので、ScoreSequencer.vue側でこんな感じで書けば良さそう?

<div style={
  width: `${gridWidth}px`,
  height: `${gridHeight}px`,
  "pointer-events": "none",
}/>

あるいはコンポーネント化するにしても、GridSpacerではなくただのSpacerとできそうだな~と。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants