TilePattern lisible
dézo antoine mais tes 7 niveaux d'identation + tes if else partout c'est interdit par la convention de geneve
This commit is contained in:
parent
40d3358c9d
commit
1a8e68e0b6
1 changed files with 21 additions and 46 deletions
|
@ -2,61 +2,36 @@
|
|||
#include "AudioEmitter.hpp"
|
||||
#include "NoteSprite.hpp"
|
||||
#include "NoteTile.hpp"
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
NotePlaceEnum getNotePlacement(int index, int notePitch, int prevPitch,
|
||||
NotePlaceEnum prevPlacement) {
|
||||
if (index == 0)
|
||||
return Middle;
|
||||
|
||||
int diff_pitch = notePitch - prevPitch;
|
||||
int sign_with_zero = (diff_pitch > 0) - (diff_pitch < 0);
|
||||
int prevPlacementInt = prevPlacement;
|
||||
int newPlacementInt = std::clamp(prevPlacementInt + sign_with_zero, 0, 2);
|
||||
|
||||
return static_cast<NotePlaceEnum>(newPlacementInt);
|
||||
}
|
||||
|
||||
void generateTilePattern(std::vector<std::pair<float, int>> 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<NotePlaceEnum>(0);
|
||||
NotePlaceEnum previous_note_placement = static_cast<NotePlaceEnum>(1);
|
||||
for (auto note : new_notes) {
|
||||
i++;
|
||||
float start_time = note.first;
|
||||
NotePlaceEnum notePlace = static_cast<NotePlaceEnum>(i % 3);
|
||||
if (i == 0) {
|
||||
notePlace = static_cast<NotePlaceEnum>(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;
|
||||
|
||||
NotePlaceEnum notePlace = getNotePlacement(
|
||||
i, note.second, previous_note_pitch, previous_note_placement);
|
||||
previous_note_placement = notePlace;
|
||||
NoteTile::create(start_time, beatDuration, notePlace, audio_emitter.getTime());
|
||||
previous_note_pitch = note.second;
|
||||
NoteTile::create(note.first, beatDuration, notePlace,
|
||||
audio_emitter.getTime());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue