mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2025-02-20 12:31:01 +01:00
Clap sound
SO CLOSE TO 0.1.0 !!!!
This commit is contained in:
parent
cb0e1846d4
commit
8ff199a7f7
@ -52,6 +52,7 @@ void EditorState::reloadMusic() {
|
||||
*/
|
||||
void EditorState::reloadPlaybackPositionAndChartRuntime() {
|
||||
playbackPosition = sf::seconds(-(fumen.offset));
|
||||
previousPos = playbackPosition;
|
||||
if (music) {
|
||||
if (selectedChart) {
|
||||
chartRuntime = sf::seconds(std::max(music->getDuration().asSeconds(),fumen.getChartRuntime(*selectedChart)-fumen.offset)+2.f);
|
||||
@ -113,9 +114,9 @@ void EditorState::displayPlayfield() {
|
||||
float TitlebarHeight = ImGui::GetWindowSize().y - ImGui::GetWindowSize().x;
|
||||
if (selectedChart) {
|
||||
int ImGuiIndex = 0;
|
||||
for (auto note : getVisibleNotes()) {
|
||||
std::optional<sf::Texture> t;
|
||||
if ((t = playfield.marker.getSprite(playfield.markerEndingState,getSecondsAt(note.getTiming())))) {
|
||||
for (auto note : visibleNotes) {
|
||||
std::optional<std::reference_wrapper<sf::Texture>> t = playfield.marker.getSprite(playfield.markerEndingState,playbackPosition.asSeconds()-getSecondsAt(note.getTiming()));
|
||||
if (t) {
|
||||
int x = note.getPos()%4;
|
||||
int y = note.getPos()/4;
|
||||
ImGui::SetCursorPos({x*squareSize,TitlebarHeight + y*squareSize});
|
||||
@ -295,12 +296,11 @@ void EditorState::displayChartList() {
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
void EditorState::updateVisibleNotes() {
|
||||
visibleNotes.clear();
|
||||
|
||||
std::vector<Note> EditorState::getVisibleNotes() {
|
||||
if (selectedChart) {
|
||||
|
||||
std::vector<Note> visibleNotes;
|
||||
|
||||
float minPos;
|
||||
if (this->playfield.markerEndingState == MISS) {
|
||||
minPos = playbackPosition.asSeconds() - 8.f/30.f;
|
||||
@ -318,11 +318,6 @@ std::vector<Note> EditorState::getVisibleNotes() {
|
||||
visibleNotes.push_back(note);
|
||||
}
|
||||
}
|
||||
|
||||
return visibleNotes;
|
||||
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
|
||||
std::optional<sf::Texture> jacket;
|
||||
|
||||
sf::Time previousPos;
|
||||
sf::Time playbackPosition;
|
||||
sf::Time chartRuntime; // sf::Time at which the chart preview stops, can be after the end of the audio
|
||||
|
||||
@ -62,7 +63,8 @@ public:
|
||||
void displayTimeline();
|
||||
void displayChartList();
|
||||
|
||||
std::vector<Note> getVisibleNotes();
|
||||
void updateVisibleNotes();
|
||||
std::vector<Note> visibleNotes;
|
||||
|
||||
explicit EditorState(Fumen& fumen);
|
||||
};
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <c++/8.2.1/functional>
|
||||
#include "Marker.h"
|
||||
|
||||
Marker::Marker(std::string folder) {
|
||||
@ -19,6 +20,7 @@ Marker::Marker(std::string folder) {
|
||||
std::cerr << "Unable to load marker " << folder;
|
||||
throw std::runtime_error("Unable to load marker " + folder);
|
||||
}
|
||||
tex.setSmooth(true);
|
||||
textures.insert({"h" + std::to_string(i+100*sup), tex});
|
||||
}
|
||||
}
|
||||
@ -40,15 +42,17 @@ Marker::Marker(std::string folder) {
|
||||
std::cerr << "Unable to load marker " << folder;
|
||||
throw std::runtime_error("Unable to load marker " + folder);
|
||||
}
|
||||
tex.setSmooth(true);
|
||||
textures.insert({fichier, tex});
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<sf::Texture> Marker::getSprite(MarkerEndingState state, float seconds) {
|
||||
std::optional<std::reference_wrapper<sf::Texture>> Marker::getSprite(MarkerEndingState state, float seconds) {
|
||||
std::ostringstream frameName;
|
||||
int frame = static_cast<int>((seconds*30.f+16.f));
|
||||
if (frame >= 0 and frame <= 15) {
|
||||
frameName << "ma" << std::setfill('0') << std::setw(2) << frame;
|
||||
std::string frameStr = frameName.str();
|
||||
return textures[frameName.str()];
|
||||
} else {
|
||||
if (state == MISS) {
|
||||
|
2
Marker.h
2
Marker.h
@ -24,7 +24,7 @@ class Marker {
|
||||
public:
|
||||
|
||||
Marker(std::string folder = "mk0013");
|
||||
std::optional<sf::Texture> getSprite(MarkerEndingState state, float seconds);
|
||||
std::optional<std::reference_wrapper<sf::Texture>> getSprite(MarkerEndingState state, float seconds);
|
||||
|
||||
private:
|
||||
|
||||
|
2
Note.cpp
2
Note.cpp
@ -5,7 +5,7 @@
|
||||
#include <stdexcept>
|
||||
#include "Note.h"
|
||||
|
||||
Note::Note(int timing, int pos, int length, int trail_pos) {
|
||||
Note::Note(int pos, int timing, int length, int trail_pos) {
|
||||
if (timing<0) {
|
||||
throw std::runtime_error("Tried creating a note with negative timing : "+std::to_string(timing));
|
||||
}
|
||||
|
2
Note.h
2
Note.h
@ -18,7 +18,7 @@ class Note {
|
||||
public:
|
||||
|
||||
|
||||
Note(int timing,int pos,int length,int trail_pos);
|
||||
Note(int pos, int timing, int length, int trail_pos);
|
||||
static bool trail_pos_correct(int pos,int trail_pos);
|
||||
|
||||
bool operator==(const Note &rhs) const;
|
||||
|
96
main.cpp
96
main.cpp
@ -9,14 +9,14 @@
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// TODO : Affichage des notes
|
||||
// TODO : Edition des notes à la souris (mode suppression / mode ajout)
|
||||
// TODO : Marker selection
|
||||
// TODO : Marker ending selection
|
||||
// TODO : Bruit des notes ticks
|
||||
// TODO : Volume des notes ticks
|
||||
// TODO : Bruit différent si clap simple ou chord
|
||||
// TODO : Undo / Redo
|
||||
// TODO : Density graph sur la timeline
|
||||
// TODO : Système de notifs
|
||||
// TODO : Undo / Redo
|
||||
// TODO : Pitch control (playback speed factor)
|
||||
|
||||
// Création de la fenêtre
|
||||
@ -41,8 +41,8 @@ int main(int argc, char** argv) {
|
||||
sf::Sound noteTickSound(noteTick);
|
||||
int noteTickVolume = 10;
|
||||
bool playNoteTick = false;
|
||||
bool noteTicked = false;
|
||||
|
||||
bool beatTicked = false;
|
||||
std::string beatTickPath = "assets/sounds/sound beat tick.wav";
|
||||
sf::SoundBuffer beatTick;
|
||||
if (!beatTick.loadFromFile(beatTickPath)) {
|
||||
@ -52,6 +52,7 @@ int main(int argc, char** argv) {
|
||||
sf::Sound beatTickSound(beatTick);
|
||||
int beatTickVolume = 10;
|
||||
bool playBeatTick = false;
|
||||
bool beatTicked = false;
|
||||
|
||||
|
||||
Widgets::Ecran_attente bg;
|
||||
@ -164,44 +165,63 @@ int main(int argc, char** argv) {
|
||||
|
||||
sf::Time delta = deltaClock.restart();
|
||||
ImGui::SFML::Update(window, delta);
|
||||
editorState->updateVisibleNotes();
|
||||
|
||||
// Gestion du playback
|
||||
if (editorState->playing) {
|
||||
editorState->playbackPosition += delta;
|
||||
if (editorState->music) {
|
||||
switch(editorState->music->getStatus()) {
|
||||
case sf::Music::Stopped:
|
||||
case sf::Music::Paused:
|
||||
if (editorState->playbackPosition.asSeconds() >= 0 and editorState->playbackPosition < editorState->music->getDuration()) {
|
||||
editorState->music->setPlayingOffset(editorState->playbackPosition);
|
||||
editorState->music->play();
|
||||
}
|
||||
break;
|
||||
case sf::Music::Playing:
|
||||
editorState->playbackPosition = editorState->music->getPlayingOffset();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (playBeatTick) {
|
||||
if (fmodf(editorState->getBeats(),1.f) < 0.5) {
|
||||
if (not beatTicked) {
|
||||
beatTickSound.play();
|
||||
beatTicked = true;
|
||||
if (editorState) {
|
||||
if (editorState->playing) {
|
||||
editorState->previousPos = editorState->playbackPosition;
|
||||
editorState->playbackPosition += delta;
|
||||
if (editorState->music) {
|
||||
switch(editorState->music->getStatus()) {
|
||||
case sf::Music::Stopped:
|
||||
case sf::Music::Paused:
|
||||
if (editorState->playbackPosition.asSeconds() >= 0 and editorState->playbackPosition < editorState->music->getDuration()) {
|
||||
editorState->music->setPlayingOffset(editorState->playbackPosition);
|
||||
editorState->music->play();
|
||||
}
|
||||
break;
|
||||
case sf::Music::Playing:
|
||||
editorState->playbackPosition = editorState->music->getPlayingOffset();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
beatTicked = false;
|
||||
}
|
||||
}
|
||||
if (editorState->playbackPosition >= editorState->chartRuntime) {
|
||||
editorState->playing = false;
|
||||
editorState->playbackPosition = editorState->chartRuntime;
|
||||
}
|
||||
} else {
|
||||
if (editorState->music) {
|
||||
if (editorState->music->getStatus() == sf::Music::Playing) {
|
||||
editorState->music->pause();
|
||||
if (playBeatTick) {
|
||||
if (fmodf(editorState->getBeats(),1.f) < 0.5) {
|
||||
if (not beatTicked) {
|
||||
beatTickSound.play();
|
||||
beatTicked = true;
|
||||
}
|
||||
} else {
|
||||
beatTicked = false;
|
||||
}
|
||||
}
|
||||
if (playNoteTick) {
|
||||
int currentTick = static_cast<int>(editorState->getTicks());
|
||||
for (auto note : editorState->visibleNotes) {
|
||||
float noteTiming = editorState->getSecondsAt(note.getTiming());
|
||||
if (noteTiming >= editorState->previousPos.asSeconds() and noteTiming <= editorState->playbackPosition.asSeconds()) {
|
||||
if (not noteTicked) {
|
||||
noteTickSound.play();
|
||||
noteTicked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noteTicked) {
|
||||
noteTicked = false;
|
||||
}
|
||||
}
|
||||
if (editorState->playbackPosition >= editorState->chartRuntime) {
|
||||
editorState->playing = false;
|
||||
editorState->playbackPosition = editorState->chartRuntime;
|
||||
}
|
||||
} else {
|
||||
if (editorState->music) {
|
||||
if (editorState->music->getStatus() == sf::Music::Playing) {
|
||||
editorState->music->pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user