diff --git a/src/MusicPlayer/Music/PlaySongInfo.cs b/src/MusicPlayer/Music/PlaySongInfo.cs index 87cb9e072..d901373dd 100644 --- a/src/MusicPlayer/Music/PlaySongInfo.cs +++ b/src/MusicPlayer/Music/PlaySongInfo.cs @@ -6,32 +6,44 @@ internal class PlaySongInfo { public List> Notes; public int Tempo; + public string? SongName; public bool PlayCompleted { get; private set; } public VirtualPerformer Performer { get; private set; } private int delta; private DateTime lastUpdate; private int noteIndex; - public PlaySongInfo(List> notes, int tempo, VirtualPerformer performer) + private bool completedTriggered; + + public event Action? OnCompleted; + + public PlaySongInfo(List> notes, int tempo, VirtualPerformer performer, string? songName = null) { this.Notes = notes; this.Tempo = tempo; this.Performer = performer; + this.SongName = songName; } + public void Update(int index) { if (this.PlayCompleted) { return; } + if (this.noteIndex == this.Notes.Count) { - this.PlayCompleted = true; - var songPlayer = MusicPlayer.SongPlayers[index]; - songPlayer?.EndSong(); + if (!this.completedTriggered) + { + this.completedTriggered = true; + this.PlayCompleted = true; + this.OnCompleted?.Invoke(index); + } return; } - this.delta += (int) (DateTime.Now - this.lastUpdate).TotalMilliseconds; + + this.delta += (int)(DateTime.Now - this.lastUpdate).TotalMilliseconds; if (this.delta > this.Tempo) { @@ -39,7 +51,6 @@ public void Update(int index) { if (noteValue >= -1f && noteValue <= 1f) { - //PlayNote(index, noteValue); this.Performer.PlayNote(index, noteValue); } } @@ -47,19 +58,23 @@ public void Update(int index) } this.lastUpdate = DateTime.Now; } + public void Play() { this.PlayCompleted = false; this.noteIndex = 0; this.delta = 0; + this.completedTriggered = false; this.lastUpdate = DateTime.Now; } + public void Stop() { this.PlayCompleted = true; } + public static void PlayNote(int index, float note) { - NetMessage.SendData((int) PacketTypes.PlayHarp, index, -1, null, index, note, 0f, 0f, 0); + NetMessage.SendData((int)PacketTypes.PlayHarp, index, -1, null, index, note, 0f, 0f, 0); } -} \ No newline at end of file +}