From 1fd2d2ff183b71a494d5a92d3cd59bffaf92faa4 Mon Sep 17 00:00:00 2001 From: Oliver Wong Date: Mon, 27 Apr 2026 19:57:48 +0800 Subject: [PATCH] =?UTF-8?q?WIP:=20=E6=97=A0=E6=95=88=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=8D=E4=BC=9A=E5=90=AF=E5=8A=A8=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Audio/HandWritten/LongAudio/BeatClock.cs | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/OCES/Audio/HandWritten/LongAudio/BeatClock.cs b/Assets/Scripts/OCES/Audio/HandWritten/LongAudio/BeatClock.cs index 2113491..92eece1 100644 --- a/Assets/Scripts/OCES/Audio/HandWritten/LongAudio/BeatClock.cs +++ b/Assets/Scripts/OCES/Audio/HandWritten/LongAudio/BeatClock.cs @@ -28,25 +28,49 @@ namespace OCES.Audio internal void Restart(MusicContainer container, float inheritedBpm, double dspTime) { - //Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}"); - StopAll(); this.m_blendError = this.m_stopped = false; this.m_containerId = container.Id; this.m_startDspTime = dspTime; - - // BPM:优先用自己的,为 0 则用传入的继承值,最终回退 120 + // BPM:优先用自己的,为 0 则用传入的继承值 float bpm = container.Bpm > 0f ? container.Bpm : inheritedBpm; - if (bpm <= 30f) bpm = 120f; // 没见过速度小于30bpm的音乐,小于30要么是数填错了,要么是有奇怪的情况。要是真有这么慢的音乐再处理吧。 + if (bpm <= 30f) + { + // BPM 无效,不启动任何回调 + return; + } this.m_secondsPerBeat = 60 / bpm; - this.m_beatsPerBar = MusicContainerConfig.GetBeatsPerBar(container.TimeSig); // 沿用现有的解析逻辑 - this.m_barsPerGrid = container.Grid > 0 ? container.Grid : 4; + // TimeSig:检查是否有效 + bool hasTimeSig = !string.IsNullOrEmpty(container.TimeSig); + if (hasTimeSig) + { + this.m_beatsPerBar = MusicContainerConfig.GetBeatsPerBar(container.TimeSig); + } + // Grid:检查是否有效 + bool hasGrid = container.Grid > 0; + if (hasGrid) + { + this.m_barsPerGrid = container.Grid; + } + + // 分层启动协程 + // Beat:只要 BPM 有效就启动 this.m_beatCoroutine = this.m_host.StartCoroutine(BeatCoroutine()); - this.m_barCoroutine = this.m_host.StartCoroutine(BarCoroutine()); - this.m_gridCoroutine = this.m_host.StartCoroutine(GridCoroutine()); + + // Bar:TimeSig 有效时启动 + if (hasTimeSig) + { + this.m_barCoroutine = this.m_host.StartCoroutine(BarCoroutine()); + } + + // Grid:TimeSig 和 Grid 都有效时启动 + if (hasTimeSig && hasGrid) + { + this.m_gridCoroutine = this.m_host.StartCoroutine(GridCoroutine()); + } } internal void OnBlendError(MusicContainer container)