From ed67d84c88e2c477a42610997064085d687b4716 Mon Sep 17 00:00:00 2001 From: antpoms <148887171+antpoms@users.noreply.github.com> Date: Sat, 14 Jun 2025 21:56:10 +0200 Subject: [PATCH 1/2] =?UTF-8?q?difficult=C3=A9=20adaptative?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SimpleGame/src/Include/AudioEmitter.hpp | 1 + SimpleGame/src/Source/AudioEmitter.cpp | 47 +++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/SimpleGame/src/Include/AudioEmitter.hpp b/SimpleGame/src/Include/AudioEmitter.hpp index d41cae8..09b19cd 100644 --- a/SimpleGame/src/Include/AudioEmitter.hpp +++ b/SimpleGame/src/Include/AudioEmitter.hpp @@ -16,6 +16,7 @@ private: std::vector> markov_matrix_chords; std::vector> markov_matrix_melody; int nbr_melo_max{4}; + int nbr_melo_total{ 64 }; int current_beat{0}; std::vector> rythmes; int index_note; diff --git a/SimpleGame/src/Source/AudioEmitter.cpp b/SimpleGame/src/Source/AudioEmitter.cpp index 26bd1bd..3d886f8 100644 --- a/SimpleGame/src/Source/AudioEmitter.cpp +++ b/SimpleGame/src/Source/AudioEmitter.cpp @@ -58,6 +58,9 @@ AudioEmitter::AudioEmitter() { for (int i = 0; i < 7; i += 1) { chords.push_back(std::unique_ptr(rawChords[i])); } + for (int i = 0; i < 7; i += 1) { + chords.push_back(std::unique_ptr(rawChords2[i])); + } std::vector rawNotes(15); ERRCHECK(system->createSound("media/notes/A1.mp3", FMOD_LOOP_OFF, nullptr, @@ -96,10 +99,6 @@ AudioEmitter::AudioEmitter() { index_note = firstNote(); - std::vector> rythmes2 = { - - }; - rythmes = { {0, 4}, {0, 2, 4, 6}, @@ -285,6 +284,14 @@ std::vector> AudioEmitter::generateMusic() { float beatDuration = tempo / 60.f; unsigned int sampleRate = 48000; int maxsize = 400; + int variation = 0; + if (((current_beat / nbr_melo_max) % 4) < 2) { //On change la manière dont sont joués les accords toutes les 2*nbr_melo_max mélodies générées + variation = 0; + } + else { + variation = 1; + } + int nbrChords = 7; if (activeChannels.size() > maxsize) { for (int i = 0; i < maxsize / 2; i += 1) { if (activeChannels[i]) { @@ -301,7 +308,7 @@ std::vector> AudioEmitter::generateMusic() { // Chords FMOD::Channel *channelChords = nullptr; int index_chord = chordProgression[i % 4]; - ERRCHECK(system->playSound(chords[index_chord].get(), nullptr, true, + ERRCHECK(system->playSound(chords[index_chord + variation*nbrChords].get(), nullptr, true, &channelChords)); unsigned long long delay = @@ -311,19 +318,23 @@ std::vector> AudioEmitter::generateMusic() { activeChannels.push_back(channelChords); // Mélodie - std::vector rythme_melodie = rythmes[rand() % rythmes.size()]; - for (float time : rythme_melodie) { - FMOD::Channel *channelNote = nullptr; - ERRCHECK(system->playSound(notes[index_note].get(), nullptr, true, - &channelNote)); - float note_start = (i + time / 8.f) * beatDuration; - unsigned long long delayNote = - (unsigned long long)(note_start * sampleRate); - ERRCHECK(channelNote->setDelay(delayNote, 0, true)); - ERRCHECK(channelNote->setPaused(false)); - result.push_back(std::pair(note_start, index_note)); - index_note = nextNote(index_note); - activeChannels.push_back(channelNote); + if (i >= 4) { + int index_rythme = floor(((i - 4) * 1.f / nbr_melo_total) * (rythmes.size() - 1)) + ( rand() % nbr_melo_max ); //Les rythmes deviennent de plus en plus complexe, plus on avance dans le temps, plus le rythme est tiré de la fin du vecteur + index_rythme = (int)fmin(index_rythme, rythmes.size() - 1); + std::vector rythme_melodie = rythmes[index_rythme]; + for (float time : rythme_melodie) { + FMOD::Channel* channelNote = nullptr; + ERRCHECK(system->playSound(notes[index_note].get(), nullptr, true, + &channelNote)); + float note_start = (i + time / 8.f) * beatDuration; + unsigned long long delayNote = + (unsigned long long)(note_start * sampleRate); + ERRCHECK(channelNote->setDelay(delayNote, 0, true)); + ERRCHECK(channelNote->setPaused(false)); + result.push_back(std::pair(note_start, index_note)); + index_note = nextNote(index_note); + activeChannels.push_back(channelNote); + } } } current_beat += nbr_melo_max; From 501f2156cc8a6446440183725fca15cccec6ad26 Mon Sep 17 00:00:00 2001 From: antpoms <148887171+antpoms@users.noreply.github.com> Date: Sat, 14 Jun 2025 22:17:58 +0200 Subject: [PATCH 2/2] random placement --- SimpleGame/src/Source/TilePattern.cpp | 46 +++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/SimpleGame/src/Source/TilePattern.cpp b/SimpleGame/src/Source/TilePattern.cpp index 6556cc2..f989fea 100644 --- a/SimpleGame/src/Source/TilePattern.cpp +++ b/SimpleGame/src/Source/TilePattern.cpp @@ -9,12 +9,54 @@ void generateTilePattern(std::vector> new_notes, const AudioEmitter &audio_emitter) { int i = -1; float beatDuration = 60.f / audio_emitter.tempo; + int previous_note_pitch = 0; + NotePlaceEnum previous_note_placement = static_cast(0); for (auto note : new_notes) { i++; - // if (i % 4 != 0) // skip les 3/4 des notes (je suis trop nul sinon) - // continue; float start_time = note.first; NotePlaceEnum notePlace = static_cast(i % 3); + if (i == 0) { + notePlace = static_cast(rand()%3); + } + else { + if (note.second == previous_note_pitch) { + notePlace = previous_note_placement; + } + else if (note.second < previous_note_pitch) { + if (previous_note_placement == Left) { + notePlace = Left; + } + else if (previous_note_placement == Middle) { + notePlace = Left; + } + else { + if (rand() % 2 == 0) { + notePlace = Left; + } + else { + notePlace = Middle; + } + } + } + else { + if (previous_note_placement == Right) { + notePlace = Right; + } + else if (previous_note_placement == Middle) { + notePlace = Right; + } + else { + if (rand() % 2 == 0) { + notePlace = Right; + } + else { + notePlace = Middle; + } + } + } + } + previous_note_pitch = note.second; + previous_note_placement = notePlace; NoteTile::create(start_time, beatDuration, notePlace, audio_emitter.getTime()); } }