-
Notifications
You must be signed in to change notification settings - Fork 1.2k
✨ feat: 支持AB循环 #794
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
Merged
✨ feat: 支持AB循环 #794
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| <template> | ||
| <n-flex :size="20" class="ab-loop" align="center" vertical> | ||
| <!-- Enable Switch --> | ||
| <n-card class="open"> | ||
| <n-flex align="center" justify="space-between"> | ||
| <n-flex size="small" align="center"> | ||
| <SvgIcon name="Repeat" size="22" /> | ||
| <n-text>AB 循环模式</n-text> | ||
| </n-flex> | ||
| <n-switch | ||
| v-model:value="statusStore.abLoop.enable" | ||
| :disabled="!canEnable" | ||
| :round="false" | ||
| /> | ||
| </n-flex> | ||
| </n-card> | ||
|
|
||
| <!-- Point A --> | ||
| <n-card class="point-card"> | ||
| <n-flex align="center" justify="space-between"> | ||
| <n-flex vertical size="small"> | ||
| <n-text strong>起点 A</n-text> | ||
| <n-text depth="3">{{ formatTime(statusStore.abLoop.pointA) }}</n-text> | ||
| </n-flex> | ||
| <n-flex> | ||
| <n-button size="small" secondary type="primary" @click="setPoint('A')">设为当前</n-button> | ||
| <n-button | ||
| size="small" | ||
| secondary | ||
| type="error" | ||
| @click="clearPoint('A')" | ||
| v-if="statusStore.abLoop.pointA !== null" | ||
| > | ||
| 清除 | ||
| </n-button> | ||
| </n-flex> | ||
| </n-flex> | ||
| <!-- Fine Tune --> | ||
| <n-input-number | ||
| v-if="statusStore.abLoop.pointA !== null" | ||
| v-model:value="statusStore.abLoop.pointA" | ||
| :step="0.1" | ||
| size="small" | ||
| style="margin-top: 10px" | ||
| placeholder="微调时间 (秒)" | ||
| > | ||
| <template #suffix>秒</template> | ||
| </n-input-number> | ||
| </n-card> | ||
|
|
||
| <!-- Point B --> | ||
| <n-card class="point-card"> | ||
| <n-flex align="center" justify="space-between"> | ||
| <n-flex vertical size="small"> | ||
| <n-text strong>终点 B</n-text> | ||
| <n-text depth="3">{{ formatTime(statusStore.abLoop.pointB) }}</n-text> | ||
| </n-flex> | ||
| <n-flex> | ||
| <n-button size="small" secondary type="primary" @click="setPoint('B')">设为当前</n-button> | ||
| <n-button | ||
| size="small" | ||
| secondary | ||
| type="error" | ||
| @click="clearPoint('B')" | ||
| v-if="statusStore.abLoop.pointB !== null" | ||
| > | ||
| 清除 | ||
| </n-button> | ||
| </n-flex> | ||
| </n-flex> | ||
| <!-- Fine Tune --> | ||
| <n-input-number | ||
| v-if="statusStore.abLoop.pointB !== null" | ||
| v-model:value="statusStore.abLoop.pointB" | ||
| :step="0.1" | ||
| size="small" | ||
| style="margin-top: 10px" | ||
| placeholder="微调时间 (秒)" | ||
| > | ||
| <template #suffix>秒</template> | ||
| </n-input-number> | ||
| </n-card> | ||
|
|
||
| <n-text depth="3" style="font-size: 12px"> | ||
| 提示:若 B 点小于或等于 A 点,循环将不会生效。 | ||
| </n-text> | ||
| </n-flex> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { useStatusStore } from "@/stores"; | ||
| import { useAudioManager } from "@/core/player/AudioManager"; | ||
| import { convertSecondsToTime } from "@/utils/time"; | ||
|
|
||
| const statusStore = useStatusStore(); | ||
| const audioManager = useAudioManager(); | ||
|
|
||
| const canEnable = computed(() => { | ||
| return ( | ||
| statusStore.abLoop.pointA !== null && | ||
| statusStore.abLoop.pointB !== null && | ||
| statusStore.abLoop.pointB > statusStore.abLoop.pointA | ||
| ); | ||
| }); | ||
|
|
||
| const formatTime = (time: number | null) => { | ||
| if (time === null) return "未设置"; | ||
| return convertSecondsToTime(time); | ||
| }; | ||
|
|
||
| const setPoint = (point: "A" | "B") => { | ||
| const current = audioManager.currentTime; | ||
| if (point === "A") { | ||
| statusStore.abLoop.pointA = Number(current.toFixed(2)); | ||
| } else { | ||
| statusStore.abLoop.pointB = Number(current.toFixed(2)); | ||
| } | ||
| // Auto disable if invalid | ||
| const { pointA, pointB } = statusStore.abLoop; | ||
| if (pointA !== null && pointB !== null && pointA >= pointB) { | ||
| statusStore.abLoop.enable = false; | ||
| } | ||
| }; | ||
|
Comment on lines
+111
to
+123
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为了提高代码的可维护性,可以对 |
||
|
|
||
| const clearPoint = (point: "A" | "B") => { | ||
| if (point === "A") { | ||
| statusStore.abLoop.pointA = null; | ||
| } else { | ||
| statusStore.abLoop.pointB = null; | ||
| } | ||
| statusStore.abLoop.enable = false; | ||
| }; | ||
| </script> | ||
|
|
||
| <style scoped lang="scss"> | ||
| .ab-loop { | ||
| width: 100%; | ||
| .open, | ||
| .point-card { | ||
| width: 100%; | ||
| border-radius: 8px; | ||
| } | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里的提示文本可以更精确一些。根据代码逻辑,当 B 点等于 A 点时,循环同样不会生效。建议将提示修改为“小于或等于”,以避免用户困惑。