Skip to content

Commit

Permalink
Drum fills are now parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
EscapeNumber001 committed Apr 16, 2023
1 parent 807d4fa commit 379ccbd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Assets/Script/Data/NoteInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class NoteInfo : AbstractInfo {
/// </summary>
public bool hopo;

/// <summary>
/// Activates SP when hit on drums. Does not break combo if missed.
/// </summary>
public bool drumSPActivator;

/// <summary>
/// Whether or not this HOPO is automatic.<br/>
/// Used for difficulty downsampling.
Expand Down
1 change: 1 addition & 0 deletions Assets/Script/PlayMode/DrumsTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 51 additions & 1 deletion Assets/Script/Serialization/Parser/MidiParser.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -138,16 +139,19 @@ 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++) {
chart.ghDrums[i] = ParseGHDrums(trackChunk, i, drumType, null);

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);
Expand Down Expand Up @@ -312,6 +316,52 @@ private void ParseStarpower(List<EventIR> eventIR, TrackChunk trackChunk, string
}
}

private void ParseDrumFills(List<EventIR> 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;
Expand Down

0 comments on commit 379ccbd

Please sign in to comment.