Skip to content

🎈 perf: 从 PlayerController 中分离混音相关逻辑#935

Merged
kazukokawagawa merged 7 commits intodevfrom
dev-shit-fix
Feb 26, 2026
Merged

🎈 perf: 从 PlayerController 中分离混音相关逻辑#935
kazukokawagawa merged 7 commits intodevfrom
dev-shit-fix

Conversation

@imsyy
Copy link
Owner

@imsyy imsyy commented Feb 24, 2026

  • 力竭了

Copilot AI review requested due to automatic review settings February 24, 2026 14:42
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @imsyy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求的核心目标是重构音频播放器架构,通过将自动混音(Automix)功能从 PlayerController 中解耦,提升代码的模块化、可维护性和可扩展性。这一变更将复杂的混音逻辑集中到独立的 AutomixManager 中,使得 PlayerController 能够更专注于核心播放控制,并为未来的音频处理功能奠定更清晰的基础。

Highlights

  • 自动混音逻辑分离: 将所有自动混音(Automix)相关的核心逻辑、状态和辅助函数从 PlayerController 中完全分离,并封装到一个新的 AutomixManager 类中,显著提升了代码的模块化和可维护性。
  • 新目录和类型定义: 引入了新的 src/core/automix 目录来存放 AutomixManager 及其依赖,并将 IExtendedAudioContext 接口和所有 Automix 相关的类型定义(如 AudioAnalysis, TransitionProposal 等)迁移到新的 src/types/audio 目录下,以提高类型管理的清晰度。
  • PlayerController 简化: 重构了 PlayerController 中的播放和交叉淡入淡出逻辑,使其通过 AutomixManager 协调自动混音操作,从而显著简化了 PlayerController 的内部复杂性,使其更专注于核心播放控制。
  • AudioManager 优化: 优化了 AudioManagercrossfade 方法,移除了不再需要的 AutomationPoint 类型和相关的混音参数,使其更专注于音频引擎的底层操作。
  • IPC 调用统一与文档增强: 统一了 PlayerIpc 中的 IPC 调用,引入了一个 sendIpc 辅助函数,并为多个核心管理器类和 IPC 函数添加了详细的 JSDoc 注释,提升了代码的可读性和维护性。
Changelog
  • src/composables/useInit.ts
    • 将 ReplayGain 监听逻辑从 PlayerController 构造函数移动到此文件。
  • src/core/audio-player/BaseAudioPlayer.ts
    • 更新了 IExtendedAudioContext 的导入路径。
    • 移除了已注释的音频上下文挂起逻辑。
  • src/core/automix/AudioScheduler.ts
    • 重命名并移动了文件到 src/core/automix 目录。
    • 为类、类型和方法添加了详细的 JSDoc 注释。
  • src/core/automix/AutomixManager.ts
    • 新增了 AutomixManager 类,封装了所有自动混音的预分析、智能调度、BPM 对齐和无缝切歌逻辑。
    • 包含了下一首歌分析缓存、过渡协议、Automix 状态管理和调度器集成。
  • src/core/automix/SharedAudioContext.ts
    • 重命名并移动了文件到 src/core/automix 目录。
    • 为函数和变量添加了详细的 JSDoc 注释。
  • src/core/automix/scheduler.worker.ts
    • 重命名并移动了文件到 src/core/automix 目录。
    • 为函数添加了 JSDoc 注释。
  • src/core/player/AudioManager.ts
    • 更新了 getSharedAudioContext 的导入路径。
    • 移除了 IPlaybackEngine 接口中不再使用的 AutomationPoint 类型。
    • 简化了 crossfade 方法的选项,移除了 pitchShift, playbackRate, automationCurrent, automationNext 等参数。
    • 优化了 crossfade 逻辑,移除了自动化曲线处理,并简化了旧引擎销毁的 setTimeout 调用。
  • src/core/player/LyricManager.ts
    • LyricManager 类添加了 JSDoc 注释。
  • src/core/player/MediaSessionManager.ts
    • MediaSessionManager 类添加了 JSDoc 注释。
  • src/core/player/PlayModeManager.ts
    • PlayModeManager 类添加了 JSDoc 注释。
  • src/core/player/PlayerController.ts
    • 移除了所有 Automix 相关的私有属性和方法(如 nextAnalysis, automixState, computeAutomixPlan 等)。
    • 更新了 applyReplayGain 方法,使其使用 AutomixManagerautomixGain
    • prepareAudioSource, setupSongUI, loadAndPlay, afterPlaySetup, shouldSkipSong 方法的访问修饰符从 private 改为 public,以供 AutomixManager 调用。
    • playSong 方法中,将 Automix 参数计算委托给 AutomixManager
    • 在音频事件监听器中,将 Automix 调度和重置逻辑委托给 AutomixManager
    • 移除了 AudioAnalysis, TransitionProposal, AdvancedTransition 等类型定义,现在从 src/types/audio/automix.ts 导入。
    • 移除了 getCurrentAnalysis 方法。
  • src/core/player/PlayerIpc.ts
    • 新增了 sendIpc 辅助函数,统一了所有 IPC 消息发送。
    • 为所有导出的 IPC 函数添加了详细的 JSDoc 注释。
    • 新增了 sendMacStatusBarProgress 函数,用于 macOS 状态栏歌词进度更新。
  • src/core/player/SongManager.ts
    • SongManager 类添加了 JSDoc 注释。
  • src/types/audio/automix.ts
    • 新增了 AudioAnalysis, TransitionProposal, AdvancedTransition, AutomixState, AutomixPlan 等 Automix 相关的接口和类型定义。
  • src/types/audio/context.ts
    • 新增了 IExtendedAudioContext 接口定义。
  • src/utils/automix.ts
    • 新增了 isAdvancedTransition, isAudioAnalysis, isTransitionProposal 等类型守卫函数。
Activity
  • 目前没有人工活动记录。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

该拉取请求通过将混音逻辑从 PlayerController 移动到专门的 AutomixManager 中,显著优化了代码结构。这种关注点分离(Separation of Concerns)的做法提高了核心播放逻辑的可读性和可维护性。此外,代码中增加了详细的 JSDoc 注释,并对 IPC 通信进行了更好的封装。所有原始反馈建议均被保留,主要集中在 AudioManager 中的上下文丢失风险、异常处理缺失,以及 AutomixManager 中状态重置不彻底和封装性问题。

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 将原本耦合在 PlayerController 内的 Automix(自动混音/智能过渡)逻辑拆分为独立的 AutomixManager,并补齐相关类型与 IPC 封装,从而让播放器核心职责更聚焦、Automix 更易维护与扩展。

Changes:

  • 新增 AutomixManager,承接 Automix 的分析预取、调度与过渡执行逻辑
  • 抽离并集中 Automix 类型定义与运行时类型守卫(type guards)
  • 重构播放器与 IPC:PlayerController 调用 AutomixManager,PlayerIpc 增加安全 send 封装,并补充 macOS statusbar 进度发送方法

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/utils/automix.ts 新增 Automix 相关类型守卫(isAudioAnalysis / isTransitionProposal / isAdvancedTransition)
src/types/audio/context.ts 提取 IExtendedAudioContext 类型,供 SharedAudioContext/BaseAudioPlayer 复用
src/types/audio/automix.ts 新增/集中 Automix 的类型定义(analysis、proposal、plan、state 等)
src/core/player/SongManager.ts 补充类注释(无行为变更)
src/core/player/PlayerIpc.ts 抽象 sendIpc,统一 Electron 环境下的 IPC 发送,并增加 macOS statusbar 进度发送函数
src/core/player/PlayerController.ts 移除大量内联 Automix 代码,改为调用 AutomixManager;暴露部分原私有字段/方法以供 Automix 调用
src/core/player/PlayModeManager.ts 注释格式清理
src/core/player/MediaSessionManager.ts 注释格式清理
src/core/player/LyricManager.ts 补充类注释(无行为变更)
src/core/player/AudioManager.ts Crossfade 逻辑整理,移除未实现的 pitch shift/automation 分支,并调整 bassSwap 调度
src/core/automix/scheduler.worker.ts 补充注释(无行为变更)
src/core/automix/SharedAudioContext.ts SharedAudioContext 改用新的类型定义并补充注释
src/core/automix/AutomixManager.ts 新增:Automix 的核心实现与单例入口 useAutomixManager()
src/core/automix/AudioScheduler.ts 类型引用更新与注释补充
src/core/audio-player/BaseAudioPlayer.ts 共享 AudioContext 引用改指向 core/automix/SharedAudioContext,并抽离 IExtendedAudioContext 类型
src/composables/useInit.ts 将 ReplayGain 设置监听迁移为 watch() 调用 player.applyReplayGain()

Comment on lines 233 to 242
@@ -593,7 +242,6 @@ class PlayerController {
});
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

在 macOS 分支这里是给“状态栏歌词”推送进度,但实际调用的是 sendTaskbarProgressData()(任务栏歌词 Tick 广播)。这里更符合预期的是调用新加的 playerIpc.sendMacStatusBarProgress(),否则 macOS 状态栏可能不会在切歌瞬间收到一次立即同步(只能等后续 timeupdate)。

Copilot uses AI. Check for mistakes.
@imsyy
Copy link
Owner Author

imsyy commented Feb 25, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这次的 PR 是一次非常棒的重构,成功地将自动混音(Automix)相关的复杂逻辑从 PlayerController 中分离出来,封装到了新的 AutomixManager 中。这极大地提升了代码的模块化、可读性和可维护性,使得 PlayerController 的职责更加清晰。同时,相关的类型定义和工具函数也被整理到了独立的模块中,代码结构更加清晰。在 Rust 部分,您进行了一些性能优化和代码风格的改进,值得称赞。

我发现了一个可以改进的地方,主要是在 Rust 代码中,具体请看我的评论。

Comment on lines +1 to +9
#![allow(
clippy::unreadable_literal,
clippy::cast_sign_loss,
clippy::cast_possible_wrap,
clippy::too_many_arguments,
clippy::similar_names,
clippy::inline_always,
clippy::needless_continue
)]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

在文件级别禁用大量的 Clippy lint 可能会掩盖潜在的问题,降低代码的可维护性。例如 cast_sign_losscast_possible_wrap 可能会隐藏数值转换中潜在的溢出或环绕问题。建议移除文件级别的 allow 属性,并逐个处理这些警告。如果某个警告确实是误报或者出于特定原因需要忽略,可以在具体的代码行上使用 #[allow(...)] 并附上注释说明原因。

@imsyy imsyy requested a review from kazukokawagawa February 26, 2026 06:41
@kazukokawagawa kazukokawagawa merged commit 80d420e into dev Feb 26, 2026
4 checks passed
@imsyy imsyy deleted the dev-shit-fix branch February 26, 2026 07:03
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.

3 participants