WIP: 无效音乐配置不会启动音乐回调
This commit is contained in:
@@ -28,25 +28,49 @@ namespace OCES.Audio
|
|||||||
|
|
||||||
internal void Restart(MusicContainer container, float inheritedBpm, double dspTime)
|
internal void Restart(MusicContainer container, float inheritedBpm, double dspTime)
|
||||||
{
|
{
|
||||||
//Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}");
|
|
||||||
|
|
||||||
StopAll();
|
StopAll();
|
||||||
this.m_blendError = this.m_stopped = false;
|
this.m_blendError = this.m_stopped = false;
|
||||||
this.m_containerId = container.Id;
|
this.m_containerId = container.Id;
|
||||||
this.m_startDspTime = dspTime;
|
this.m_startDspTime = dspTime;
|
||||||
|
|
||||||
|
// BPM:优先用自己的,为 0 则用传入的继承值
|
||||||
// BPM:优先用自己的,为 0 则用传入的继承值,最终回退 120
|
|
||||||
float bpm = container.Bpm > 0f ? container.Bpm : inheritedBpm;
|
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_secondsPerBeat = 60 / bpm;
|
||||||
|
|
||||||
this.m_beatsPerBar = MusicContainerConfig.GetBeatsPerBar(container.TimeSig); // 沿用现有的解析逻辑
|
// TimeSig:检查是否有效
|
||||||
this.m_barsPerGrid = container.Grid > 0 ? container.Grid : 4;
|
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_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)
|
internal void OnBlendError(MusicContainer container)
|
||||||
|
|||||||
Reference in New Issue
Block a user