From 1a9b75fc21606d8d9ebda3092c65989b3104d775 Mon Sep 17 00:00:00 2001 From: Simon Gagne Date: Tue, 21 Mar 2023 13:16:41 -0400 Subject: Merge chart file --- chordNote.cpp | 7 +++- main.cpp | 128 +++++++++++++++++++++++++++++----------------------------- song.cpp | 7 +++- song.h | 9 +++-- 4 files changed, 80 insertions(+), 71 deletions(-) diff --git a/chordNote.cpp b/chordNote.cpp index 1fa7549..3f1f795 100644 --- a/chordNote.cpp +++ b/chordNote.cpp @@ -96,8 +96,11 @@ void ChordNote::print(){ // Trim all timings to milliseconds void ChordNote::trim(){ - start = start/1000000; - end = end/1000000; + start = start/1000; + if (end != 0) + { + end = end / 1000; + } } // }}} diff --git a/main.cpp b/main.cpp index d72b1d0..9234ef7 100644 --- a/main.cpp +++ b/main.cpp @@ -85,59 +85,61 @@ int main() cout << repertoire[i].getTitle() << " parsed!" << endl; } + std::vector song = repertoire[0].expert; + string displayString; // Initialisation du port de communication //string com; //cout <<"Entrer le port de communication du Arduino: "; //cin >> com; - const int POWERUP_LENGTH = 10000; + const int POWERUP_LENGTH = 5000; const int NB_SQUARES = 50; - ChordNote note1(0, 5200, 5600); - ChordNote note2(0, 6000, 0); - ChordNote note3(0, 6600, 0); - ChordNote note4(0, 8000, 0); - ChordNote note5(0, 9000, 9600); - ChordNote note6(0, 10000, 0); - ChordNote note7(0, 11500, 12000); - ChordNote note8(0, 12400, 0); - ChordNote note9(0, 12600, 0); - ChordNote note10(0, 13000, 13400); - - ChordNote note11(0, 15200, 15600); - ChordNote note12(0, 16000, 0); - ChordNote note13(0, 16600, 0); - ChordNote note14(0, 18000, 0); - ChordNote note15(0, 19000, 19600); - ChordNote note16(0, 20000, 0); - ChordNote note17(0, 21500, 22000); - ChordNote note18(0, 22400, 0); - ChordNote note19(0, 22600, 0); - ChordNote note20(0, 23000, 23400); - - ChordNote note21(0, 25200, 25600); - ChordNote note22(0, 26000, 0); - ChordNote note23(0, 26600, 0); - ChordNote note24(0, 28000, 0); - ChordNote note25(0, 29000, 29600); - - - note2.toggle(0); - /*note2.change(0); - note7.change(2);*/ - - const int NB_NOTES = 25; - ChordNote song[NB_NOTES] = {note1, note2, note3, note4, note5, - note6, note7, note8, note9, note10, - note11, note12, note13, note14, note15, - note16, note17, note18, note19, note20, - note21, note22, note23, note24, note25}; - - const int FRAMERATE = 100; + //ChordNote note1(0, 5200, 5600); + //ChordNote note2(0, 6000, 0); + //ChordNote note3(0, 6600, 0); + //ChordNote note4(0, 8000, 0); + //ChordNote note5(0, 9000, 9600); + //ChordNote note6(0, 10000, 0); + //ChordNote note7(0, 11500, 12000); + //ChordNote note8(0, 12400, 0); + //ChordNote note9(0, 12600, 0); + //ChordNote note10(0, 13000, 13400); + + //ChordNote note11(0, 15200, 15600); + //ChordNote note12(0, 16000, 0); + //ChordNote note13(0, 16600, 0); + //ChordNote note14(0, 18000, 0); + //ChordNote note15(0, 19000, 19600); + //ChordNote note16(0, 20000, 0); + //ChordNote note17(0, 21500, 22000); + //ChordNote note18(0, 22400, 0); + //ChordNote note19(0, 22600, 0); + //ChordNote note20(0, 23000, 23400); + + //ChordNote note21(0, 25200, 25600); + //ChordNote note22(0, 26000, 0); + //ChordNote note23(0, 26600, 0); + //ChordNote note24(0, 28000, 0); + //ChordNote note25(0, 29000, 29600); + + + //note2.toggle(0); + ///*note2.change(0); + //note7.change(2);*/ + + //const int NB_NOTES = 25; + //ChordNote song[NB_NOTES] = {note1, note2, note3, note4, note5, + // note6, note7, note8, note9, note10, + // note11, note12, note13, note14, note15, + // note16, note17, note18, note19, note20, + // note21, note22, note23, note24, note25}; + + const int FRAMERATE = 50; int renderStart = FRAMERATE * (NB_SQUARES); - for (int i = 0; i < NB_NOTES; i++) + for (int i = 0; i < song.size(); i++) { song[i].setRenderStart(renderStart); } @@ -186,7 +188,7 @@ int main() int lastCorrectHoldTime = 0; int powerupStartTime = 0; - int multiplier = 1; + int powerupModifier = 1; std::thread worker(RcvJsonThread); @@ -195,7 +197,8 @@ int main() auto currentTime = chrono::steady_clock::now(); totalDiff = int(std::chrono::duration_cast (currentTime - startTime).count()); - if(totalDiff > 30000)//End of song + //if(totalDiff > 30000)//End of song + if (nextNoteToPlay == song.size()) { isThreadOver = true; worker.join(); @@ -210,7 +213,7 @@ int main() //CHECK NOTES INPUT int nextNoteStart = song[nextNoteToPlay].getStart(); - if (abs(nextNoteStart - diffSinceBeginning) < 25 && nextNoteToPlay < NB_NOTES) + if (abs(nextNoteStart - diffSinceBeginning) < 25 && nextNoteToPlay < song.size()) { bool isNotePlayedCorrectly = ComparePlayedNotes(song[nextNoteToPlay], false); //TODO. DEVRA ETRE A TRUE if (isNotePlayedCorrectly) @@ -222,12 +225,7 @@ int main() { if (notes[i]) { - multiplier = 1; - if (IsInPowerup) - { - multiplier = 2; - } - points += 100 * multiplier; + points += 100 * powerupModifier; } } nextNoteToPlay++; @@ -236,7 +234,7 @@ int main() hasLetGoHold = false; } } - else if (nextNoteStart < diffSinceBeginning && nextNoteToPlay < NB_NOTES) + else if (nextNoteStart < diffSinceBeginning && nextNoteToPlay < song.size()) { nextNoteToPlay++; NotesCorrectStreak = 0; @@ -268,12 +266,7 @@ int main() nbHeldNotes++; } } - multiplier = 1; - if (IsInPowerup) - { - multiplier = 2; - } - points += ((diffSinceBeginning - lastCorrectHoldTime) * nbHeldNotes) * multiplier; + points += ((diffSinceBeginning - lastCorrectHoldTime) * nbHeldNotes) * powerupModifier; } lastCorrectHoldTime = diffSinceBeginning; } @@ -284,15 +277,17 @@ int main() } } - if (IsShaking && LedState == 10) + if (!IsInPowerup && IsShaking && LedState == 10) { IsInPowerup = true; powerupStartTime = diffSinceBeginning; + powerupModifier = 2; } if (IsInPowerup && diffSinceBeginning - powerupStartTime > POWERUP_LENGTH) { IsInPowerup = false; BargraphNeedReset = true; + powerupModifier = 1; } //Gestion affichage @@ -384,20 +379,23 @@ int main() string ledStateString = to_string(LedState); string streakString = to_string(NotesCorrectStreak); string holdTimeString = to_string(points); - string multiplierString = to_string(multiplier); + string powerupModifierString = to_string(powerupModifier); displayString += "Timestamp " + timestampString.substr(0, timestampString.find(".")) + " ms\n"; displayString += "Nb LEDs : " + ledStateString.substr(0, ledStateString.find(".")) + "/10\n"; displayString += "Nb notes de suite : " + streakString.substr(0, streakString.find(".")) + "\n"; displayString += "Points : " + holdTimeString.substr(0, holdTimeString.find(".")) + "\n"; if (IsInPowerup) { - displayString += "Multiplicateur : x" + multiplierString.substr(0, multiplierString.find(".")) + " --- POWERUP !!!!!\n"; + displayString += "Multiplicateur : x" + powerupModifierString.substr(0, powerupModifierString.find(".")) + " --- POWERUP !!!!!\n"; } else { - displayString += "Multiplicateur : x" + multiplierString.substr(0, multiplierString.find(".")) + "\n"; + displayString += "Multiplicateur : x" + powerupModifierString.substr(0, powerupModifierString.find(".")) + "\n"; } + string IsShakingString = to_string(IsShaking); + displayString += "IsShaking : " + IsShakingString.substr(0, IsShakingString.find(".")) + "\n"; + cout << displayString; } } @@ -492,6 +490,10 @@ int main() JoyDir = json_recu[JOY_DIR]; IsShaking = json_recu[ACCEL]; + if (IsShaking) + { + cout << "SENSIBILITE BEN TROP BASSE" << endl; + } /*if(led_state == 10) //lorsque la dixieme led est allumee { diff --git a/song.cpp b/song.cpp index 9ac5f91..84c962d 100644 --- a/song.cpp +++ b/song.cpp @@ -323,8 +323,11 @@ std::string Song::getAudioFile(){ void Song::trim(int difficulty){ // TODO: make this fuction use the difficulty parameter - std::vector*chords = &expert; - chords->trim(); + //std::vector *chords = &expert; + for (int i = 0; i < expert.size(); i++) + { + expert[i].trim(); + } } diff --git a/song.h b/song.h index 5af5fbd..69cdbd5 100644 --- a/song.h +++ b/song.h @@ -37,6 +37,11 @@ class Song{ std::string getGenre(); std::string getAudioFile(); + std::vector easy; + std::vector medium; + std::vector hard; + std::vector expert; + private: const std::string chartFile; std::string title; @@ -49,10 +54,6 @@ class Song{ bool difficulty[4]; // Which difficulties are available int resolution; std::vector timestamps; - std::vector easy; - std::vector medium; - std::vector hard; - std::vector expert; }; //#include "song.cpp" -- cgit v1.2.3