Skip to content

Commit

Permalink
Fix midi loading
Browse files Browse the repository at this point in the history
  • Loading branch information
RileyTheFox committed Apr 27, 2023
1 parent 1f58b5a commit 0a22890
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
21 changes: 17 additions & 4 deletions Assets/Script/Data/YargChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ public List<NoteInfo>[] GhDrums {

public YargChart(MoonSong song) {
_song = song;

allParts = new() {
guitar, guitarCoop, rhythm,bass, keys, RealGuitar, RealBass, drums, realDrums, ghDrums
};
}

public List<NoteInfo>[] GetChartByName(string name) {
Expand All @@ -106,6 +102,23 @@ public List<NoteInfo>[] GetChartByName(string name) {
};
}

public void InitializeArrays() {
Guitar = CreateArray();
GuitarCoop = CreateArray();
Rhythm = CreateArray();
Bass = CreateArray();
Keys = CreateArray();
RealGuitar = CreateArray();
RealBass = CreateArray();
Drums = CreateArray(5);
RealDrums = CreateArray(5);
GhDrums = CreateArray(5);

allParts = new() {
guitar, guitarCoop, rhythm, bass, keys, RealGuitar, RealBass, drums, realDrums, ghDrums
};
}

private List<NoteInfo>[] LoadArray(ref List<NoteInfo>[] notes, IChartLoader<NoteInfo> loader, MoonSong.MoonInstrument instrument, int length = 4) {
notes = new List<NoteInfo>[length];
for (int i = 0; i < length; i++) {
Expand Down
26 changes: 12 additions & 14 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,24 @@ private void LoadChart() {
// }

// Parse
//var parser = new MidiParser(song, files.ToArray());

MoonSong moonSong;
var state = MidReader.CallbackState.None;
if (song.mainFile.EndsWith(".mid")) {
Debug.Log("Reading .mid file");
moonSong = MidReader.ReadMidi(song.mainFile, ref state);
} else if (song.mainFile.EndsWith(".chart")) {
MoonSong moonSong = null;
if (song.mainFile.EndsWith(".chart")) {
Debug.Log("Reading .chart file");
moonSong = ChartReader.ReadChart(song.mainFile);
} else {
throw new Exception("Unknown file type");
}

chart = new YargChart(moonSong);

var handler = new BeatHandler(moonSong);
handler.GenerateBeats();
chart.beats = handler.Beats;
//parser.Parse(chart);
if (song.mainFile.EndsWith(".mid")) {
// Parse
var parser = new MidiParser(song, files.ToArray());
chart.InitializeArrays();
parser.Parse(chart);
} else if(song.mainFile.EndsWith(".chart")) {
var handler = new BeatHandler(moonSong);
handler.GenerateBeats();
chart.beats = handler.Beats;
}

// initialize current tempo
if (chart.beats.Count > 2)
Expand Down

0 comments on commit 0a22890

Please sign in to comment.