forked from nikita/muzika-gromche
Add specialized color transition event to improve debug output
This commit is contained in:
parent
6a0be0d780
commit
667368d719
|
@ -580,6 +580,11 @@ namespace MuzikaGromche
|
|||
{
|
||||
return All.Where(easing => easing.Name == Name).DefaultIfEmpty(Linear).First();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
public record Palette(Color[] Colors)
|
||||
|
@ -1106,12 +1111,9 @@ namespace MuzikaGromche
|
|||
windUpZeroBeatEventTriggered = true;
|
||||
}
|
||||
|
||||
if (GetColorEvent(loopOffsetSpan, windUpOffsetTimestamp) is { } colorEvent)
|
||||
{
|
||||
var colorEvent = GetColorEvent(loopOffsetSpan, windUpOffsetTimestamp);
|
||||
if (colorEvent != null)
|
||||
{
|
||||
events.Add(colorEvent);
|
||||
}
|
||||
events.Add(colorEvent);
|
||||
}
|
||||
|
||||
if (loopOffsetSpan.GetLastIndex(track.FlickerLightsTimeSeries) != null)
|
||||
|
@ -1142,20 +1144,20 @@ namespace MuzikaGromche
|
|||
|
||||
private SetLightsColorEvent? GetColorEvent(BeatTimeSpan loopOffsetSpan, BeatTimestamp windUpOffsetTimestamp)
|
||||
{
|
||||
if (FadeOut(loopOffsetSpan) is Color c1)
|
||||
if (FadeOut(loopOffsetSpan) is { } colorEvent1)
|
||||
{
|
||||
return new SetLightsColorEvent(c1);
|
||||
return colorEvent1;
|
||||
}
|
||||
|
||||
if (ColorFromPaletteAtTimestamp(windUpOffsetTimestamp) is Color c2)
|
||||
if (ColorFromPaletteAtTimestamp(windUpOffsetTimestamp) is { } colorEvent2)
|
||||
{
|
||||
return new SetLightsColorEvent(c2);
|
||||
return colorEvent2;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Color? FadeOut(BeatTimeSpan loopOffsetSpan)
|
||||
private SetLightsColorTransitionEvent? FadeOut(BeatTimeSpan loopOffsetSpan)
|
||||
{
|
||||
var beat = loopOffsetSpan.BeatToInclusive;
|
||||
var fadeOutStart = track.FadeOutBeat;
|
||||
|
@ -1163,9 +1165,8 @@ namespace MuzikaGromche
|
|||
|
||||
if (track.FadeOutBeat < beat && beat <= fadeOutEnd)
|
||||
{
|
||||
var x = (beat - track.FadeOutBeat) / track.FadeOutDuration;
|
||||
var t = Mathf.Clamp(Easing.Linear.Eval(x), 0f, 1f);
|
||||
return Color.Lerp(Color.white, Color.black, t);
|
||||
var t = (beat - track.FadeOutBeat) / track.FadeOutDuration;
|
||||
return new SetLightsColorTransitionEvent(Color.white, Color.black, Easing.Linear, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1173,7 +1174,7 @@ namespace MuzikaGromche
|
|||
}
|
||||
}
|
||||
|
||||
public Color? ColorFromPaletteAtTimestamp(BeatTimestamp timestamp)
|
||||
public SetLightsColorEvent? ColorFromPaletteAtTimestamp(BeatTimestamp timestamp)
|
||||
{
|
||||
if (timestamp.Beat <= -track.ColorTransitionIn)
|
||||
{
|
||||
|
@ -1218,20 +1219,19 @@ namespace MuzikaGromche
|
|||
}
|
||||
}
|
||||
// default
|
||||
return ColorAtWholeBeat(timestamp);
|
||||
return new SetLightsColorEvent(ColorAtWholeBeat(timestamp));
|
||||
|
||||
Color ColorTransition(BeatTimestamp clipsBoundary)
|
||||
SetLightsColorEvent ColorTransition(BeatTimestamp clipsBoundary)
|
||||
{
|
||||
var transitionStart = clipsBoundary - track.ColorTransitionIn;
|
||||
var transitionEnd = clipsBoundary + track.ColorTransitionOut;
|
||||
var x = BeatTimeSpan.Between(transitionStart, timestamp).Duration() / transitionLength;
|
||||
var t = Mathf.Clamp(track.ColorTransitionEasing.Eval(x), 0f, 1f);
|
||||
var t = BeatTimeSpan.Between(transitionStart, timestamp).Duration() / transitionLength;
|
||||
if (track.ColorTransitionIn == 0.0f)
|
||||
{
|
||||
// Subtract an epsilon, so we don't use the same beat twice
|
||||
transitionStart -= 0.01f;
|
||||
}
|
||||
return Color.Lerp(ColorAtWholeBeat(transitionStart), ColorAtWholeBeat(transitionEnd), t);
|
||||
return new SetLightsColorTransitionEvent(ColorAtWholeBeat(transitionStart), ColorAtWholeBeat(transitionEnd), track.ColorTransitionEasing, t);
|
||||
}
|
||||
|
||||
Color ColorAtWholeBeat(BeatTimestamp timestamp)
|
||||
|
@ -1260,6 +1260,20 @@ namespace MuzikaGromche
|
|||
}
|
||||
}
|
||||
|
||||
public class SetLightsColorTransitionEvent(Color from, Color to, Easing easing, float t)
|
||||
: SetLightsColorEvent(Color.Lerp(from, to, Mathf.Clamp(easing.Eval(t), 0f, 1f)))
|
||||
{
|
||||
// Additional context for debugging
|
||||
public readonly Color From = from;
|
||||
public readonly Color To = to;
|
||||
public readonly Easing Easing = easing;
|
||||
public readonly float T = t;
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Color(#{ColorUtility.ToHtmlStringRGB(Color)} = #{ColorUtility.ToHtmlStringRGB(From)}..#{ColorUtility.ToHtmlStringRGB(To)} {Easing} {T:N4})";
|
||||
}
|
||||
}
|
||||
|
||||
public class FlickerLightsEvent : BaseEvent
|
||||
{
|
||||
public override string ToString() => "Flicker";
|
||||
|
|
Loading…
Reference in New Issue