From 379ccbd0c6f86b7f93c536efbe614d29e0d885f3 Mon Sep 17 00:00:00 2001 From: EscapeNumber001 Date: Sun, 16 Apr 2023 17:56:20 -0400 Subject: [PATCH] Drum fills are now parsed --- Assets/Script/Data/NoteInfo.cs | 5 ++ Assets/Script/PlayMode/DrumsTrack.cs | 1 + Assets/Script/PlayMode/Play.cs | 6 +-- .../Script/Serialization/Parser/MidiParser.cs | 52 ++++++++++++++++++- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/Assets/Script/Data/NoteInfo.cs b/Assets/Script/Data/NoteInfo.cs index 00ab78108..4865c18a0 100644 --- a/Assets/Script/Data/NoteInfo.cs +++ b/Assets/Script/Data/NoteInfo.cs @@ -9,6 +9,11 @@ public class NoteInfo : AbstractInfo { /// public bool hopo; + /// + /// Activates SP when hit on drums. Does not break combo if missed. + /// + public bool drumSPActivator; + /// /// Whether or not this HOPO is automatic.
/// Used for difficulty downsampling. diff --git a/Assets/Script/PlayMode/DrumsTrack.cs b/Assets/Script/PlayMode/DrumsTrack.cs index 9974b93e3..fb6a63587 100644 --- a/Assets/Script/PlayMode/DrumsTrack.cs +++ b/Assets/Script/PlayMode/DrumsTrack.cs @@ -120,6 +120,7 @@ protected override void UpdateTrack() { } else if (eventInfo.name == "beatLine_major") { genericPool.Add("beatLine_major", new(0f, 0.01f, compensation)); } else if (eventInfo.name == $"starpower_{player.chosenInstrument}") { + Debug.Log("Star Power Segment"); StarpowerSection = eventInfo; } diff --git a/Assets/Script/PlayMode/Play.cs b/Assets/Script/PlayMode/Play.cs index 656368411..097e7a869 100644 --- a/Assets/Script/PlayMode/Play.cs +++ b/Assets/Script/PlayMode/Play.cs @@ -160,10 +160,8 @@ private IEnumerator StartSong() { // Spawn tracks int i = 0; foreach (var player in PlayerManager.players) { - player.chosenDifficulty = player.setlistDifficulties[0]; - player.chosenInstrument = player.setlistInstruments[0]; - player.setlistDifficulties.RemoveAt(0); - player.setlistInstruments.RemoveAt(0); + player.chosenDifficulty = player.setlistDifficulties[setlistCurrentSongIndex]; + player.chosenInstrument = player.setlistInstruments[setlistCurrentSongIndex]; if (player.chosenInstrument == null) { // Skip players that are sitting out diff --git a/Assets/Script/Serialization/Parser/MidiParser.cs b/Assets/Script/Serialization/Parser/MidiParser.cs index 4beeae019..1bdc605d5 100644 --- a/Assets/Script/Serialization/Parser/MidiParser.cs +++ b/Assets/Script/Serialization/Parser/MidiParser.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using JetBrains.Annotations; using Melanchall.DryWetMidi.Core; using Melanchall.DryWetMidi.Interaction; using Melanchall.DryWetMidi.MusicTheory; @@ -138,6 +139,9 @@ public override void Parse(Chart chart) { chart.realDrums[i] = ParseDrums(trackChunk, true, i, drumType, null); chart.ghDrums[i] = ParseGHDrums(trackChunk, i, drumType, chart.realDrums[i]); + ParseStarpower(eventIR, trackChunk, "drums"); + ParseStarpower(eventIR, trackChunk, "realDrums"); + ParseDrumFills(eventIR, trackChunk, "realDrums"); } } else { for (int i = 0; i < 5; i++) { @@ -145,9 +149,9 @@ public override void Parse(Chart chart) { chart.drums[i] = ParseDrums(trackChunk, false, i, drumType, chart.ghDrums[i]); chart.realDrums[i] = ParseDrums(trackChunk, true, i, drumType, chart.ghDrums[i]); + ParseStarpower(eventIR, trackChunk, "ghDrums"); } } - break; case "BEAT": ParseBeats(eventIR, trackChunk); @@ -312,6 +316,52 @@ private void ParseStarpower(List eventIR, TrackChunk trackChunk, string } } + private void ParseDrumFills(List eventIR, TrackChunk trackChunk, string instrument) { + long totalDelta = 0; + + long? starPowerStart = null; + + // Convert track events into intermediate representation + foreach (var trackEvent in trackChunk.Events) { + totalDelta += trackEvent.DeltaTime; + + if (trackEvent is not NoteEvent noteEvent) { + continue; + } + + // Look for correct octave + if (noteEvent.GetNoteOctave() != 9) { + continue; + } + + // Skip if not a star power event + if (noteEvent.GetNoteName() != NoteName.B + && noteEvent.GetNoteName() != NoteName.C + && noteEvent.GetNoteName() != NoteName.D + && noteEvent.GetNoteName() != NoteName.E + ) { + continue; + } + + if (trackEvent is NoteOnEvent) { + // We need to know when it ends before adding it + starPowerStart = totalDelta; + } else if (trackEvent is NoteOffEvent) { + if (starPowerStart == null) { + continue; + } + + // Now that we know the start and end, add it to the list of events. + eventIR.Add(new EventIR { + startTick = starPowerStart.Value, + endTick = totalDelta, + name = $"starpower_{instrument}" + }); + starPowerStart = null; + } + } + } + private SongInfo.DrumType GetDrumType(TrackChunk trackChunk) { if (songInfo.drumType != SongInfo.DrumType.UNKNOWN) { return songInfo.drumType;