summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2023-03-21 14:59:14 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2023-03-21 14:59:14 -0400
commite169020157fae20f21f1f9e244cb86ca049176e8 (patch)
tree601279c023618aff30335efb701c84a0fbb2ae83
parentc4529c56a4687b693254e2d87d57483ce94a7564 (diff)
Song methods utilize the difficulty parameter
-rw-r--r--song.cpp72
-rw-r--r--song.h24
2 files changed, 72 insertions, 24 deletions
diff --git a/song.cpp b/song.cpp
index 84c962d..ba1dcd8 100644
--- a/song.cpp
+++ b/song.cpp
@@ -156,18 +156,31 @@ void Song::printTimestamps(){
}
bool Song::parseChords(int difficulty){
- // List of chords for each difficulty
- const std::vector<ChordNote> *chordDifficulties[4]={&easy,&medium,&hard,&expert};
- // List of patterns to stringPattern
- const std::string patterns[4] = {
- "EasySingle", "MediumSingle", "HardSingle", "ExpertSingle"
- };
- // We set the stringPattern to match depending on the difficulty
- /* std::string stringPattern = patterns[difficulty]; */
- std::string stringPattern = "ExpertSingle";
// We set a chord vector to store point to the correct difficulty vector
- /* std::vector<ChordNote>*chords=(std::vector<ChordNote>*)chordDifficulties[difficulty]; */
- std::vector<ChordNote>*chords = &expert;
+ std::vector<ChordNote>*chords;
+ // We set the stringPattern to match depending on the difficulty
+ std::string stringPattern;
+ switch (difficulty){
+ case DIFFICULTY_EASY:
+ stringPattern = "EasySingle";
+ std::vector<ChordNote>*chords = &easy;
+ break;
+ case DIFFICULTY_MEDIUM:
+ stringPattern = "MediumSingle";
+ std::vector<ChordNote>*chords = &medium;
+ break;
+ case DIFFICULTY_HARD:
+ stringPattern = "HardSingle";
+ std::vector<ChordNote>*chords = &hard;
+ break;
+ case DIFFICULTY_EXPERT:
+ stringPattern = "ExpertSingle";
+ std::vector<ChordNote>*chords = &expert;
+ break;
+ default:
+ std::cerr << "Invalid difficulty" << std::endl;
+ return false;
+ }
// We open the chart file
std::ifstream file(chartFile);
if (!file.is_open()) {
@@ -231,6 +244,23 @@ bool Song::parseChords(int difficulty){
#endif // DEBUG
// Create a new chord and add it to the vector
chords->push_back(ChordNote(fret, chordTime, chordEnd));
+ /* switch (difficulty){ */
+ /* case DIFFICULTY_EASY: */
+ /* easy.push_back(ChordNote(fret, chordTime, chordEnd)); */
+ /* break; */
+ /* case DIFFICULTY_MEDIUM: */
+ /* medium.push_back(ChordNote(fret, chordTime, chordEnd)); */
+ /* break; */
+ /* case DIFFICULTY_HARD: */
+ /* hard.push_back(ChordNote(fret, chordTime, chordEnd)); */
+ /* break; */
+ /* case DIFFICULTY_EXPERT: */
+ /* expert.push_back(ChordNote(fret, chordTime, chordEnd)); */
+ /* break; */
+ /* default: */
+ /* std::cerr << "Invalid difficulty" << std::endl; */
+ /* return false; */
+ /* } */
}
else if (line.find("[") != std::string::npos) return true;
}
@@ -242,7 +272,24 @@ bool Song::parseChords(int difficulty){
void Song::consolidateChords(int difficulty){
// TODO: make this fuction use the difficulty parameter
- std::vector<ChordNote>*chords = &expert;
+ std::vector<ChordNote>*chords;
+ switch (difficulty){
+ case DIFFICULTY_EASY:
+ std::vector<ChordNote>*chords = &easy;
+ break;
+ case DIFFICULTY_MEDIUM:
+ std::vector<ChordNote>*chords = &medium;
+ break;
+ case DIFFICULTY_HARD:
+ std::vector<ChordNote>*chords = &hard;
+ break;
+ case DIFFICULTY_EXPERT:
+ std::vector<ChordNote>*chords = &expert;
+ break;
+ default:
+ std::cerr << "Invalid difficulty" << std::endl;
+ return;
+ }
// Number of chords in the vector
int chordSize = chords->size();
// Go through all the chords
@@ -282,6 +329,7 @@ void Song::consolidateChords(int difficulty){
}
void Song::printChords(int difficulty){
+ // TODO: make this fuction use the difficulty parameter
for (int i=0; i<expert.size(); i++){
expert[i].print();
}
diff --git a/song.h b/song.h
index 69cdbd5..73ae2bf 100644
--- a/song.h
+++ b/song.h
@@ -14,20 +14,21 @@
class Song{
public:
+ // Constructors/Destructors
Song(std::string chartFile);
~Song();
-
- void parseInfo(); // info from "Song" section
- void parseSync(); // timestamps from "SyncTrack" section
- bool parseChords(int difficulty); // chords from "Events" section
-
+ // Pre-Processing
+ void parseInfo(); // info from "Song" section
+ void parseSync(); // timestamps from "SyncTrack" section
+ bool parseChords(int difficulty=0); // chords from "Events" section
+ void consolidateChords(int difficulty=0); // Merge chords with same start/end times
+ void trim(int difficulty); // Trim chord timings from
+ // nanoseconds to milliseconds
+ // Print statements for debugging
void print();
void printTimestamps();
- void printChords(int difficulty);
-
- void consolidateChords(int difficulty); // Merge chords with same start/end times
- void trim(int difficulty); // Trim chord timings from nanoseconds to milliseconds
-
+ void printChords(int difficulty=0);
+ // Getters
std::string getChartFile();
std::string getTitle();
std::string getArtist();
@@ -36,12 +37,11 @@ class Song{
std::string getYear();
std::string getGenre();
std::string getAudioFile();
-
+ // Public variables (Chord vectors for each difficulty) TODO: Make private
std::vector<ChordNote> easy;
std::vector<ChordNote> medium;
std::vector<ChordNote> hard;
std::vector<ChordNote> expert;
-
private:
const std::string chartFile;
std::string title;