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

[F] Sudden changes in headphone volume #9

Merged
merged 3 commits into from
Jan 20, 2025
Merged

Conversation

Becods
Copy link
Contributor

@Becods Becods commented Jan 11, 2025

解决开启EntryToMusicSelection后音量突变问题

放在MusicSelectProcess防止调音量卡住ReleaseProcess影响体验

1P测试正常,2P情况下尚未测试,可能会存在bug

Summary by Sourcery

Bug 修复:

  • 修复了在跳过入口电影时导致耳机音量突然变化的问题。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fixed an issue that caused sudden changes in headphone volume when skipping the entry movie.

Copy link

sourcery-ai bot commented Jan 11, 2025

审阅者指南 by Sourcery

这个拉取请求解决了在进入音乐选择时突然改变耳机音量的问题。它在 MusicSelectProcess 中实现了在 90 帧内逐渐增加音量,以提供更平滑的过渡,并防止音量调整阻塞发布过程,从而改善用户体验。

耳机音量调整过程的序列图

sequenceDiagram
    participant U as User
    participant MS as MusicSelectProcess
    participant SM as SoundManager
    participant UD as UserDataManager

U->>MS: Enter music selection
MS->>UD: Get user data
UD-->>MS: Return user settings
Note over MS: Initialize volume fade-in
loop Every frame for 90 frames
    MS->>MS: Update volume value
    MS->>SM: Set headphone volume
end
Note over MS: Volume reaches target
Loading

音乐选择入口变更的类图

classDiagram
    class EntryToMusicSelection {
        -int _timer
        -CommonValue _volumeFadeIn
        -bool[] _volumeFadeInState
        +OnUpdate(InformationProcess)
        +MapResultMonitorPreInitialize(int)
        +MusicSelectProcessOnUpdate()
    }

    class CommonValue {
        +float start
        +float current
        +float end
        +float diff
        +UpdateValue()
    }

    EntryToMusicSelection --> CommonValue
    note for CommonValue "用于平滑音量过渡"
Loading

音量过渡状态图

stateDiagram-v2
    [*] --> InitialVolume
    InitialVolume --> FadingIn: Start fade-in
    FadingIn --> TargetVolume: After 90 frames

    state FadingIn {
        [*] --> Updating
        Updating --> Updating: Update volume every frame
    }

    TargetVolume --> [*]
Loading

文件级变更

变更 详情 文件
将耳机音量调整移至 MusicSelectProcess
  • InformationProcessOnUpdate 方法中移除耳机音量设置。
  • MusicSelectProcessOnUpdate 方法中添加新的音量调整逻辑。
  • 引入 90 帧音量淡入,以防止突然变化和发布过程中可能的阻塞问题。
  • 添加新字段 _timer_volumeFadeIn_volumeFadeInState 以管理音量淡入逻辑。
  • 音量淡入从低值(0.05f)开始,对于新游戏,对于继续的游戏则从当前值开始,以确保从先前音量级别平滑过渡。
AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs
导入 Monitor.ModeSelect 命名空间
  • 添加 using Monitor.ModeSelect; 以在不完全限定名称的情况下访问 MusicSelectProcess 类。
AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs

提示和命令

与 Sourcery 交互

  • 触发新审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub 问题: 通过回复评论要求 Sourcery 创建问题。
  • 生成拉取请求标题: 在拉取请求标题中的任何位置写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中的任何位置写 @sourcery-ai summary 以随时生成 PR 摘要。您还可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审阅功能,如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request addresses an issue with sudden headphone volume changes when entering music selection. It implements a gradual volume increase over 90 frames within the MusicSelectProcess to provide a smoother transition and prevent the volume adjustment from blocking the release process, thereby improving user experience.

Sequence diagram for headphone volume adjustment process

sequenceDiagram
    participant U as User
    participant MS as MusicSelectProcess
    participant SM as SoundManager
    participant UD as UserDataManager

U->>MS: Enter music selection
MS->>UD: Get user data
UD-->>MS: Return user settings
Note over MS: Initialize volume fade-in
loop Every frame for 90 frames
    MS->>MS: Update volume value
    MS->>SM: Set headphone volume
end
Note over MS: Volume reaches target
Loading

Class diagram for EntryToMusicSelection changes

classDiagram
    class EntryToMusicSelection {
        -int _timer
        -CommonValue _volumeFadeIn
        -bool[] _volumeFadeInState
        +OnUpdate(InformationProcess)
        +MapResultMonitorPreInitialize(int)
        +MusicSelectProcessOnUpdate()
    }

    class CommonValue {
        +float start
        +float current
        +float end
        +float diff
        +UpdateValue()
    }

    EntryToMusicSelection --> CommonValue
    note for CommonValue "Used for smooth volume transition"
Loading

State diagram for volume transition

stateDiagram-v2
    [*] --> InitialVolume
    InitialVolume --> FadingIn: Start fade-in
    FadingIn --> TargetVolume: After 90 frames

    state FadingIn {
        [*] --> Updating
        Updating --> Updating: Update volume every frame
    }

    TargetVolume --> [*]
Loading

File-Level Changes

Change Details Files
Moved headphone volume adjustment to MusicSelectProcess
  • Removed headphone volume setting from OnUpdate method in InformationProcess.
  • Added a new volume adjustment logic within the OnUpdate method of MusicSelectProcess.
  • Introduced a 90-frame fade-in for headphone volume to prevent sudden changes and potential blocking issues during release process.
  • Added new fields _timer, _volumeFadeIn, and _volumeFadeInState to manage the volume fade-in logic.
  • The volume fade-in starts at a low value (0.05f) for new games and at the current value for continued games to ensure a smooth transition from the previous volume level.
AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs
Import Monitor.ModeSelect namespace
  • Added using Monitor.ModeSelect; to access the MusicSelectProcess class without fully qualifying the name.
AquaMai.Mods/Tweaks/TimeSaving/EntryToMusicSelection.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@Becods - 我已经审查了你的更改 - 以下是一些反馈:

整体评论

  • 考虑将最小音量 (0.05f) 设置为可配置的常量,而不是硬编码的值,以提高可维护性和在不同硬件设置中的灵活性。
  • 请在合并之前彻底测试2P(双人)场景,因为PR描述中提到尚未测试。
以下是我在审查期间查看的内容
  • 🟡 一般性问题:发现2个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享 ✨
帮助我变得更有用!请对每条评论点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey @Becods - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the minimum volume (0.05f) a configurable constant rather than a hardcoded value for better maintainability and flexibility across different hardware setups.
  • Please test the 2P (two player) scenario thoroughly before merging, as indicated in the PR description that it hasn't been tested yet.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -14,6 +15,12 @@ namespace AquaMai.Mods.Tweaks.TimeSaving;
zh: "登录完成后直接进入选歌界面")]
public class EntryToMusicSelection
{
private static int _timer;

private static CommonValue _volumeFadeIn = new();
Copy link

Choose a reason for hiding this comment

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

建议 (bug_risk): 考虑使 _volumeFadeIn 特定于玩家,以避免竞争条件

当前的实现为两个玩家使用单个 CommonValue 实例,这可能导致两个玩家同时调整音量时出现意外行为。考虑使用数组:private static CommonValue[] _volumeFadeIn = new CommonValue[2];

建议的实现:

    private static readonly CommonValue[] _volumeFadeIn = { new(), new() };

这个更改还需要:

  1. 更新任何访问 _volumeFadeIn 的代码,使用适当的数组索引(例如,_volumeFadeIn[playerIndex] 而不是 _volumeFadeIn)
  2. 确保正确传递玩家索引到使用 _volumeFadeIn 的任何方法
Original comment in English

suggestion (bug_risk): Consider making _volumeFadeIn player-specific to avoid race conditions

The current implementation uses a single CommonValue instance for both players, which could lead to unexpected behavior when both players are adjusting volume simultaneously. Consider using an array: private static CommonValue[] _volumeFadeIn = new CommonValue[2];

Suggested implementation:

    private static readonly CommonValue[] _volumeFadeIn = { new(), new() };

This change will also require:

  1. Updating any code that accesses _volumeFadeIn to use the appropriate array index (e.g., _volumeFadeIn[playerIndex] instead of _volumeFadeIn)
  2. Ensuring the player index is properly passed to any methods that use _volumeFadeIn

@@ -14,6 +15,12 @@ namespace AquaMai.Mods.Tweaks.TimeSaving;
zh: "登录完成后直接进入选歌界面")]
public class EntryToMusicSelection
{
private static int _timer;
Copy link

Choose a reason for hiding this comment

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

建议 (bug_risk): 计时器应该特定于玩家,以防止玩家之间的干扰

共享计时器可能导致一个玩家的淡入被另一个玩家的淡入中断。考虑使用数组:private static int[] _timer = new int[2];

建议的实现:

    private static int[] _timer = new int[2];

这个更改还需要:

  1. 更新使用 _timer 的任何代码,指定要使用的是哪个玩家的计时器,例如 _timer[playerIndex]
  2. 确保正确初始化两个数组元素
  3. 更新任何计时器增加/减少操作,以处理特定玩家的计时器

由于我无法看到使用 _timer 的文件的其余部分,你需要在这些位置进行相应的更改。

Original comment in English

suggestion (bug_risk): Timer should be player-specific to prevent interference between players

A shared timer could cause one player's fade to be cut short if another player starts their fade. Consider using an array: private static int[] _timer = new int[2];

Suggested implementation:

    private static int[] _timer = new int[2];

This change will also require:

  1. Updating any code that uses _timer to specify which player's timer to use, e.g., _timer[playerIndex]
  2. Ensuring proper initialization of both array elements
  3. Updating any timer increment/decrement operations to work with the specific player's timer

Since I can't see the rest of the file where _timer is used, you'll need to make these corresponding changes in those locations.

@clansty
Copy link
Contributor

clansty commented Jan 15, 2025

是不是没有在登出的时候重置 _volumeFadeInState

@Becods
Copy link
Contributor Author

Becods commented Jan 15, 2025

是不是没有在登出的时候重置 _volumeFadeInState

Done

@@ -95,4 +95,14 @@ public static void MusicSelectProcessOnUpdate()
}
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(ContinueProcess), "OnStart")]
Copy link
Contributor

Choose a reason for hiding this comment

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

万一没开续关不就没有 ContinueProcess
我觉得应该 hook 别的地方吧
不行的话到时候我改一下

Copy link
Contributor

@clansty clansty left a comment

Choose a reason for hiding this comment

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

先这样,到时候我再想想有没有更好的实现

@clansty clansty merged commit d00f70d into MewoLab:main Jan 20, 2025
1 check passed
@clansty
Copy link
Contributor

clansty commented Jan 20, 2025

先这样,到时候我再想想有没有更好的实现

我们是不是也可以在原先那个设置音量的地方 start coroutine

@clansty
Copy link
Contributor

clansty commented Jan 20, 2025

0487dd4

改成了用协程实现

image

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