diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 99d7eff..afd9aab 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -431,6 +431,9 @@ namespace MuzikaGromche set => _BeatsOffset = value; } + // Offset of beats, in seconds. Bigger offset => colors will change later. + public float Offset => BeatsOffset / Beats * LoadedLoop.length; + // Duration of color transition, measured in beats. public float _ColorTransitionIn = 0.25f; public float ColorTransitionIn @@ -469,27 +472,28 @@ namespace MuzikaGromche // NOTE 2: There is a weird state when Jester has popped and chases a player: // Start/farAudio isPlaying is true but stays exactly at zero time, so we need to ignore that. - var elapsed = start.isPlaying && start.time != 0f + float elapsed = 0f; + elapsed -= Config.AudioOffset.Value; + elapsed -= Offset; + + elapsed += start.isPlaying && start.time != 0f // [1] Start source is still playing ? start.time - WindUpTimer // [2] Start source has finished : loop.time + FixedLoopDelay; - elapsed -= Config.AudioOffset.Value; - var normalized = Mod.Positive(elapsed / LoadedLoop.length, 1f); var beat = normalized * (float)Beats; - var offset = Mod.Positive(beat - BeatsOffset, (float)Beats); #if DEBUG var color = ColorAtBeat(beat); - Debug.LogFormat("MuzikaGromche t={0,10:N4} d={1,7:N4} Start[{2}{3,8:N4} ==0f? {4}] Loop[{5}{6,8:N4}] norm={7,6:N4} beat={8,7:N4} {9,7:N4} color={10}", + Debug.LogFormat("MuzikaGromche t={0,10:N4} d={1,7:N4} Start[{2}{3,8:N4} ==0f? {4}] Loop[{5}{6,8:N4}] norm={7,6:N4} beat={8,7:N4} color={9}", Time.realtimeSinceStartup, Time.deltaTime, (start.isPlaying ? '+' : ' '), start.time, (start.time == 0f ? 'Y' : 'n'), (loop.isPlaying ? '+' : ' '), loop.time, - normalized, beat, offset, color); + normalized, beat, color); #endif - return offset; + return beat; } public Palette _Palette = Palette.DEFAULT;