Skip to content

Commit

Permalink
Merge branch 'moonscraper-parsing' of https://github.com/RileyTheFox/…
Browse files Browse the repository at this point in the history
…YARG into RileyTheFox-moonscraper-parsing
  • Loading branch information
EliteAsian123 committed Apr 30, 2023
2 parents a4166d5 + d34603a commit ba1ca58
Show file tree
Hide file tree
Showing 42 changed files with 1,048 additions and 209 deletions.
4 changes: 2 additions & 2 deletions Assets/Plugins/MoonscraperChartParser/Events/BPM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public float displayValue
}
}

public float? anchor = null;
public double? anchor = null;

/// <summary>
/// Basic constructor.
Expand All @@ -41,7 +41,7 @@ public BPM(BPM _bpm) : base(_bpm.tick)
anchor = _bpm.anchor;
}

public float assignedTime = 0;
public double assignedTime = 0;

public override SongObject Clone()
{
Expand Down
14 changes: 7 additions & 7 deletions Assets/Plugins/MoonscraperChartParser/Events/MoonNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum GHLiveGuitarFret
Open
}

public enum NoteType
public enum MoonNoteType
{
Natural,
Strum,
Expand Down Expand Up @@ -388,31 +388,31 @@ public int GetMaskWithRequiredFlags(Flags flags)
/// <summary>
/// Live calculation of what Note_Type this note would currently be.
/// </summary>
public NoteType type
public MoonNoteType type
{
get
{
if (this.gameMode == MoonChart.GameMode.Drums)
{
if (!this.IsOpenNote() && (flags & Flags.ProDrums_Cymbal) == Flags.ProDrums_Cymbal)
{
return NoteType.Cymbal;
return MoonNoteType.Cymbal;
}

return NoteType.Strum;
return MoonNoteType.Strum;
}
else
{
if (!this.IsOpenNote() && (flags & Flags.Tap) == Flags.Tap)
{
return NoteType.Tap;
return MoonNoteType.Tap;
}
else
{
if (isHopo)
return NoteType.Hopo;
return MoonNoteType.Hopo;
else
return NoteType.Strum;
return MoonNoteType.Strum;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Plugins/MoonscraperChartParser/Events/SongObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SongObject(uint _tick)
/// <summary>
/// Automatically converts the object's tick position into the time it will appear in the song.
/// </summary>
public float time
public double time
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class ChartReader
struct Anchor
{
public uint tick;
public float anchorTime;
public double anchorTime;
}

struct NoteFlag
Expand Down
90 changes: 45 additions & 45 deletions Assets/Plugins/MoonscraperChartParser/IO/Midi/MidReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ struct EventProcessParams
{
{ MidIOHelper.SYSEX_CODE_GUITAR_OPEN, ProcessSysExEventPairAsOpenNoteModifier },
{ MidIOHelper.SYSEX_CODE_GUITAR_TAP, (in EventProcessParams eventProcessParams) => {
ProcessSysExEventPairAsForcedType(eventProcessParams, MoonNote.NoteType.Tap);
ProcessSysExEventPairAsForcedType(eventProcessParams, MoonNote.MoonNoteType.Tap);
}},
};

static readonly Dictionary<byte, EventProcessFn> GhlGuitarSysExEventToProcessFnMap = new Dictionary<byte, EventProcessFn>()
{
{ MidIOHelper.SYSEX_CODE_GUITAR_OPEN, ProcessSysExEventPairAsOpenNoteModifier },
{ MidIOHelper.SYSEX_CODE_GUITAR_TAP, (in EventProcessParams eventProcessParams) => {
ProcessSysExEventPairAsForcedType(eventProcessParams, MoonNote.NoteType.Tap);
ProcessSysExEventPairAsForcedType(eventProcessParams, MoonNote.MoonNoteType.Tap);
}},
};

Expand Down Expand Up @@ -274,7 +274,7 @@ public static MoonSong ReadMidi(string path, ref CallbackState callBackState)
break;
}
}

// Display messages to user
ProcessPendingUserMessages(messageList, ref callBackState);

Expand All @@ -283,27 +283,27 @@ public static MoonSong ReadMidi(string path, ref CallbackState callBackState)

static void ProcessPendingUserMessages(IList<MessageProcessParams> messageList, ref CallbackState callBackState)
{
if (messageList == null)
{
Debug.Assert(false, $"No message list provided to {nameof(ProcessPendingUserMessages)}!");
return;
}

foreach (var processParams in messageList)
{
if (messageList == null)
{
Debug.Assert(false, $"No message list provided to {nameof(ProcessPendingUserMessages)}!");
return;
}

foreach (var processParams in messageList)
{
#if UNITY_EDITOR
// The editor freezes when its message box API is used during parsing,
// we use the params to determine whether or not to execute actions instead
if (!processParams.executeInEditor)
{
Debug.Log("Auto-skipping action for message: " + processParams.message);
continue;
}
else
{
Debug.Log("Auto-executing action for message: " + processParams.message);
processParams.processFn(processParams);
}
// The editor freezes when its message box API is used during parsing,
// we use the params to determine whether or not to execute actions instead
if (!processParams.executeInEditor)
{
Debug.Log("Auto-skipping action for message: " + processParams.message);
continue;
}
else
{
Debug.Log("Auto-executing action for message: " + processParams.message);
processParams.processFn(processParams);
}
#else
// callBackState = CallbackState.WaitingForExternalInformation;
// NativeMessageBox.Result result = NativeMessageBox.Show(processParams.message, processParams.title, NativeMessageBox.Type.YesNo, null);
Expand All @@ -313,9 +313,9 @@ static void ProcessPendingUserMessages(IList<MessageProcessParams> messageList,
// processParams.processFn(processParams);
// }
#endif
}
}
}

static void ReadTrack(IList<MidiEvent> track)
{
foreach (var me in track)
Expand Down Expand Up @@ -738,7 +738,7 @@ static IReadOnlyDictionary<int, EventProcessFn> BuildGuitarMidiNoteNumberToProce
{
{ MidIOHelper.STARPOWER_NOTE, ProcessNoteOnEventAsStarpower },
{ MidIOHelper.TAP_NOTE_CH, (in EventProcessParams eventProcessParams) => {
ProcessNoteOnEventAsForcedType(eventProcessParams, MoonNote.NoteType.Tap);
ProcessNoteOnEventAsForcedType(eventProcessParams, MoonNote.MoonNoteType.Tap);
}},
{ MidIOHelper.SOLO_NOTE, (in EventProcessParams eventProcessParams) => {
ProcessNoteOnEventAsEvent(eventProcessParams, MidIOHelper.SOLO_EVENT_TEXT, 0, MidIOHelper.SOLO_END_EVENT_TEXT, SOLO_END_CORRECTION_OFFSET);
Expand Down Expand Up @@ -780,14 +780,14 @@ static IReadOnlyDictionary<int, EventProcessFn> BuildGuitarMidiNoteNumberToProce
int flagKey = difficultyStartRange + 5;
processFnDict.Add(flagKey, (in EventProcessParams eventProcessParams) =>
{
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.NoteType.Hopo);
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.MoonNoteType.Hopo);
});
}
{
int flagKey = difficultyStartRange + 6;
processFnDict.Add(flagKey, (in EventProcessParams eventProcessParams) =>
{
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.NoteType.Strum);
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.MoonNoteType.Strum);
});
}
};
Expand All @@ -801,7 +801,7 @@ static IReadOnlyDictionary<int, EventProcessFn> BuildGhlGuitarMidiNoteNumberToPr
{
{ MidIOHelper.STARPOWER_NOTE, ProcessNoteOnEventAsStarpower },
{ MidIOHelper.TAP_NOTE_CH, (in EventProcessParams eventProcessParams) => {
ProcessNoteOnEventAsForcedType(eventProcessParams, MoonNote.NoteType.Tap);
ProcessNoteOnEventAsForcedType(eventProcessParams, MoonNote.MoonNoteType.Tap);
}},
{ MidIOHelper.SOLO_NOTE, (in EventProcessParams eventProcessParams) => {
ProcessNoteOnEventAsEvent(eventProcessParams, MidIOHelper.SOLO_EVENT_TEXT, 0, MidIOHelper.SOLO_END_EVENT_TEXT, SOLO_END_CORRECTION_OFFSET);
Expand Down Expand Up @@ -842,14 +842,14 @@ static IReadOnlyDictionary<int, EventProcessFn> BuildGhlGuitarMidiNoteNumberToPr
int flagKey = difficultyStartRange + 7;
processFnDict.Add(flagKey, (in EventProcessParams eventProcessParams) =>
{
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.NoteType.Hopo);
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.MoonNoteType.Hopo);
});
}
{
int flagKey = difficultyStartRange + 8;
processFnDict.Add(flagKey, (in EventProcessParams eventProcessParams) =>
{
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.NoteType.Strum);
ProcessNoteOnEventAsForcedType(eventProcessParams, difficulty, MoonNote.MoonNoteType.Strum);
});
}
};
Expand Down Expand Up @@ -1035,7 +1035,7 @@ static void ProcessNoteOnEventAsDrumRoll(in EventProcessParams eventProcessParam
}
}

static void ProcessNoteOnEventAsForcedType(in EventProcessParams eventProcessParams, MoonNote.NoteType noteType)
static void ProcessNoteOnEventAsForcedType(in EventProcessParams eventProcessParams, MoonNote.MoonNoteType moonNoteType)
{
var flagEvent = eventProcessParams.midiEvent as NoteOnEvent;
Debug.Assert(flagEvent != null, $"Wrong note event type passed to {nameof(ProcessNoteOnEventAsForcedType)}. Expected: {typeof(NoteOnEvent)}, Actual: {eventProcessParams.midiEvent.GetType()}");
Expand All @@ -1048,12 +1048,12 @@ static void ProcessNoteOnEventAsForcedType(in EventProcessParams eventProcessPar
// Delay the actual processing once all the notes are actually in
eventProcessParams.delayedProcessesList.Add((in EventProcessParams processParams) =>
{
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, diff, noteType);
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, diff, moonNoteType);
});
}
}

static void ProcessNoteOnEventAsForcedType(in EventProcessParams eventProcessParams, MoonSong.Difficulty difficulty, MoonNote.NoteType noteType)
static void ProcessNoteOnEventAsForcedType(in EventProcessParams eventProcessParams, MoonSong.Difficulty difficulty, MoonNote.MoonNoteType moonNoteType)
{
var flagEvent = eventProcessParams.midiEvent as NoteOnEvent;
Debug.Assert(flagEvent != null, $"Wrong note event type passed to {nameof(ProcessNoteOnEventAsForcedType)}. Expected: {typeof(NoteOnEvent)}, Actual: {eventProcessParams.midiEvent.GetType()}");
Expand All @@ -1064,11 +1064,11 @@ static void ProcessNoteOnEventAsForcedType(in EventProcessParams eventProcessPar
// Delay the actual processing once all the notes are actually in
eventProcessParams.delayedProcessesList.Add((in EventProcessParams processParams) =>
{
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, difficulty, noteType);
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, difficulty, moonNoteType);
});
}

static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcessParams, uint startTick, uint endTick, MoonSong.Difficulty difficulty, MoonNote.NoteType noteType)
static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcessParams, uint startTick, uint endTick, MoonSong.Difficulty difficulty, MoonNote.MoonNoteType moonNoteType)
{
var song = eventProcessParams.moonSong;
var instrument = eventProcessParams.moonInstrument;
Expand Down Expand Up @@ -1100,9 +1100,9 @@ static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcess
expectedForceFailure = false;
shouldBeForced = false;

switch (noteType)
switch (moonNoteType)
{
case (MoonNote.NoteType.Strum):
case (MoonNote.MoonNoteType.Strum):
{
if (!moonNote.isChord && moonNote.isNaturalHopo)
{
Expand All @@ -1111,7 +1111,7 @@ static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcess
break;
}

case (MoonNote.NoteType.Hopo):
case (MoonNote.MoonNoteType.Hopo):
{
// Forcing consecutive same-fret HOPOs is possible in charts, but we do not allow it
// (see RB2's chart of Steely Dan - Bodhisattva)
Expand All @@ -1127,7 +1127,7 @@ static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcess
break;
}

case (MoonNote.NoteType.Tap):
case (MoonNote.MoonNoteType.Tap):
{
if (!moonNote.IsOpenNote())
{
Expand All @@ -1149,7 +1149,7 @@ static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcess
}

default:
Debug.Assert(false, $"Unhandled note type {noteType} in .mid forced type processing");
Debug.Assert(false, $"Unhandled note type {moonNoteType} in .mid forced type processing");
continue; // Unhandled
}

Expand All @@ -1167,7 +1167,7 @@ static void ProcessEventAsForcedTypePostDelay(in EventProcessParams eventProcess

lastChordTick = moonNote.tick;

Debug.Assert(moonNote.type == noteType || expectedForceFailure, $"Failed to set forced type! Expected: {noteType} Actual: {moonNote.type} Natural HOPO: {moonNote.isNaturalHopo} Chord: {moonNote.isChord} Forceable: {!moonNote.cannotBeForced}\non {difficulty} {instrument} at tick {moonNote.tick} ({TimeSpan.FromSeconds(moonNote.time):mm':'ss'.'ff})");
Debug.Assert(moonNote.type == moonNoteType || expectedForceFailure, $"Failed to set forced type! Expected: {moonNoteType} Actual: {moonNote.type} Natural HOPO: {moonNote.isNaturalHopo} Chord: {moonNote.isChord} Forceable: {!moonNote.cannotBeForced}\non {difficulty} {instrument} at tick {moonNote.tick} ({TimeSpan.FromSeconds(moonNote.time):mm':'ss'.'ff})");
}
}

Expand Down Expand Up @@ -1301,7 +1301,7 @@ static void ProcessTextEventPairAsStarpower(in EventProcessParams eventProcessPa
}
}

static void ProcessSysExEventPairAsForcedType(in EventProcessParams eventProcessParams, MoonNote.NoteType noteType)
static void ProcessSysExEventPairAsForcedType(in EventProcessParams eventProcessParams, MoonNote.MoonNoteType moonNoteType)
{
var startEvent = eventProcessParams.midiEvent as PhaseShiftSysExStart;
Debug.Assert(startEvent != null, $"Wrong note event type passed to {nameof(ProcessSysExEventPairAsForcedType)}. Expected: {typeof(PhaseShiftSysExStart)}, Actual: {eventProcessParams.midiEvent.GetType()}");
Expand All @@ -1317,7 +1317,7 @@ static void ProcessSysExEventPairAsForcedType(in EventProcessParams eventProcess
{
eventProcessParams.delayedProcessesList.Add((in EventProcessParams processParams) =>
{
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, diff, noteType);
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, diff, moonNoteType);
});
}
}
Expand All @@ -1326,7 +1326,7 @@ static void ProcessSysExEventPairAsForcedType(in EventProcessParams eventProcess
var diff = MidIOHelper.SYSEX_TO_MS_DIFF_LOOKUP[startEvent.difficulty];
eventProcessParams.delayedProcessesList.Add((in EventProcessParams processParams) =>
{
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, diff, noteType);
ProcessEventAsForcedTypePostDelay(processParams, startTick, endTick, diff, moonNoteType);
});
}
}
Expand Down
Loading

0 comments on commit ba1ca58

Please sign in to comment.