From 218dd136728190660a18ded8fc502ee0fce9317b Mon Sep 17 00:00:00 2001 From: stardream <1011819146@qq.com> Date: Sun, 15 Mar 2026 17:49:32 +0800 Subject: [PATCH 1/2] Add OnCompleted event to PlaySongInfo class --- src/MusicPlayer/Music/PlaySongInfo.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/MusicPlayer/Music/PlaySongInfo.cs b/src/MusicPlayer/Music/PlaySongInfo.cs index 87cb9e072..5a35a2047 100644 --- a/src/MusicPlayer/Music/PlaySongInfo.cs +++ b/src/MusicPlayer/Music/PlaySongInfo.cs @@ -12,6 +12,7 @@ internal class PlaySongInfo private int delta; private DateTime lastUpdate; private int noteIndex; + public event Action? OnCompleted; public PlaySongInfo(List> notes, int tempo, VirtualPerformer performer) { this.Notes = notes; @@ -27,8 +28,7 @@ public void Update(int index) if (this.noteIndex == this.Notes.Count) { this.PlayCompleted = true; - var songPlayer = MusicPlayer.SongPlayers[index]; - songPlayer?.EndSong(); + this.OnCompleted?.Invoke(index); return; } this.delta += (int) (DateTime.Now - this.lastUpdate).TotalMilliseconds; @@ -39,7 +39,6 @@ public void Update(int index) { if (noteValue >= -1f && noteValue <= 1f) { - //PlayNote(index, noteValue); this.Performer.PlayNote(index, noteValue); } } @@ -62,4 +61,4 @@ public static void PlayNote(int index, float note) { NetMessage.SendData((int) PacketTypes.PlayHarp, index, -1, null, index, note, 0f, 0f, 0); } -} \ No newline at end of file +} From 271b892212de4dbf212be19aebaa30ace1e9c82e Mon Sep 17 00:00:00 2001 From: stardream <1011819146@qq.com> Date: Sun, 15 Mar 2026 18:29:18 +0800 Subject: [PATCH 2/2] Add SongName property and improve play completion logic --- src/MusicPlayer/Music/PlaySongInfo.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/MusicPlayer/Music/PlaySongInfo.cs b/src/MusicPlayer/Music/PlaySongInfo.cs index 5a35a2047..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; + private bool completedTriggered; + public event Action? OnCompleted; - public PlaySongInfo(List> notes, int tempo, VirtualPerformer performer) + + 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; - this.OnCompleted?.Invoke(index); + 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) { @@ -46,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); } }