Skip to content

Commit

Permalink
Started song upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Feb 3, 2023
1 parent 8c35e0d commit 6374f46
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
26 changes: 22 additions & 4 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ private IEnumerator StartSong() {
audioSources.Add(Path.GetFileNameWithoutExtension(file.Name), audioSource);
}

// Load midi
var parser = new MidiParser(Path.Combine(song.folder.FullName, "notes.mid"), song.delay);
chart = new Chart();
parser.Parse(chart);
// Load chart (from midi, upgrades, etc.)
LoadChart();

// Spawn tracks
for (int i = 0; i < PlayerManager.players.Count; i++) {
Expand Down Expand Up @@ -112,6 +110,26 @@ private IEnumerator StartSong() {
SongStarted = true;
}

private void LoadChart() {
// Add main file
var files = new List<string> {
Path.Combine(song.folder.FullName, "notes.mid")
};

// Look for upgrades and add
var upgradeFolder = new DirectoryInfo(Path.Combine(song.folder.FullName, "yarg_upgrade"));
if (upgradeFolder.Exists) {
foreach (var midi in upgradeFolder.GetFiles("*.mid")) {
files.Add(midi.FullName);
}
}

// Parse
var parser = new MidiParser(files.ToArray(), song.delay);
chart = new Chart();
parser.Parse(chart);
}

private void Update() {
if (!SongStarted) {
return;
Expand Down
6 changes: 3 additions & 3 deletions Assets/Script/Serialization/Parser/AbstractParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace YARG.Serialization.Parser {
public abstract class AbstractParser {
protected string file;
protected string[] files;
protected float delay;

public AbstractParser(string file, float delay) {
this.file = file;
public AbstractParser(string[] files, float delay) {
this.files = files;
this.delay = delay;
}

Expand Down
25 changes: 23 additions & 2 deletions Assets/Script/Serialization/Parser/MidiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,29 @@ private struct EventIR {

public MidiFile midi;

public MidiParser(string file, float delay) : base(file, delay) {
midi = MidiFile.Read(file);
public MidiParser(string[] files, float delay) : base(files, delay) {
midi = MidiFile.Read(files[0]);

// Merge midi files
for (int i = 1; i < files.Length; i++) {
var upgrade = MidiFile.Read(files[i]);

foreach (var trackChunk in upgrade.GetTrackChunks()) {
foreach (var trackEvent in trackChunk.Events) {
if (trackEvent is not SequenceTrackNameEvent trackName) {
continue;
}

// Only merge specific tracks
switch (trackName.Text) {
case "PART REAL_GUITAR":
case "PART REAL_BASS":
midi.Chunks.Add(trackChunk);
break;
}
}
}
}
}

public override void Parse(Chart chart) {
Expand Down

0 comments on commit 6374f46

Please sign in to comment.