dézo antoine mais tes 7 niveaux d'identation + tes if else partout c'est interdit par la convention de geneve
37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
#include "TilePattern.hpp"
|
|
#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>(1);
|
|
for (auto note : new_notes) {
|
|
|
|
NotePlaceEnum notePlace = getNotePlacement(
|
|
i, note.second, previous_note_pitch, previous_note_placement);
|
|
previous_note_placement = notePlace;
|
|
previous_note_pitch = note.second;
|
|
NoteTile::create(note.first, beatDuration, notePlace,
|
|
audio_emitter.getTime());
|
|
}
|
|
}
|