diff --git a/includes/RhythmGameUtilities/Parsers.hpp b/includes/RhythmGameUtilities/Parsers.hpp index afd466a..8f00da3 100644 --- a/includes/RhythmGameUtilities/Parsers.hpp +++ b/includes/RhythmGameUtilities/Parsers.hpp @@ -1,9 +1,17 @@ #pragma once +#include +#include #include #include #include +#include "Enums/Difficulty.h" +#include "Enums/NamedSection.h" +#include "Enums/TypeCode.h" + +#include "Structs/Note.h" + #include "Utilities.hpp" #ifdef _WIN32 @@ -91,4 +99,96 @@ std::vector ParseSectionsFromChart(const char *contents) return sections; } +std::map +ParseTimeSignaturesFromChartSection(std::vector sections) +{ + auto timeSignatures = std::map(); + + for (auto §ion : sections) + { + if (section.name == ToString(NamedSection::SyncTrack)) + { + for (auto &line : section.lines) + { + if (line.second.front() == + ToString(TypeCode::TimeSignatureMarker)) + { + timeSignatures.insert( + {std::stoi(line.first), std::stoi(line.second.at(1))}); + } + } + } + } + + return timeSignatures; +} + +std::map ParseBpmFromChartSection(std::vector sections) +{ + auto bpm = std::map(); + + for (auto §ion : sections) + { + if (section.name == ToString(NamedSection::SyncTrack)) + { + for (auto &line : section.lines) + { + if (line.second.front() == ToString(TypeCode::BPM_Marker)) + { + bpm.insert( + {std::stoi(line.first), std::stoi(line.second.at(1))}); + } + } + } + } + + return bpm; +} + +std::vector ParseNotesFromChartSection(std::vector sections, + Difficulty difficulty) +{ + auto notes = std::vector(); + + for (auto §ion : sections) + { + if (section.name == ToString(difficulty) + "Single") + { + for (auto &line : section.lines) + { + if (line.second.front() == ToString(TypeCode::NoteMarker)) + { + notes.push_back({std::stoi(line.first), + std::stoi(line.second.at(1)), + std::stoi(line.second.at(2))}); + } + } + } + } + + return notes; +} + +std::map +ParseLyricsFromChartSection(std::vector sections) +{ + auto lyrics = std::map(); + + for (auto §ion : sections) + { + if (section.name == ToString(NamedSection::Events)) + { + for (auto &line : section.lines) + { + if (line.second.back().rfind("lyric", 0) == 0) + { + lyrics.insert({std::stoi(line.first), line.second.at(1)}); + } + } + } + } + + return lyrics; +} + } // namespace RhythmGameUtilities diff --git a/includes/RhythmGameUtilities/Structs/Song.h b/includes/RhythmGameUtilities/Structs/Song.h new file mode 100644 index 0000000..e82a165 --- /dev/null +++ b/includes/RhythmGameUtilities/Structs/Song.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include + +#include "RhythmGameUtilities/Enums/Difficulty.h" +#include "RhythmGameUtilities/Structs/BeatBar.h" +#include "RhythmGameUtilities/Structs/Note.h" + +namespace RhythmGameUtilities +{ + +struct Song +{ + + // Title of the song. + std::string Name; + + // Artist(s) or band(s) behind the song. + std::string Artist; + + // Title of the album the song is featured in. + std::string Album; + + // Genre of the song. + std::string Genre; + + // Year of the song’s release.
Typically preceded by a comma and space, + // for example `, 2002`, to make importing into GHTCP quicker. + std::string Year; + + // Community member who charted the song. + std::string Charter; + + // (Required) Number of positional ticks between each 1/4th note in the + // chart. + int Resolution; + + // Estimated difficulty of the song. + int Difficulty; + + // Start time of the audio, in seconds.
A higher value makes the audio + // start sooner. + double Offset; + + // Time of the song, in seconds, where the song preview should start. + double PreviewStart; + + // Time of the song, in seconds, where the song preview should end. + double PreviewEnd; + + // The main audio stream.
When other audio stems are present, this is + // background audio not in the other tracks and/or instruments not charted. + std::string MusicStream; + + std::map Lyrics; + + std::map> Difficulties; + + std::map BPM; + + std::map> TimeSignatures; + + std::vector BeatBars; +}; + +} // namespace RhythmGameUtilities diff --git a/tests/RhythmGameUtilities/Parsers.cpp b/tests/RhythmGameUtilities/Parsers.cpp index 38dc789..212c56f 100644 --- a/tests/RhythmGameUtilities/Parsers.cpp +++ b/tests/RhythmGameUtilities/Parsers.cpp @@ -104,10 +104,59 @@ void testParseValuesFromChartSections() std::cout << "."; } +void testParseTimeSignaturesFromChartSection() +{ + auto sections = ParseSectionsFromChart(contents); + + auto lines = ParseTimeSignaturesFromChartSection(sections); + + assert(lines.size() == 4); + + std::cout << "."; +} + +void testParseBpmFromChartSection() +{ + auto sections = ParseSectionsFromChart(contents); + + auto lines = ParseBpmFromChartSection(sections); + + assert(lines.size() == 7); + + std::cout << "."; +} + +void testParseNotesFromChartSection() +{ + auto sections = ParseSectionsFromChart(contents); + + auto lines = ParseNotesFromChartSection(sections, Difficulty::Expert); + + assert(lines.size() == 8); + + std::cout << "."; +} + +void testParseLyricsFromChartSection() +{ + auto sections = ParseSectionsFromChart(contents); + + auto lines = ParseLyricsFromChartSection(sections); + + assert(lines.size() == 12); + + std::cout << "."; +} + int main() { testParseSectionsFromChart(); testParseValuesFromChartSections(); + testParseTimeSignaturesFromChartSection(); + testParseBpmFromChartSection(); + testParseNotesFromChartSection(); + testParseLyricsFromChartSection(); + return 0; }