forked from nikita/muzika-gromche
Mark AudioClip as nullable
This commit is contained in:
parent
afb3e34e71
commit
f83f2a72ba
|
|
@ -63,8 +63,8 @@ namespace MuzikaGromche
|
||||||
["Beats"] = audioTrack.Beats,
|
["Beats"] = audioTrack.Beats,
|
||||||
["LoopOffset"] = audioTrack.LoopOffset,
|
["LoopOffset"] = audioTrack.LoopOffset,
|
||||||
["Ext"] = audioTrack.Ext,
|
["Ext"] = audioTrack.Ext,
|
||||||
["FileDurationIntro"] = audioTrack.LoadedIntro.length,
|
["FileDurationIntro"] = audioTrack.LoadedIntro?.length ?? 0f,
|
||||||
["FileDurationLoop"] = audioTrack.LoadedLoop.length,
|
["FileDurationLoop"] = audioTrack.LoadedLoop?.length ?? 0f,
|
||||||
["FileNameIntro"] = audioTrack.FileNameIntro,
|
["FileNameIntro"] = audioTrack.FileNameIntro,
|
||||||
["FileNameLoop"] = audioTrack.FileNameLoop,
|
["FileNameLoop"] = audioTrack.FileNameLoop,
|
||||||
["BeatsOffset"] = audioTrack.BeatsOffset,
|
["BeatsOffset"] = audioTrack.BeatsOffset,
|
||||||
|
|
|
||||||
|
|
@ -1259,21 +1259,47 @@ namespace MuzikaGromche
|
||||||
public float WindUpTimer { get; }
|
public float WindUpTimer { get; }
|
||||||
|
|
||||||
// Estimated number of beats per minute. Not used for light show, but might come in handy.
|
// Estimated number of beats per minute. Not used for light show, but might come in handy.
|
||||||
public float Bpm => 60f / (LoadedLoop.length / Beats);
|
public float Bpm
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (LoadedLoop == null || LoadedLoop.length <= 0f)
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 60f / (LoadedLoop.length / Beats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// How many beats the loop segment has. The default strategy is to switch color of lights on each beat.
|
// How many beats the loop segment has. The default strategy is to switch color of lights on each beat.
|
||||||
public int Beats { get; }
|
public int Beats { get; }
|
||||||
|
|
||||||
// Number of beats between WindUpTimer and where looped segment starts (not the loop audio).
|
// Number of beats between WindUpTimer and where looped segment starts (not the loop audio).
|
||||||
public int LoopOffset { get; }
|
public int LoopOffset { get; }
|
||||||
public float LoopOffsetInSeconds => (float)LoopOffset / (float)Beats * LoadedLoop.length;
|
public float LoopOffsetInSeconds
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (LoadedLoop == null || LoadedLoop.length <= 0f)
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (float)LoopOffset / (float)Beats * LoadedLoop.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MPEG is basically mp3, and it can produce gaps at the start.
|
// MPEG is basically mp3, and it can produce gaps at the start.
|
||||||
// WAV is OK, but takes a lot of space. Try OGGVORBIS instead.
|
// WAV is OK, but takes a lot of space. Try OGGVORBIS instead.
|
||||||
public AudioType AudioType { get; }
|
public AudioType AudioType { get; }
|
||||||
|
|
||||||
public AudioClip LoadedIntro { get; internal set; }
|
public AudioClip? LoadedIntro { get; internal set; }
|
||||||
public AudioClip LoadedLoop { get; internal set; }
|
public AudioClip? LoadedLoop { get; internal set; }
|
||||||
|
|
||||||
public string FileNameIntro { get; }
|
public string FileNameIntro { get; }
|
||||||
public string FileNameLoop { get; }
|
public string FileNameLoop { get; }
|
||||||
|
|
@ -1290,7 +1316,20 @@ namespace MuzikaGromche
|
||||||
public float BeatsOffset { get; }
|
public float BeatsOffset { get; }
|
||||||
|
|
||||||
// Offset of beats, in seconds. Bigger offset => colors will change later.
|
// Offset of beats, in seconds. Bigger offset => colors will change later.
|
||||||
public float BeatsOffsetInSeconds => BeatsOffset / Beats * LoadedLoop.length;
|
public float BeatsOffsetInSeconds
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (LoadedLoop == null || LoadedLoop.length <= 0f)
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BeatsOffset / (float)Beats * LoadedLoop.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public float FadeOutBeat { get; }
|
public float FadeOutBeat { get; }
|
||||||
public float FadeOutDuration { get; }
|
public float FadeOutDuration { get; }
|
||||||
|
|
@ -1329,8 +1368,8 @@ namespace MuzikaGromche
|
||||||
int IAudioTrack.Beats => Track.Beats;
|
int IAudioTrack.Beats => Track.Beats;
|
||||||
int IAudioTrack.LoopOffset => Track.LoopOffset;
|
int IAudioTrack.LoopOffset => Track.LoopOffset;
|
||||||
AudioType IAudioTrack.AudioType => Track.AudioType;
|
AudioType IAudioTrack.AudioType => Track.AudioType;
|
||||||
AudioClip IAudioTrack.LoadedIntro { get => Track.LoadedIntro; set => Track.LoadedIntro = value; }
|
AudioClip? IAudioTrack.LoadedIntro { get => Track.LoadedIntro; set => Track.LoadedIntro = value; }
|
||||||
AudioClip IAudioTrack.LoadedLoop { get => Track.LoadedLoop; set => Track.LoadedLoop = value; }
|
AudioClip? IAudioTrack.LoadedLoop { get => Track.LoadedLoop; set => Track.LoadedLoop = value; }
|
||||||
string IAudioTrack.FileNameIntro => Track.FileNameIntro;
|
string IAudioTrack.FileNameIntro => Track.FileNameIntro;
|
||||||
string IAudioTrack.FileNameLoop => Track.FileNameLoop;
|
string IAudioTrack.FileNameLoop => Track.FileNameLoop;
|
||||||
float IAudioTrack.BeatsOffset => Track.BeatsOffset;
|
float IAudioTrack.BeatsOffset => Track.BeatsOffset;
|
||||||
|
|
@ -1364,8 +1403,8 @@ namespace MuzikaGromche
|
||||||
|
|
||||||
public int LoopOffset { get; init; } = 0;
|
public int LoopOffset { get; init; } = 0;
|
||||||
public AudioType AudioType { get; init; } = AudioType.MPEG;
|
public AudioType AudioType { get; init; } = AudioType.MPEG;
|
||||||
public AudioClip LoadedIntro { get; set; } = null!;
|
public AudioClip? LoadedIntro { get; set; } = null;
|
||||||
public AudioClip LoadedLoop { get; set; } = null!;
|
public AudioClip? LoadedLoop { get; set; } = null;
|
||||||
|
|
||||||
private string? FileNameIntroOverride = null;
|
private string? FileNameIntroOverride = null;
|
||||||
public string FileNameIntro
|
public string FileNameIntro
|
||||||
|
|
@ -1442,7 +1481,7 @@ namespace MuzikaGromche
|
||||||
|
|
||||||
void ISelectableTrack.Debug()
|
void ISelectableTrack.Debug()
|
||||||
{
|
{
|
||||||
Plugin.Log.LogDebug($"Track \"{Name}\", Intro={LoadedIntro.length:N4}, Loop={LoadedLoop.length:N4}");
|
Plugin.Log.LogDebug($"Track \"{Name}\", Intro={LoadedIntro?.length:N4}, Loop={LoadedLoop?.length:N4}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1472,7 +1511,7 @@ namespace MuzikaGromche
|
||||||
Plugin.Log.LogDebug($"Track Group \"{Name}\", Count={Tracks.Length}");
|
Plugin.Log.LogDebug($"Track Group \"{Name}\", Count={Tracks.Length}");
|
||||||
foreach (var (track, index) in Tracks.Select((x, i) => (x, i)))
|
foreach (var (track, index) in Tracks.Select((x, i) => (x, i)))
|
||||||
{
|
{
|
||||||
Plugin.Log.LogDebug($" Track {index} \"{track.Name}\", Intro={track.LoadedIntro.length:N4}, Loop={track.LoadedLoop.length:N4}");
|
Plugin.Log.LogDebug($" Track {index} \"{track.Name}\", Intro={track.LoadedIntro?.length:N4}, Loop={track.LoadedLoop?.length:N4}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1839,7 +1878,7 @@ namespace MuzikaGromche
|
||||||
|
|
||||||
float timeSinceStartOfLoop = time - offset;
|
float timeSinceStartOfLoop = time - offset;
|
||||||
|
|
||||||
var adjustedTimeNormalized = timeSinceStartOfLoop / LoopLength;
|
var adjustedTimeNormalized = (LoopLength <= 0f) ? 0f : timeSinceStartOfLoop / LoopLength;
|
||||||
|
|
||||||
var beat = adjustedTimeNormalized * Beats;
|
var beat = adjustedTimeNormalized * Beats;
|
||||||
|
|
||||||
|
|
@ -1887,9 +1926,10 @@ namespace MuzikaGromche
|
||||||
LyricsRandomPerLoop = LyricsRandom.Next();
|
LyricsRandomPerLoop = LyricsRandom.Next();
|
||||||
}
|
}
|
||||||
this.track = track;
|
this.track = track;
|
||||||
AudioState = new(track.LoadedIntro.length);
|
AudioState = new(track.LoadedIntro?.length ?? 0f);
|
||||||
WindUpLoopingState = new(track.WindUpTimer, track.LoadedLoop.length, track.Beats);
|
var loadedLoopLength = track.LoadedLoop?.length ?? 0f;
|
||||||
LoopLoopingState = new(track.WindUpTimer + track.LoopOffsetInSeconds, track.LoadedLoop.length, track.Beats);
|
WindUpLoopingState = new(track.WindUpTimer, loadedLoopLength, track.Beats);
|
||||||
|
LoopLoopingState = new(track.WindUpTimer + track.LoopOffsetInSeconds, loadedLoopLength, track.Beats);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BaseEvent> Update(AudioSource intro, AudioSource loop)
|
public List<BaseEvent> Update(AudioSource intro, AudioSource loop)
|
||||||
|
|
@ -3074,7 +3114,7 @@ namespace MuzikaGromche
|
||||||
var introAudioSource = behaviour.IntroAudioSource;
|
var introAudioSource = behaviour.IntroAudioSource;
|
||||||
var loopAudioSource = behaviour.LoopAudioSource;
|
var loopAudioSource = behaviour.LoopAudioSource;
|
||||||
|
|
||||||
if (behaviour.CurrentTrack == null)
|
if (behaviour.CurrentTrack == null || behaviour.CurrentTrack.LoadedIntro == null || behaviour.CurrentTrack.LoadedLoop == null)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Plugin.Log.LogError("CurrentTrack is not set!");
|
Plugin.Log.LogError("CurrentTrack is not set!");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue