Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic .chart drums loading #252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Assets/Script/Chart/Loaders/FiveLaneDrumsChartLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public class FiveLaneDrumsChartLoader : IChartLoader<NoteInfo> {
public List<NoteInfo> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<NoteInfo>();
bool doubleBass = false;
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
doubleBass = true;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Drums, MoonSong.Difficulty.Easy - (int) difficulty);

foreach (var moonNote in chart.notes) {
// Ignore double-kicks if not Expert+
if (!doubleBass && (moonNote.flags & MoonNote.Flags.DoubleKick) != 0)
continue;

// Convert note value
int pad = MoonDrumNoteToPad(moonNote);
if (pad == -1)
continue;

// Length of the note in realtime
double timeLength = song.TickToTime(moonNote.tick + moonNote.length, song.resolution) - moonNote.time;

var note = new NoteInfo {
time = (float) moonNote.time,
length = (float) timeLength,
fret = pad,
hopo = moonNote.type == MoonNote.MoonNoteType.Cymbal
};

notes.Add(note);
}

// TODO: Need to handle playing 4-lane charts on 5-lane
return notes;
}

private int MoonDrumNoteToPad(MoonNote note) {
return note.drumPad switch {
MoonNote.DrumPad.Kick => 5,
MoonNote.DrumPad.Red => 0,
MoonNote.DrumPad.Yellow => 1,
MoonNote.DrumPad.Blue => 2,
MoonNote.DrumPad.Orange => 3,
MoonNote.DrumPad.Green => 4,
_ => -1
};
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/Chart/Loaders/FiveLaneDrumsChartLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Assets/Script/Chart/Loaders/FourLaneDrumsChartLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public class FourLaneDrumsChartLoader : IChartLoader<NoteInfo> {
private bool _proDrums;

public FourLaneDrumsChartLoader(bool pro) {
_proDrums = pro;
}

public List<NoteInfo> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<NoteInfo>();
bool doubleBass = false;
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
doubleBass = true;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Drums, MoonSong.Difficulty.Easy - (int) difficulty);

foreach (var moonNote in chart.notes) {
// Ignore double-kicks if not Expert+
if (!doubleBass && (moonNote.flags & MoonNote.Flags.DoubleKick) != 0)
continue;

// Convert note value
int pad = MoonDrumNoteToPad(moonNote);
if (pad == -1)
continue;

// Length of the note in realtime
double timeLength = song.TickToTime(moonNote.tick + moonNote.length, song.resolution) - moonNote.time;

var note = new NoteInfo {
time = (float) moonNote.time,
length = (float) timeLength,
fret = pad,
hopo = _proDrums && moonNote.type == MoonNote.MoonNoteType.Cymbal
};

notes.Add(note);
}

// TODO: Need to handle playing 5-lane charts on 4-lane
return notes;
}

private int MoonDrumNoteToPad(MoonNote note) {
return note.drumPad switch {
MoonNote.DrumPad.Kick => 4,
MoonNote.DrumPad.Red => 0,
MoonNote.DrumPad.Yellow => 1,
MoonNote.DrumPad.Blue => 2,
MoonNote.DrumPad.Orange => 3, // Moonscraper internally uses Orange for 4-lane green
MoonNote.DrumPad.Green => 3, // Turn 5-lane green into 4-lane green
_ => -1
};
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/Chart/Loaders/FourLaneDrumsChartLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Assets/Script/Chart/Loaders/GuitarChartLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace YARG.Chart {
public class GuitarChartLoader : IChartLoader<NoteInfo> {
public List<NoteInfo> GetNotesFromChart(MoonSong song, MoonChart chart) {
public List<NoteInfo> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<NoteInfo>();
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Guitar, MoonSong.Difficulty.Easy - (int) difficulty);

foreach (var moonNote in chart.notes) {
// Length of the note in realtime
Expand Down
3 changes: 2 additions & 1 deletion Assets/Script/Chart/Loaders/IChartLoader.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public interface IChartLoader<T> {

public List<T> GetNotesFromChart(MoonSong song, MoonChart chart);
public List<T> GetNotesFromChart(MoonSong song, Difficulty chart);

}
}
15 changes: 10 additions & 5 deletions Assets/Script/Chart/Loaders/New/NewDrumChartLoader.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public class NewDrumChartLoader : IChartLoader<DrumNote> {

private readonly bool _isPro;
private readonly bool _isDoubleBass;

public NewDrumChartLoader(bool isPro, bool doubleBass) {
public NewDrumChartLoader(bool isPro) {
_isPro = isPro;
_isDoubleBass = doubleBass;
}

public List<DrumNote> GetNotesFromChart(MoonSong song, MoonChart chart) {
public List<DrumNote> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<DrumNote>();
bool doubleBass = false;
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
doubleBass = true;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Drums, MoonSong.Difficulty.Easy - (int) difficulty);

// do star power later lol idk how it works

Expand All @@ -34,7 +39,7 @@ public List<DrumNote> GetNotesFromChart(MoonSong song, MoonChart chart) {
// Is kick, is double kick note but double bass not active
// Skip the note
if (moonNote.drumPad == MoonNote.DrumPad.Kick && (moonNote.flags & MoonNote.Flags.DoubleKick) != 0 &&
!_isDoubleBass) {
!doubleBass) {
continue;
}

Expand Down
7 changes: 6 additions & 1 deletion Assets/Script/Chart/Loaders/New/NewGuitarChartLoader.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public class NewGuitarChartLoader : IChartLoader<GuitarNote> {

public List<GuitarNote> GetNotesFromChart(MoonSong song, MoonChart chart) {
public List<GuitarNote> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<GuitarNote>();
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Guitar, MoonSong.Difficulty.Easy - (int) difficulty);

var starpowers = chart.starPower.ToArray();

Expand Down
19 changes: 10 additions & 9 deletions Assets/Script/Data/YargChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ public List<NoteInfo>[] Keys {

private List<NoteInfo>[] drums;
public List<NoteInfo>[] Drums {
get => drums;// ?? LoadArray(new DrumsChartLoader(false), MoonSong.MoonInstrument.Drums, 4);
get => drums ?? LoadArray(ref drums, new FourLaneDrumsChartLoader(pro: false), MoonSong.MoonInstrument.Drums, Difficulty.EXPERT_PLUS);
set => drums = value;
}

private List<NoteInfo>[] realDrums;
public List<NoteInfo>[] RealDrums {
get => realDrums;// ?? LoadArray(new DrumsChartLoader(true), MoonSong.MoonInstrument.Drums, 4);
get => realDrums ?? LoadArray(ref realDrums, new FourLaneDrumsChartLoader(pro: true), MoonSong.MoonInstrument.Drums, Difficulty.EXPERT_PLUS, isPro: true);
set => realDrums = value;
}

private List<NoteInfo>[] ghDrums;
public List<NoteInfo>[] GhDrums {
get => ghDrums;// ?? LoadArray(new DrumsChartLoader(false), MoonSong.MoonInstrument.Drums, 4);
get => ghDrums ?? LoadArray(ref ghDrums, new FiveLaneDrumsChartLoader(), MoonSong.MoonInstrument.Drums, Difficulty.EXPERT_PLUS, isGh: true);
set => ghDrums = value;
}

Expand Down Expand Up @@ -121,11 +122,11 @@ public void InitializeArrays() {
};
}

private List<NoteInfo>[] LoadArray(ref List<NoteInfo>[] notes, IChartLoader<NoteInfo> loader, MoonSong.MoonInstrument instrument, int length = 4,
bool isPro = false, bool isGh = false) {
notes = new List<NoteInfo>[length];
for (int i = 0; i < length; i++) {
notes[i] = loader.GetNotesFromChart(_song, _song.GetChart(instrument, (MoonSong.Difficulty) length - 1 - i));
private List<NoteInfo>[] LoadArray(ref List<NoteInfo>[] notes, IChartLoader<NoteInfo> loader, MoonSong.MoonInstrument instrument,
Difficulty maxDifficulty = Difficulty.EXPERT, bool isPro = false, bool isGh = false) {
notes = new List<NoteInfo>[(int) (maxDifficulty + 1)];
for (Difficulty diff = Difficulty.EASY; diff <= maxDifficulty; diff++) {
notes[(int) diff] = loader.GetNotesFromChart(_song, diff);
}

if (_loadedEvents.Contains(instrument)) {
Expand Down