2017-08-17 19:10:53 +02:00
|
|
|
#include <SFML/Graphics.hpp>
|
2019-01-02 23:38:47 +01:00
|
|
|
#include <imgui.h>
|
|
|
|
#include <imgui-SFML.h>
|
2019-01-03 23:20:35 +01:00
|
|
|
#include <imgui_stdlib.h>
|
2019-03-27 20:37:30 +01:00
|
|
|
#include <variant>
|
2019-01-13 22:29:29 +01:00
|
|
|
#include "Widgets.h"
|
2019-01-02 23:38:47 +01:00
|
|
|
#include "EditorState.h"
|
2019-01-03 23:20:35 +01:00
|
|
|
#include "tinyfiledialogs.h"
|
2019-01-13 03:53:42 +01:00
|
|
|
#include "Toolbox.h"
|
2019-03-02 16:06:33 +01:00
|
|
|
#include "NotificationsQueue.h"
|
2019-03-24 22:57:02 +01:00
|
|
|
#include "SoundEffect.h"
|
2019-03-27 20:37:30 +01:00
|
|
|
#include "TimeSelection.h"
|
2019-03-28 02:16:29 +01:00
|
|
|
#include "Preferences.h"
|
2017-08-17 19:10:53 +02:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
2019-03-27 20:37:30 +01:00
|
|
|
// TODO : Rewrite the terrible LNMarker stuff
|
2019-01-16 01:59:02 +01:00
|
|
|
|
2019-01-16 19:12:01 +01:00
|
|
|
// Création de la fenêtre
|
|
|
|
sf::RenderWindow window(sf::VideoMode(800, 600), "FEIS");
|
|
|
|
sf::RenderWindow & ref_window = window;
|
|
|
|
window.setVerticalSyncEnabled(true);
|
|
|
|
window.setFramerateLimit(60);
|
2019-01-12 17:16:20 +01:00
|
|
|
|
|
|
|
ImGui::SFML::Init(window, false);
|
|
|
|
|
|
|
|
ImGuiIO& IO = ImGui::GetIO();
|
|
|
|
IO.Fonts->Clear();
|
|
|
|
IO.Fonts->AddFontFromFileTTF("assets/fonts/NotoSans-Medium.ttf", 16.f);
|
|
|
|
ImGui::SFML::UpdateFontTexture();
|
|
|
|
|
2019-03-24 22:57:02 +01:00
|
|
|
SoundEffect beatTick("sound beat tick.wav");
|
|
|
|
SoundEffect noteTick("sound note tick.wav");
|
|
|
|
SoundEffect chordTick("sound chord tick.wav");
|
2019-01-14 21:43:56 +01:00
|
|
|
|
2019-01-17 15:37:15 +01:00
|
|
|
// Loading markers preview
|
2019-01-18 01:55:41 +01:00
|
|
|
std::map<std::filesystem::path,sf::Texture> markerPreviews;
|
2019-01-17 15:37:15 +01:00
|
|
|
for (const auto& folder : std::filesystem::directory_iterator("assets/textures/markers")) {
|
|
|
|
if (folder.is_directory()) {
|
2019-01-19 17:12:41 +01:00
|
|
|
sf::Texture markerPreview;
|
|
|
|
markerPreview.loadFromFile((folder/"ma15.png").string());
|
|
|
|
markerPreview.setSmooth(true);
|
|
|
|
markerPreviews.insert({folder,markerPreview});
|
2019-01-17 15:37:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 02:16:29 +01:00
|
|
|
Preferences preferences;
|
|
|
|
|
|
|
|
Marker defaultMarker = Marker(preferences.marker);
|
2019-01-17 15:37:15 +01:00
|
|
|
Marker& marker = defaultMarker;
|
2019-03-28 02:16:29 +01:00
|
|
|
MarkerEndingState markerEndingState = preferences.markerEndingState;
|
2019-01-17 15:37:15 +01:00
|
|
|
|
2019-03-27 20:37:30 +01:00
|
|
|
Widgets::BlankScreen bg;
|
2019-01-16 19:12:01 +01:00
|
|
|
std::optional<EditorState> editorState;
|
2019-03-02 16:06:33 +01:00
|
|
|
NotificationsQueue notificationsQueue;
|
2019-01-16 19:12:01 +01:00
|
|
|
ESHelper::NewChartDialog newChartDialog;
|
|
|
|
ESHelper::ChartPropertiesDialog chartPropertiesDialog;
|
2019-01-02 23:38:47 +01:00
|
|
|
|
2019-01-16 19:12:01 +01:00
|
|
|
sf::Clock deltaClock;
|
|
|
|
while (window.isOpen()) {
|
|
|
|
sf::Event event;
|
|
|
|
while (window.pollEvent(event)) {
|
|
|
|
ImGui::SFML::ProcessEvent(event);
|
2019-01-02 23:38:47 +01:00
|
|
|
|
2019-01-16 19:12:01 +01:00
|
|
|
switch (event.type) {
|
|
|
|
case sf::Event::Closed:
|
2019-03-28 02:16:29 +01:00
|
|
|
preferences.save();
|
|
|
|
if (editorState) {
|
2019-03-28 10:07:19 +01:00
|
|
|
switch (editorState->alertSaveChanges()) {
|
|
|
|
case saveChangesYes:
|
|
|
|
ESHelper::save(*editorState);
|
|
|
|
case saveChangesNo:
|
|
|
|
case saveChangesDidNotDisplayDialog:
|
|
|
|
window.close();
|
|
|
|
case saveChangesCancel:
|
|
|
|
break;
|
|
|
|
}
|
2019-03-28 02:16:29 +01:00
|
|
|
} else {
|
|
|
|
window.close();
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
break;
|
|
|
|
case sf::Event::Resized:
|
2019-01-12 03:13:30 +01:00
|
|
|
window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
|
2019-01-16 19:12:01 +01:00
|
|
|
break;
|
2019-03-28 02:16:29 +01:00
|
|
|
case sf::Event::MouseButtonPressed:
|
|
|
|
switch (event.mouseButton.button) {
|
|
|
|
case sf::Mouse::Button::Right:
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
editorState->chart->creatingLongNote = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Event::MouseButtonReleased:
|
|
|
|
switch (event.mouseButton.button) {
|
|
|
|
case sf::Mouse::Button::Right:
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
if (editorState->chart->longNoteBeingCreated) {
|
|
|
|
auto pair = *editorState->chart->longNoteBeingCreated;
|
|
|
|
Note new_note = Note(pair.first,pair.second);
|
|
|
|
std::set<Note> new_note_set = {new_note};
|
|
|
|
editorState->chart->ref.Notes.insert(new_note);
|
|
|
|
editorState->chart->longNoteBeingCreated.reset();
|
|
|
|
editorState->chart->creatingLongNote = false;
|
|
|
|
editorState->chart->history.push(std::make_shared<ToggledNotes>(new_note_set, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-01-16 19:12:01 +01:00
|
|
|
case sf::Event::KeyPressed:
|
|
|
|
switch (event.key.code) {
|
2019-03-27 20:37:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Selection related stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Discard, in that order : timeSelection, selected_notes
|
|
|
|
case sf::Keyboard::Escape:
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
if (not std::holds_alternative<std::monostate>(editorState->chart->timeSelection)) {
|
|
|
|
editorState->chart->timeSelection.emplace<std::monostate>();
|
|
|
|
} else if (not editorState->chart->selectedNotes.empty()) {
|
|
|
|
editorState->chart->selectedNotes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Modify timeSelection
|
|
|
|
case sf::Keyboard::Tab:
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
|
|
|
|
// if no timeSelection was previously made
|
|
|
|
if (std::holds_alternative<std::monostate>(editorState->chart->timeSelection)) {
|
|
|
|
|
|
|
|
// set the start of the timeSelection to the current time
|
2019-03-28 02:16:29 +01:00
|
|
|
editorState->chart->timeSelection = static_cast<unsigned int>(editorState->getCurrentTick());
|
2019-03-27 20:37:30 +01:00
|
|
|
|
|
|
|
// if the start of the timeSelection is already set
|
|
|
|
} else if (std::holds_alternative<unsigned int>(editorState->chart->timeSelection)) {
|
|
|
|
|
2019-03-28 02:16:29 +01:00
|
|
|
auto current_tick = static_cast<int>(editorState->getCurrentTick());
|
2019-03-27 20:37:30 +01:00
|
|
|
auto selection_start = static_cast<int>(std::get<unsigned int>(editorState->chart->timeSelection));
|
|
|
|
|
|
|
|
// if we are on the same tick as the timeSelection start we discard the timeSelection
|
|
|
|
if (current_tick == selection_start) {
|
|
|
|
editorState->chart->timeSelection.emplace<std::monostate>();
|
|
|
|
|
|
|
|
// else we create a full timeSelection while paying attention to the order
|
|
|
|
} else {
|
|
|
|
auto new_selection_start = static_cast<unsigned int>(std::min(current_tick, selection_start));
|
|
|
|
auto duration = static_cast<unsigned int>(std::abs(current_tick - selection_start));
|
|
|
|
editorState->chart->timeSelection.emplace<TimeSelection>(new_selection_start,duration);
|
|
|
|
editorState->chart->selectedNotes = editorState->chart->ref.getNotesBetween(new_selection_start, new_selection_start+duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if a full timeSelection already exists
|
|
|
|
} else if (std::holds_alternative<TimeSelection>(editorState->chart->timeSelection)) {
|
|
|
|
// discard the current timeSelection and set the start of the timeSelection to the current time
|
2019-03-28 02:16:29 +01:00
|
|
|
editorState->chart->timeSelection = static_cast<unsigned int>(editorState->getCurrentTick());
|
2019-03-27 20:37:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Delete selected notes from the chart and discard timeSelection
|
|
|
|
case sf::Keyboard::Delete:
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
if (not editorState->chart->selectedNotes.empty()) {
|
|
|
|
editorState->chart->history.push(std::make_shared<ToggledNotes>(editorState->chart->selectedNotes,false));
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Deleted selected notes"));
|
|
|
|
for (auto note : editorState->chart->selectedNotes) {
|
|
|
|
editorState->chart->ref.Notes.erase(note);
|
|
|
|
}
|
|
|
|
editorState->chart->selectedNotes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arrow keys
|
|
|
|
*/
|
2019-01-17 01:08:38 +01:00
|
|
|
case sf::Keyboard::Up:
|
|
|
|
if (event.key.shift) {
|
|
|
|
if (editorState) {
|
2019-03-24 23:19:06 +01:00
|
|
|
editorState->musicVolumeUp();
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Music Volume : " << editorState->musicVolume*10 << "%";
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
2019-01-17 01:08:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-24 21:51:33 +01:00
|
|
|
// TODO : there is something weird with the way I'm doing this, going back with the key often makes it go back twice
|
2019-03-02 13:47:26 +01:00
|
|
|
if (editorState and editorState->chart) {
|
2019-03-28 02:16:29 +01:00
|
|
|
float floatTicks = editorState->getCurrentTick();
|
2019-01-17 01:08:38 +01:00
|
|
|
int prevTick = static_cast<int>(floorf(floatTicks));
|
|
|
|
int step = editorState->getSnapStep();
|
|
|
|
int prevTickInSnap = prevTick;
|
|
|
|
if (prevTick%step == 0) {
|
|
|
|
prevTickInSnap -= step;
|
|
|
|
} else {
|
|
|
|
prevTickInSnap -= prevTick%step;
|
|
|
|
}
|
|
|
|
editorState->setPlaybackAndMusicPosition(sf::seconds(editorState->getSecondsAt(prevTickInSnap)));
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-01-17 01:08:38 +01:00
|
|
|
case sf::Keyboard::Down:
|
|
|
|
if (event.key.shift) {
|
|
|
|
if (editorState) {
|
2019-03-24 23:19:06 +01:00
|
|
|
editorState->musicVolumeDown();
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Music Volume : " << editorState->musicVolume*10 << "%";
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
2019-01-17 01:08:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-02 13:47:26 +01:00
|
|
|
if (editorState and editorState->chart) {
|
2019-03-28 02:16:29 +01:00
|
|
|
float floatTicks = editorState->getCurrentTick();
|
2019-01-17 01:08:38 +01:00
|
|
|
int nextTick = static_cast<int>(ceilf(floatTicks));
|
|
|
|
int step = editorState->getSnapStep();
|
|
|
|
int nextTickInSnap = nextTick + (step - nextTick%step);
|
|
|
|
editorState->setPlaybackAndMusicPosition(sf::seconds(editorState->getSecondsAt(nextTickInSnap)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::Left:
|
2019-03-24 23:19:06 +01:00
|
|
|
if (event.key.shift) {
|
|
|
|
if (editorState) {
|
|
|
|
editorState->musicSpeedDown();
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Speed : " << editorState->musicSpeed*10 << "%";
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
editorState->snap = Toolbox::getPreviousDivisor(
|
|
|
|
editorState->chart->ref.getResolution(), editorState->snap);
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Snap : " << Toolbox::toOrdinal(4 * editorState->snap);
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
|
|
|
}
|
2019-01-17 01:08:38 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::Right:
|
2019-03-24 23:19:06 +01:00
|
|
|
if (event.key.shift) {
|
|
|
|
editorState->musicSpeedUp();
|
2019-03-24 21:51:33 +01:00
|
|
|
std::stringstream ss;
|
2019-03-24 23:19:06 +01:00
|
|
|
ss << "Speed : " << editorState->musicSpeed*10 << "%";
|
2019-03-24 21:51:33 +01:00
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
2019-03-24 23:19:06 +01:00
|
|
|
} else {
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
editorState->snap = Toolbox::getNextDivisor(editorState->chart->ref.getResolution(),editorState->snap);
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Snap : " << Toolbox::toOrdinal(4*editorState->snap);
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-03-27 20:37:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* F keys
|
|
|
|
*/
|
2019-01-17 01:08:38 +01:00
|
|
|
case sf::Keyboard::F3:
|
2019-03-24 22:57:02 +01:00
|
|
|
if (beatTick.toggle()) {
|
2019-03-24 21:51:33 +01:00
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Beat tick : on"));
|
2019-03-02 16:06:33 +01:00
|
|
|
} else {
|
2019-03-24 21:51:33 +01:00
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Beat tick : off"));
|
2019-03-02 16:06:33 +01:00
|
|
|
}
|
2019-01-17 01:08:38 +01:00
|
|
|
break;
|
|
|
|
case sf::Keyboard::F4:
|
2019-03-25 19:16:45 +01:00
|
|
|
if (event.key.shift) {
|
|
|
|
if (chordTick.toggle()) {
|
|
|
|
noteTick.shouldPlay = true;
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Note+Chord tick : on"));
|
|
|
|
} else {
|
|
|
|
noteTick.shouldPlay = false;
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Note+Chord tick : off"));
|
|
|
|
}
|
2019-03-02 16:06:33 +01:00
|
|
|
} else {
|
2019-03-25 19:16:45 +01:00
|
|
|
if (noteTick.toggle()) {
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Note tick : on"));
|
|
|
|
} else {
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Note tick : off"));
|
|
|
|
}
|
2019-03-02 16:06:33 +01:00
|
|
|
}
|
2019-01-17 01:08:38 +01:00
|
|
|
break;
|
2019-01-16 19:12:01 +01:00
|
|
|
case sf::Keyboard::Space:
|
|
|
|
if (not ImGui::GetIO().WantTextInput) {
|
|
|
|
if (editorState) {
|
|
|
|
editorState->playing = not editorState->playing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-03-26 00:04:29 +01:00
|
|
|
case sf::Keyboard::Add:
|
|
|
|
if (editorState) {
|
|
|
|
editorState->linearView.zoom_in();
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Zoom in"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::Subtract:
|
|
|
|
if (editorState) {
|
|
|
|
editorState->linearView.zoom_out();
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Zoom out"));
|
|
|
|
}
|
|
|
|
break;
|
2019-03-27 20:37:30 +01:00
|
|
|
/*
|
|
|
|
* Letter keys, in alphabetical order
|
|
|
|
*/
|
|
|
|
case sf::Keyboard::C:
|
|
|
|
if (event.key.control) {
|
|
|
|
if (editorState and editorState->chart and (not editorState->chart->selectedNotes.empty())) {
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Copied " << editorState->chart->selectedNotes.size() << " note";
|
|
|
|
if (editorState->chart->selectedNotes.size() > 1) {
|
|
|
|
ss << "s";
|
|
|
|
}
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
|
|
|
|
|
|
|
editorState->chart->notesClipboard.copy(editorState->chart->selectedNotes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-01-16 22:10:20 +01:00
|
|
|
case sf::Keyboard::O:
|
|
|
|
if (event.key.control) {
|
|
|
|
ESHelper::open(editorState);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::P:
|
|
|
|
if (event.key.shift) {
|
|
|
|
editorState->showProperties = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::S:
|
|
|
|
if (event.key.control) {
|
|
|
|
ESHelper::save(*editorState);
|
2019-03-24 21:51:33 +01:00
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>("Saved file"));
|
2019-01-16 22:10:20 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-03-27 20:37:30 +01:00
|
|
|
case sf::Keyboard::V:
|
|
|
|
if (event.key.control) {
|
|
|
|
if (editorState and editorState->chart and (not editorState->chart->notesClipboard.empty())) {
|
|
|
|
|
2019-03-28 02:16:29 +01:00
|
|
|
int tick_offset = static_cast<int>(editorState->getCurrentTick());
|
2019-03-27 20:37:30 +01:00
|
|
|
std::set<Note> pasted_notes = editorState->chart->notesClipboard.paste(tick_offset);
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Pasted " << pasted_notes.size() << " note";
|
|
|
|
if (pasted_notes.size() > 1) {
|
|
|
|
ss << "s";
|
|
|
|
}
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
|
|
|
|
|
|
|
for (auto note : pasted_notes) {
|
|
|
|
editorState->chart->ref.Notes.insert(note);
|
|
|
|
}
|
|
|
|
editorState->chart->selectedNotes = pasted_notes;
|
|
|
|
editorState->chart->history.push(std::make_shared<ToggledNotes>(editorState->chart->selectedNotes,true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::X:
|
|
|
|
if (event.key.control) {
|
|
|
|
if (editorState and editorState->chart and (not editorState->chart->selectedNotes.empty())) {
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Cut " << editorState->chart->selectedNotes.size() << " note";
|
|
|
|
if (editorState->chart->selectedNotes.size() > 1) {
|
|
|
|
ss << "s";
|
|
|
|
}
|
|
|
|
notificationsQueue.push(std::make_shared<TextNotification>(ss.str()));
|
|
|
|
|
|
|
|
editorState->chart->notesClipboard.copy(editorState->chart->selectedNotes);
|
|
|
|
for (auto note : editorState->chart->selectedNotes) {
|
|
|
|
editorState->chart->ref.Notes.erase(note);
|
|
|
|
}
|
|
|
|
editorState->chart->history.push(std::make_shared<ToggledNotes>(editorState->chart->selectedNotes,false));
|
|
|
|
editorState->chart->selectedNotes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-03-02 13:47:26 +01:00
|
|
|
case sf::Keyboard::Y:
|
|
|
|
if (event.key.control) {
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
auto next = editorState->chart->history.get_next();
|
|
|
|
if (next) {
|
2019-03-02 16:12:57 +01:00
|
|
|
notificationsQueue.push(std::make_shared<RedoNotification>(**next));
|
2019-03-02 13:47:26 +01:00
|
|
|
(*next)->doAction(*editorState);
|
2019-03-25 19:16:45 +01:00
|
|
|
editorState->densityGraph.should_recompute = true;
|
2019-03-02 13:47:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Keyboard::Z:
|
|
|
|
if (event.key.control) {
|
|
|
|
if (editorState and editorState->chart) {
|
|
|
|
auto previous = editorState->chart->history.get_previous();
|
|
|
|
if (previous) {
|
2019-03-02 16:12:57 +01:00
|
|
|
notificationsQueue.push(std::make_shared<UndoNotification>(**previous));
|
2019-03-02 13:47:26 +01:00
|
|
|
(*previous)->undoAction(*editorState);
|
2019-03-25 19:16:45 +01:00
|
|
|
editorState->densityGraph.should_recompute = true;
|
2019-03-02 13:47:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-01-16 22:10:20 +01:00
|
|
|
default:
|
|
|
|
break;
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-01-16 22:10:20 +01:00
|
|
|
default:
|
|
|
|
break;
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-14 21:43:56 +01:00
|
|
|
|
2019-01-14 04:20:30 +01:00
|
|
|
sf::Time delta = deltaClock.restart();
|
2019-01-16 19:12:01 +01:00
|
|
|
ImGui::SFML::Update(window, delta);
|
|
|
|
|
2019-02-13 00:52:52 +01:00
|
|
|
// Audio playback management
|
2019-01-17 03:02:37 +01:00
|
|
|
if (editorState) {
|
2019-01-18 01:25:29 +01:00
|
|
|
editorState->updateVisibleNotes();
|
2019-01-17 03:02:37 +01:00
|
|
|
if (editorState->playing) {
|
|
|
|
editorState->previousPos = editorState->playbackPosition;
|
2019-03-24 23:19:06 +01:00
|
|
|
editorState->playbackPosition += delta*(editorState->musicSpeed/10.f);
|
2019-01-17 03:02:37 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 22:57:02 +01:00
|
|
|
if (beatTick.shouldPlay) {
|
|
|
|
int previous_tick = static_cast<int>(editorState->getTicksAt(editorState->previousPos.asSeconds()));
|
|
|
|
int current_tick = static_cast<int>(editorState->getTicksAt(editorState->playbackPosition.asSeconds()));
|
|
|
|
if (previous_tick/editorState->getResolution() != current_tick/editorState->getResolution()) {
|
|
|
|
beatTick.play();
|
2019-01-17 03:02:37 +01:00
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
2019-03-24 22:57:02 +01:00
|
|
|
if (noteTick.shouldPlay) {
|
|
|
|
int note_count = 0;
|
2019-01-17 03:02:37 +01:00
|
|
|
for (auto note : editorState->visibleNotes) {
|
|
|
|
float noteTiming = editorState->getSecondsAt(note.getTiming());
|
2019-02-09 06:26:57 +01:00
|
|
|
if (noteTiming >= editorState->previousPos.asSeconds()
|
2019-03-24 21:51:33 +01:00
|
|
|
and noteTiming <= editorState->playbackPosition.asSeconds()) {
|
2019-03-24 22:57:02 +01:00
|
|
|
note_count++;
|
2019-01-17 03:02:37 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-24 22:57:02 +01:00
|
|
|
if (chordTick.shouldPlay) {
|
|
|
|
if (note_count > 1) {
|
|
|
|
chordTick.play();
|
|
|
|
} else if (note_count == 1) {
|
|
|
|
noteTick.play();
|
|
|
|
}
|
|
|
|
} else if (note_count >= 1) {
|
|
|
|
noteTick.play();
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
2019-03-24 22:57:02 +01:00
|
|
|
|
2019-03-25 19:16:45 +01:00
|
|
|
if (editorState->playbackPosition >= editorState->previewEnd) {
|
2019-01-17 03:02:37 +01:00
|
|
|
editorState->playing = false;
|
2019-03-25 19:16:45 +01:00
|
|
|
editorState->playbackPosition = editorState->previewEnd;
|
2019-01-17 03:02:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (editorState->music) {
|
|
|
|
if (editorState->music->getStatus() == sf::Music::Playing) {
|
|
|
|
editorState->music->pause();
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 13:47:26 +01:00
|
|
|
// Drawing
|
2019-01-16 19:12:01 +01:00
|
|
|
if (editorState) {
|
2019-01-14 21:43:56 +01:00
|
|
|
|
2019-01-16 19:12:01 +01:00
|
|
|
window.clear(sf::Color(0, 0, 0));
|
2019-01-03 23:20:35 +01:00
|
|
|
|
2019-03-02 13:47:26 +01:00
|
|
|
if (editorState->showHistory) {
|
|
|
|
editorState->chart->history.display(print_history_message);
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
if (editorState->showPlayfield) {
|
2019-01-17 15:37:15 +01:00
|
|
|
editorState->displayPlayfield(marker,markerEndingState);
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
2019-03-26 00:04:29 +01:00
|
|
|
if (editorState->showLinearView) {
|
|
|
|
editorState->displayLinearView();
|
|
|
|
}
|
2019-03-27 20:37:30 +01:00
|
|
|
if (editorState->linearView.shouldDisplaySettings) {
|
|
|
|
editorState->linearView.displaySettings();
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
if (editorState->showProperties) {
|
|
|
|
editorState->displayProperties();
|
|
|
|
}
|
|
|
|
if (editorState->showStatus) {
|
|
|
|
editorState->displayStatus();
|
|
|
|
}
|
2019-01-12 17:16:20 +01:00
|
|
|
if (editorState->showPlaybackStatus) {
|
|
|
|
editorState->displayPlaybackStatus();
|
|
|
|
}
|
2019-01-13 03:53:42 +01:00
|
|
|
if (editorState->showTimeline) {
|
|
|
|
editorState->displayTimeline();
|
2019-01-16 01:59:02 +01:00
|
|
|
}
|
|
|
|
if (editorState->showChartList) {
|
2019-01-16 19:12:01 +01:00
|
|
|
editorState->displayChartList();
|
2019-01-16 01:59:02 +01:00
|
|
|
}
|
|
|
|
if (editorState->showNewChartDialog) {
|
2019-01-16 19:12:01 +01:00
|
|
|
std::optional<Chart> c = newChartDialog.display(*editorState);
|
|
|
|
if (c) {
|
|
|
|
editorState->showNewChartDialog = false;
|
2019-01-17 01:08:38 +01:00
|
|
|
if(editorState->fumen.Charts.try_emplace(c->dif_name,*c).second) {
|
2019-03-24 21:51:33 +01:00
|
|
|
editorState->chart.emplace(editorState->fumen.Charts.at(c->dif_name));
|
2019-01-17 01:08:38 +01:00
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
2019-01-16 01:59:02 +01:00
|
|
|
} else {
|
2019-01-16 19:12:01 +01:00
|
|
|
newChartDialog.resetValues();
|
2019-01-13 03:53:42 +01:00
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
if (editorState->showChartProperties) {
|
|
|
|
chartPropertiesDialog.display(*editorState);
|
|
|
|
} else {
|
|
|
|
chartPropertiesDialog.shouldRefreshValues = true;
|
|
|
|
}
|
2019-03-25 19:16:45 +01:00
|
|
|
|
|
|
|
if (editorState->showSoundSettings) {
|
|
|
|
ImGui::Begin("Sound Settings",&editorState->showSoundSettings,ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
{
|
|
|
|
if (ImGui::TreeNode("Beat Tick")) {
|
|
|
|
beatTick.displayControls();
|
|
|
|
ImGui::TreePop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("Note Tick")) {
|
|
|
|
noteTick.displayControls();
|
|
|
|
ImGui::Checkbox("Chord sound",&chordTick.shouldPlay);
|
|
|
|
ImGui::TreePop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2019-01-16 19:12:01 +01:00
|
|
|
} else {
|
|
|
|
bg.render(window);
|
|
|
|
}
|
2019-01-02 23:38:47 +01:00
|
|
|
|
2019-03-02 16:06:33 +01:00
|
|
|
notificationsQueue.display();
|
|
|
|
|
|
|
|
// Main Menu bar drawing
|
2019-01-16 19:12:01 +01:00
|
|
|
ImGui::BeginMainMenuBar();
|
|
|
|
{
|
2019-01-02 23:38:47 +01:00
|
|
|
if (ImGui::BeginMenu("File")) {
|
2019-01-03 23:20:35 +01:00
|
|
|
if (ImGui::MenuItem("New")) {
|
2019-01-12 03:13:30 +01:00
|
|
|
const char* _filepath = tinyfd_saveFileDialog("New File",nullptr,0,nullptr,nullptr);
|
2019-01-05 00:07:52 +01:00
|
|
|
if (_filepath != nullptr) {
|
2019-01-12 03:13:30 +01:00
|
|
|
std::filesystem::path filepath(_filepath);
|
2019-01-05 00:07:52 +01:00
|
|
|
try {
|
2019-01-12 03:13:30 +01:00
|
|
|
Fumen f(filepath);
|
|
|
|
f.autoSaveAsMemon();
|
2019-01-05 00:07:52 +01:00
|
|
|
editorState.emplace(f);
|
2019-01-13 03:53:42 +01:00
|
|
|
Toolbox::pushNewRecentFile(std::filesystem::canonical(editorState->fumen.path));
|
2019-01-05 00:07:52 +01:00
|
|
|
} catch (const std::exception& e) {
|
|
|
|
tinyfd_messageBox("Error",e.what(),"ok","error",1);
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 23:20:35 +01:00
|
|
|
}
|
|
|
|
ImGui::Separator();
|
2019-01-16 19:12:01 +01:00
|
|
|
if (ImGui::MenuItem("Open","Ctrl+O")) {
|
2019-01-13 22:29:29 +01:00
|
|
|
ESHelper::open(editorState);
|
2019-01-03 23:20:35 +01:00
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
if (ImGui::BeginMenu("Recent Files")) {
|
|
|
|
int i = 0;
|
|
|
|
for (const auto& file : Toolbox::getRecentFiles()) {
|
2019-01-13 03:53:42 +01:00
|
|
|
ImGui::PushID(i);
|
|
|
|
if (ImGui::MenuItem(file.c_str())) {
|
2019-03-28 02:16:29 +01:00
|
|
|
if (editorState) {
|
2019-03-28 10:07:19 +01:00
|
|
|
switch(editorState->alertSaveChanges()) {
|
|
|
|
case saveChangesYes:
|
|
|
|
ESHelper::save(*editorState);
|
|
|
|
case saveChangesNo:
|
|
|
|
case saveChangesDidNotDisplayDialog:
|
|
|
|
ESHelper::openFromFile(editorState,file);
|
|
|
|
case saveChangesCancel:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ESHelper::openFromFile(editorState,file);
|
2019-03-28 02:16:29 +01:00
|
|
|
}
|
2019-01-13 03:53:42 +01:00
|
|
|
}
|
2019-01-03 23:20:35 +01:00
|
|
|
ImGui::PopID();
|
2019-01-13 03:53:42 +01:00
|
|
|
++i;
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
if (ImGui::MenuItem("Close","",false,editorState.has_value())) {
|
|
|
|
editorState.reset();
|
|
|
|
}
|
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::MenuItem("Save","Ctrl+S",false,editorState.has_value())) {
|
2019-01-13 22:29:29 +01:00
|
|
|
ESHelper::save(*editorState);
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
if (ImGui::MenuItem("Save As","",false,editorState.has_value())) {
|
2019-01-03 23:20:35 +01:00
|
|
|
char const * options[1] = {"*.memon"};
|
|
|
|
const char* _filepath(tinyfd_saveFileDialog("Save File",nullptr,1,options,nullptr));
|
|
|
|
if (_filepath != nullptr) {
|
2019-01-12 03:13:30 +01:00
|
|
|
std::filesystem::path filepath(_filepath);
|
2019-01-05 00:07:52 +01:00
|
|
|
try {
|
|
|
|
editorState->fumen.saveAsMemon(filepath);
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
tinyfd_messageBox("Error",e.what(),"ok","error",1);
|
|
|
|
}
|
2019-01-03 23:20:35 +01:00
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
2019-01-13 22:29:29 +01:00
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::MenuItem("Properties","Shift+P",false,editorState.has_value())) {
|
|
|
|
editorState->showProperties = true;
|
|
|
|
}
|
2019-01-16 19:12:01 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2019-01-03 23:20:35 +01:00
|
|
|
if (ImGui::BeginMenu("Edit")) {
|
2019-01-12 03:13:30 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2019-01-16 01:59:02 +01:00
|
|
|
if (ImGui::BeginMenu("Chart",editorState.has_value())) {
|
2019-01-16 19:12:01 +01:00
|
|
|
if (ImGui::MenuItem("Chart List")) {
|
|
|
|
editorState->showChartList = true;
|
|
|
|
}
|
2019-03-02 13:47:26 +01:00
|
|
|
if (ImGui::MenuItem("Properties##Chart",nullptr,false,editorState->chart.has_value())) {
|
2019-01-16 19:12:01 +01:00
|
|
|
editorState->showChartProperties = true;
|
|
|
|
}
|
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::MenuItem("New Chart")) {
|
|
|
|
editorState->showNewChartDialog = true;
|
|
|
|
}
|
|
|
|
ImGui::Separator();
|
2019-03-02 13:47:26 +01:00
|
|
|
if (ImGui::MenuItem("Delete Chart",nullptr,false,editorState->chart.has_value())) {
|
|
|
|
editorState->fumen.Charts.erase(editorState->chart->ref.dif_name);
|
|
|
|
editorState->chart.reset();
|
2019-01-16 19:12:01 +01:00
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
2019-01-16 01:59:02 +01:00
|
|
|
}
|
2019-01-12 03:13:30 +01:00
|
|
|
if (ImGui::BeginMenu("View",editorState.has_value())) {
|
2019-01-13 22:29:29 +01:00
|
|
|
if (ImGui::MenuItem("Playfield", nullptr,editorState->showPlayfield)) {
|
|
|
|
editorState->showPlayfield = not editorState->showPlayfield;
|
2019-01-12 17:16:20 +01:00
|
|
|
}
|
2019-03-26 00:04:29 +01:00
|
|
|
if (ImGui::MenuItem("Linear View", nullptr, editorState->showLinearView)) {
|
|
|
|
editorState->showLinearView = not editorState->showLinearView;
|
|
|
|
}
|
2019-01-12 17:16:20 +01:00
|
|
|
if (ImGui::MenuItem("Playback Status",nullptr,editorState->showPlaybackStatus)) {
|
2019-01-13 03:53:42 +01:00
|
|
|
editorState->showPlaybackStatus = not editorState->showPlaybackStatus;
|
|
|
|
}
|
|
|
|
if (ImGui::MenuItem("Timeline",nullptr,editorState->showTimeline)) {
|
|
|
|
editorState->showTimeline = not editorState->showTimeline;
|
2019-01-03 23:20:35 +01:00
|
|
|
}
|
2019-01-13 22:29:29 +01:00
|
|
|
if (ImGui::MenuItem("Editor Status",nullptr,editorState->showStatus)) {
|
|
|
|
editorState->showStatus = not editorState->showStatus;
|
|
|
|
}
|
2019-03-02 13:47:26 +01:00
|
|
|
if (ImGui::MenuItem("History",nullptr,editorState->showHistory)) {
|
|
|
|
editorState->showHistory = not editorState->showHistory;
|
|
|
|
}
|
2019-01-03 23:20:35 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2019-01-17 15:37:15 +01:00
|
|
|
if (ImGui::BeginMenu("Settings",editorState.has_value())) {
|
2019-03-25 19:16:45 +01:00
|
|
|
if (ImGui::MenuItem("Sound")) {
|
|
|
|
editorState->showSoundSettings = true;
|
|
|
|
}
|
2019-03-27 20:37:30 +01:00
|
|
|
if (ImGui::MenuItem("Linear View")) {
|
|
|
|
editorState->linearView.shouldDisplaySettings = true;
|
|
|
|
}
|
2019-01-17 15:37:15 +01:00
|
|
|
if (ImGui::BeginMenu("Marker")) {
|
|
|
|
int i = 0;
|
|
|
|
for (auto& tuple : markerPreviews) {
|
|
|
|
ImGui::PushID(tuple.first.c_str());
|
|
|
|
if (ImGui::ImageButton(tuple.second,{100,100})) {
|
|
|
|
try {
|
|
|
|
marker = Marker(tuple.first);
|
2019-03-28 02:16:29 +01:00
|
|
|
preferences.marker = tuple.first.string();
|
2019-01-17 15:37:15 +01:00
|
|
|
} catch (const std::exception& e) {
|
|
|
|
tinyfd_messageBox("Error",e.what(),"ok","error",1);
|
|
|
|
marker = defaultMarker;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
i++;
|
|
|
|
if (i%4 != 0) {
|
|
|
|
ImGui::SameLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
if (ImGui::BeginMenu("Marker Ending State")) {
|
|
|
|
for (auto& m : Markers::markerStatePreviews) {
|
|
|
|
if (ImGui::ImageButton(marker.getTextures().at(m.textureName),{100,100})) {
|
|
|
|
markerEndingState = m.state;
|
2019-03-28 02:16:29 +01:00
|
|
|
preferences.markerEndingState = m.state;
|
2019-01-17 15:37:15 +01:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::TextUnformatted(m.printName.c_str());
|
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2019-01-02 23:38:47 +01:00
|
|
|
}
|
|
|
|
ImGui::EndMainMenuBar();
|
|
|
|
|
|
|
|
ImGui::SFML::Render(window);
|
2019-01-16 19:12:01 +01:00
|
|
|
window.display();
|
|
|
|
}
|
2019-01-02 23:38:47 +01:00
|
|
|
|
|
|
|
ImGui::SFML::Shutdown();
|
|
|
|
return 0;
|
2017-08-17 19:10:53 +02:00
|
|
|
}
|