Skip to content

Commit

Permalink
Clean up/re-organize note types and add some new things to them (YARC…
Browse files Browse the repository at this point in the history
…-Official#27)

* Rework chart event constructor parameters
- Reorganize note parameters to better follow class hierarchy
- Remove previousNote parameter, it's not really that useful
- Remove text event length parameters

* Reorganize note flags
- Move instrument-specific note flags to their respective types
- Change values to use `1 << x` instead of raw values
- Move IsChord to Note, and base it off of the child note count instead of a flag
- Add missing properties for flags

* Tidy up chart event fields and properties
- Reordered by modifiers: private first, public last
- Aligned everything in columns

* Fix child notes list not getting created

* Add guitar/drums note value definitions and vocals harmony part value
Removed the drums cymbal flag, it's now part of the note value

* Add note type values to guitar/drum notes

* Add SP activator flag to drum notes

* Add Pro Guitar note

* (Re-)Add convenience properties for note types

* Allow publically setting note type values

* Simplify guitar/Pro guitar IsSustain property
  • Loading branch information
TheNathannator authored Jun 17, 2023
1 parent c6e8119 commit 489541f
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 95 deletions.
8 changes: 4 additions & 4 deletions YARG.Core/Chart/Events/ChartEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace YARG.Core.Chart
/// </summary>
public abstract class ChartEvent
{
public double Time { get; }
public double Time { get; }
public double TimeLength { get; }
public double TimeEnd => Time + TimeLength;
public double TimeEnd => Time + TimeLength;

public uint Tick { get; }
public uint Tick { get; }
public uint TickLength { get; }
public uint TickEnd => Tick + TickLength;
public uint TickEnd => Tick + TickLength;

public ChartEvent(double time, double timeLength, uint tick, uint tickLength)
{
Expand Down
4 changes: 2 additions & 2 deletions YARG.Core/Chart/Events/TextEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class TextEvent : ChartEvent
{
public string Text { get; }

public TextEvent(string text, double time, double timeLength, uint tick, uint tickLength)
: base(time, timeLength, tick, tickLength)
public TextEvent(string text, double time, uint tick)
: base(time, 0, tick, 0)
{
Text = text;
}
Expand Down
73 changes: 67 additions & 6 deletions YARG.Core/Chart/Notes/DrumNote.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,79 @@
namespace YARG.Core.Chart
using System;

namespace YARG.Core.Chart
{
public class DrumNote : Note
{
private readonly DrumNoteFlags _drumFlags;

public int Pad { get; }

public bool IsCymbal => (_flags & NoteFlags.Cymbal) != 0;
public DrumNoteType Type { get; set; }

public bool IsGhost => (_flags & NoteFlags.DrumGhost) != 0;
public bool IsAccent => (_flags & NoteFlags.DrumAccent) != 0;
public bool IsNeutral => Type == DrumNoteType.Neutral;
public bool IsAccent => Type == DrumNoteType.Accent;
public bool IsGhost => Type == DrumNoteType.Ghost;

public DrumNote(Note previousNote, double time, uint tick, int pad, NoteFlags flags)
: base(previousNote, time, 0, tick, 0, flags)
public bool IsStarPowerActivator => (_drumFlags & DrumNoteFlags.StarPowerActivator) != 0;

public DrumNote(FourLaneDrumPad pad, DrumNoteType noteType, DrumNoteFlags drumFlags,
NoteFlags flags, double time, uint tick)
: this((int)pad, noteType, drumFlags, flags, time, tick)
{
}

public DrumNote(FiveLaneDrumPad pad, DrumNoteType noteType, DrumNoteFlags drumFlags,
NoteFlags flags, double time, uint tick)
: this((int)pad, noteType, drumFlags, flags, time, tick)
{
}

public DrumNote(int pad, DrumNoteType noteType, DrumNoteFlags drumFlags, NoteFlags flags, double time, uint tick)
: base(flags, time, 0, tick, 0)
{
Pad = pad;
Type = noteType;
_drumFlags = drumFlags;
}
}

public enum FourLaneDrumPad
{
Kick,

RedDrum,
YellowDrum,
BlueDrum,
GreenDrum,

YellowCymbal,
BlueCymbal,
GreenCymbal,
}

public enum FiveLaneDrumPad
{
Kick,

Red,
Yellow,
Blue,
Orange,
Green,
}

public enum DrumNoteType
{
Neutral,
Ghost,
Accent,
}

[Flags]
public enum DrumNoteFlags
{
None = 0,

StarPowerActivator = 1 << 0,
}
}
117 changes: 60 additions & 57 deletions YARG.Core/Chart/Notes/GuitarNote.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,46 @@
using MoonscraperChartEditor.Song;
using System;
using MoonscraperChartEditor.Song;

namespace YARG.Core.Chart
{
public class GuitarNote : Note
{
private readonly GuitarNoteFlags _guitarFlags;

public int Fret { get; }
public int NoteMask { get; private set; }

public bool IsSustain { get; }

public bool IsChord => (_flags & NoteFlags.Chord) != 0;

public bool IsExtendedSustain => (_flags & NoteFlags.ExtendedSustain) != 0;
public bool IsDisjoint => (_flags & NoteFlags.Disjoint) != 0;
public GuitarNoteType Type { get; set; }

private bool _isForced;
public bool IsStrum => Type == GuitarNoteType.Strum;
public bool IsHopo => Type == GuitarNoteType.Hopo;
public bool IsTap => Type == GuitarNoteType.Tap;

private bool _isStrum;
private bool _isHopo;
private bool _isTap;
public bool IsSustain => TickLength > 0;

public bool IsStrum
{
get => _isStrum;
set
{
if (value)
{
IsHopo = false;
IsTap = false;
}

_isStrum = true;
}
}
public bool IsExtendedSustain => (_guitarFlags & GuitarNoteFlags.ExtendedSustain) != 0;
public bool IsDisjoint => (_guitarFlags & GuitarNoteFlags.Disjoint) != 0;

public bool IsHopo
public GuitarNote(FiveFretGuitarFret fret, GuitarNoteType noteType, GuitarNoteFlags guitarFlags,
NoteFlags flags, double time, double timeLength, uint tick, uint tickLength)
: this((int)fret, noteType, guitarFlags, flags, time, timeLength, tick, tickLength)
{
get => _isHopo;
set
{
if (value)
{
IsStrum = false;
IsTap = false;
}

_isHopo = true;
}
}

public bool IsTap
public GuitarNote(SixFretGuitarFret fret, GuitarNoteType noteType, GuitarNoteFlags guitarFlags,
NoteFlags flags, double time, double timeLength, uint tick, uint tickLength)
: this((int)fret, noteType, guitarFlags, flags, time, timeLength, tick, tickLength)
{
get => _isTap;
set
{
if (value)
{
IsStrum = false;
IsHopo = false;
}

_isTap = true;
}
}

public GuitarNote(Note previousNote, double time, double timeLength, uint tick, uint tickLength, int fret,
MoonNote.MoonNoteType moonNoteType, NoteFlags flags) : base(previousNote, time, timeLength, tick, tickLength, flags)
public GuitarNote(int fret, GuitarNoteType noteType, GuitarNoteFlags guitarFlags, NoteFlags flags,
double time, double timeLength, uint tick, uint tickLength)
: base(flags, time, timeLength, tick, tickLength)
{
Fret = fret;
Type = noteType;

IsSustain = tickLength > 0;

_isStrum = moonNoteType == MoonNote.MoonNoteType.Strum;
_isTap = moonNoteType == MoonNote.MoonNoteType.Tap;
_isHopo = moonNoteType == MoonNote.MoonNoteType.Hopo && !_isTap;
_guitarFlags = guitarFlags;

NoteMask = 1 << fret - 1;
}
Expand All @@ -86,7 +52,44 @@ public override void AddChildNote(Note note)

base.AddChildNote(note);

NoteMask |= 1 << guitarNote.Fret - 1;
NoteMask |= 1 << guitarNote.Fret;
}
}

public enum FiveFretGuitarFret
{
Open,
Green,
Red,
Yellow,
Blue,
Orange,
}

public enum SixFretGuitarFret
{
Open,
Black1,
Black2,
Black3,
White1,
White2,
White3,
}

public enum GuitarNoteType
{
Strum,
Hopo,
Tap
}

[Flags]
public enum GuitarNoteFlags
{
None = 0,

ExtendedSustain = 1 << 0,
Disjoint = 1 << 1,
}
}
43 changes: 21 additions & 22 deletions YARG.Core/Chart/Notes/Note.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
using System;
using System;
using System.Collections.Generic;

namespace YARG.Core.Chart
{
public abstract class Note : ChartEvent
{
private readonly List<Note> _childNotes = new();
private readonly NoteFlags _flags;

public Note previousNote;
public Note nextNote;

private readonly List<Note> _childNotes;
public IReadOnlyList<Note> ChildNotes => _childNotes;

protected NoteFlags _flags;
public IReadOnlyList<Note> ChildNotes => _childNotes;

public bool IsChord => _childNotes.Count > 0;

public bool IsStarPowerStart => (_flags & NoteFlags.StarPowerStart) != 0;
public bool IsStarPower => (_flags & NoteFlags.StarPower) != 0;
public bool IsStarPowerStart => (_flags & NoteFlags.StarPowerStart) != 0;
public bool IsStarPowerEnd => (_flags & NoteFlags.StarPowerEnd) != 0;

public bool IsSoloStart => (_flags & NoteFlags.SoloStart) != 0;
public bool IsSoloEnd => (_flags & NoteFlags.SoloEnd) != 0;

public bool WasHit { get; private set; }
public bool WasHit { get; private set; }
public bool WasMissed { get; private set; }

protected Note(Note previousNote, double time, double timeLength, uint tick, uint tickLength, NoteFlags flags)
protected Note(NoteFlags flags, double time, double timeLength, uint tick, uint tickLength)
: base(time, timeLength, tick, tickLength)
{
this.previousNote = previousNote;
_flags = flags;
}

Expand Down Expand Up @@ -61,18 +65,13 @@ public void SetMissState(bool miss, bool includeChildren)
[Flags]
public enum NoteFlags
{
None = 0,
Chord = 1,
ExtendedSustain = 2,
Disjoint = 4,
StarPowerStart = 8,
StarPower = 16,
StarPowerEnd = 32,
SoloStart = 64,
SoloEnd = 128,
Cymbal = 256,
DrumGhost = 512,
DrumAccent = 1024,
VocalNonPitched = 2048,
None = 0,

StarPower = 1 << 0,
StarPowerStart = 1 << 1,
StarPowerEnd = 1 << 2,

SoloStart = 1 << 3,
SoloEnd = 1 << 4,
}
}
54 changes: 54 additions & 0 deletions YARG.Core/Chart/Notes/ProGuitarNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;

namespace YARG.Core.Chart
{
public class ProGuitarNote : Note
{
private readonly ProGuitarNoteFlags _proFlags;

public int String { get; }
public int Fret { get; }

public ProGuitarNoteType Type { get; set; }

public bool IsStrum => Type == ProGuitarNoteType.Strum;
public bool IsHopo => Type == ProGuitarNoteType.Hopo;
public bool IsTap => Type == ProGuitarNoteType.Tap;

public bool IsSustain => TickLength > 0;

public bool IsExtendedSustain => (_proFlags & ProGuitarNoteFlags.ExtendedSustain) != 0;
public bool IsDisjoint => (_proFlags & ProGuitarNoteFlags.Disjoint) != 0;

public bool IsMuted => (_proFlags & ProGuitarNoteFlags.Muted) != 0;

public ProGuitarNote(int stringNo, int fret, ProGuitarNoteType type, ProGuitarNoteFlags proFlags,
NoteFlags flags, double time, double timeLength, uint tick, uint tickLength)
: base(flags, time, timeLength, tick, tickLength)
{
String = stringNo;
Fret = fret;
Type = type;

_proFlags = proFlags;
}
}

public enum ProGuitarNoteType
{
Strum,
Hopo,
Tap,
}

[Flags]
public enum ProGuitarNoteFlags
{
None = 0,

ExtendedSustain = 1 << 0,
Disjoint = 1 << 1,

Muted = 1 << 2,
}
}
Loading

0 comments on commit 489541f

Please sign in to comment.