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)