2022-03-02 23:59:19 +01:00
|
|
|
#pragma once
|
2019-01-03 23:20:35 +01:00
|
|
|
|
|
|
|
#include <SFML/Audio.hpp>
|
2022-05-11 00:09:02 +02:00
|
|
|
#include <SFML/Audio/SoundSource.hpp>
|
2019-01-12 17:16:20 +01:00
|
|
|
#include <SFML/Graphics.hpp>
|
2021-12-31 14:59:39 +01:00
|
|
|
#include <optional>
|
|
|
|
|
2022-04-06 15:47:04 +02:00
|
|
|
|
2022-04-04 22:03:10 +02:00
|
|
|
#include "better_note.hpp"
|
2022-03-16 02:10:18 +01:00
|
|
|
#include "better_song.hpp"
|
|
|
|
#include "chart_state.hpp"
|
2022-03-26 00:23:13 +01:00
|
|
|
#include "generic_interval.hpp"
|
2021-12-31 00:57:06 +01:00
|
|
|
#include "history.hpp"
|
2021-12-31 14:59:39 +01:00
|
|
|
#include "marker.hpp"
|
2022-05-11 00:09:02 +02:00
|
|
|
#include "note_claps.hpp"
|
2021-12-31 00:57:06 +01:00
|
|
|
#include "notes_clipboard.hpp"
|
2022-03-23 02:20:07 +01:00
|
|
|
#include "notifications_queue.hpp"
|
2022-04-04 22:03:10 +02:00
|
|
|
#include "playfield.hpp"
|
2022-05-11 00:09:02 +02:00
|
|
|
#include "custom_sfml_audio/synced_sound_streams.hpp"
|
|
|
|
#include "src/custom_sfml_audio/synced_sound_streams.hpp"
|
2021-12-31 00:57:06 +01:00
|
|
|
#include "widgets/linear_view.hpp"
|
2019-01-03 23:20:35 +01:00
|
|
|
|
2019-03-28 10:07:19 +01:00
|
|
|
|
2019-03-27 20:37:30 +01:00
|
|
|
/*
|
2021-12-31 14:59:39 +01:00
|
|
|
* The god class, holds everything there is to know about the currently open
|
2022-03-17 02:50:30 +01:00
|
|
|
* file
|
2019-03-27 20:37:30 +01:00
|
|
|
*/
|
2019-03-02 13:47:26 +01:00
|
|
|
class EditorState {
|
2019-01-03 23:20:35 +01:00
|
|
|
public:
|
2022-04-01 02:30:32 +02:00
|
|
|
explicit EditorState(const std::filesystem::path& assets);
|
2022-03-16 02:10:18 +01:00
|
|
|
EditorState(
|
|
|
|
const better::Song& song,
|
2022-03-17 02:50:30 +01:00
|
|
|
const std::filesystem::path& assets,
|
|
|
|
const std::filesystem::path& save_path
|
|
|
|
);
|
2022-04-01 02:30:32 +02:00
|
|
|
|
|
|
|
better::Song song;
|
2019-01-17 15:37:15 +01:00
|
|
|
|
2022-03-17 02:50:30 +01:00
|
|
|
std::optional<std::filesystem::path> song_path;
|
|
|
|
|
2022-03-16 02:10:18 +01:00
|
|
|
std::optional<ChartState> chart_state;
|
2019-03-26 00:04:29 +01:00
|
|
|
|
2022-05-11 00:09:02 +02:00
|
|
|
SyncedSoundStreams audio;
|
|
|
|
NoteClaps note_claps;
|
2022-04-07 00:14:01 +02:00
|
|
|
|
|
|
|
int get_volume() const;
|
|
|
|
void set_volume(int newMusicVolume);
|
|
|
|
void volume_up();
|
|
|
|
void volume_down();
|
|
|
|
|
|
|
|
/* These speed dials also work when no music is loaded */
|
|
|
|
int get_speed() const;
|
|
|
|
void set_speed(int newMusicSpeed);
|
|
|
|
void speed_up();
|
|
|
|
void speed_down();
|
2019-03-26 00:04:29 +01:00
|
|
|
|
2022-03-23 02:20:07 +01:00
|
|
|
std::optional<sf::Music> preview_audio;
|
|
|
|
|
2019-04-06 22:35:17 +02:00
|
|
|
Playfield playfield;
|
2022-03-16 02:10:18 +01:00
|
|
|
LinearView linear_view;
|
2019-03-26 00:04:29 +01:00
|
|
|
|
2022-04-03 15:59:05 +02:00
|
|
|
std::uint64_t snap = 1;
|
2019-01-16 22:10:20 +01:00
|
|
|
|
2022-03-17 02:50:30 +01:00
|
|
|
std::optional<sf::Texture> jacket;
|
2019-01-12 17:16:20 +01:00
|
|
|
|
2019-03-28 02:16:29 +01:00
|
|
|
bool playing;
|
|
|
|
|
2022-04-16 05:25:03 +02:00
|
|
|
std::variant<sf::Time, Fraction> playback_position;
|
|
|
|
std::variant<sf::Time, Fraction> previous_playback_position;
|
2019-04-09 23:07:22 +02:00
|
|
|
|
2022-03-26 00:23:13 +01:00
|
|
|
const Interval<sf::Time>& get_editable_range();
|
2019-01-17 01:08:38 +01:00
|
|
|
|
2022-05-11 00:09:02 +02:00
|
|
|
void play();
|
|
|
|
void pause();
|
|
|
|
void stop();
|
|
|
|
SyncedSoundStreams::Status get_status();
|
|
|
|
void set_pitch(float pitch);
|
2022-04-16 05:25:03 +02:00
|
|
|
void set_playback_position(std::variant<sf::Time, Fraction> newPosition);
|
2022-05-11 00:09:02 +02:00
|
|
|
sf::Time get_playback_position();
|
2019-02-09 16:05:46 +01:00
|
|
|
|
2022-03-23 02:20:07 +01:00
|
|
|
Fraction current_exact_beats() const;
|
|
|
|
Fraction current_snaped_beats() const;
|
2022-04-16 05:25:03 +02:00
|
|
|
Fraction previous_exact_beats() const;
|
|
|
|
sf::Time current_time() const;
|
|
|
|
sf::Time previous_time() const;
|
2022-03-23 02:20:07 +01:00
|
|
|
Fraction beats_at(sf::Time time) const;
|
|
|
|
sf::Time time_at(Fraction beat) const;
|
|
|
|
Fraction get_snap_step() const;
|
2019-01-12 17:16:20 +01:00
|
|
|
|
2019-01-13 22:29:29 +01:00
|
|
|
bool showPlayfield = true;
|
2022-04-09 00:54:06 +02:00
|
|
|
void display_playfield(Marker& marker, Judgement markerEndingState);
|
2022-03-23 02:20:07 +01:00
|
|
|
|
2019-01-03 23:20:35 +01:00
|
|
|
bool showProperties;
|
2022-03-23 02:20:07 +01:00
|
|
|
void display_properties();
|
|
|
|
|
2019-01-12 03:13:30 +01:00
|
|
|
bool showStatus;
|
2022-03-23 02:20:07 +01:00
|
|
|
void display_status();
|
|
|
|
|
2019-01-12 17:16:20 +01:00
|
|
|
bool showPlaybackStatus = true;
|
2022-03-23 02:20:07 +01:00
|
|
|
void display_playback_status();
|
|
|
|
|
2019-01-13 03:53:42 +01:00
|
|
|
bool showTimeline = true;
|
2022-03-23 02:20:07 +01:00
|
|
|
void display_timeline();
|
|
|
|
|
2019-01-16 01:59:02 +01:00
|
|
|
bool showChartList;
|
2022-03-24 01:42:41 +01:00
|
|
|
void display_chart_list();
|
2022-03-23 02:20:07 +01:00
|
|
|
|
|
|
|
bool showLinearView;
|
|
|
|
void display_linear_view();
|
|
|
|
|
2019-01-16 01:59:02 +01:00
|
|
|
bool showNewChartDialog;
|
2019-01-16 19:12:01 +01:00
|
|
|
bool showChartProperties;
|
2019-03-02 13:47:26 +01:00
|
|
|
bool showHistory;
|
2019-03-25 19:16:45 +01:00
|
|
|
bool showSoundSettings;
|
2019-01-14 21:43:56 +01:00
|
|
|
|
2022-04-02 04:10:09 +02:00
|
|
|
enum class SaveOutcome {
|
|
|
|
UserSaved,
|
|
|
|
UserDeclindedSaving,
|
|
|
|
UserCanceled,
|
|
|
|
NoSavingNeeded,
|
|
|
|
};
|
|
|
|
|
2022-04-09 00:54:06 +02:00
|
|
|
SaveOutcome save_if_needed_and_user_wants_to();
|
2022-04-06 15:47:04 +02:00
|
|
|
|
2022-04-07 00:14:01 +02:00
|
|
|
SaveOutcome save_if_needed();
|
2022-04-02 04:10:09 +02:00
|
|
|
|
|
|
|
bool needs_to_save() const;
|
|
|
|
|
|
|
|
enum class UserWantsToSave {
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
Cancel,
|
|
|
|
};
|
|
|
|
|
|
|
|
UserWantsToSave ask_if_user_wants_to_save() const;
|
2022-04-01 02:30:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
If the given song already has a dedicated file on disk, returns its path.
|
|
|
|
Otherwise use a dialog box to ask the user for a path and return it, or
|
|
|
|
return nothing if the user canceled
|
|
|
|
*/
|
|
|
|
std::optional<std::filesystem::path> ask_for_save_path_if_needed();
|
2019-03-28 02:16:29 +01:00
|
|
|
|
2022-03-27 03:32:13 +02:00
|
|
|
void toggle_note_at_current_time(const better::Position& pos);
|
2022-03-16 02:10:18 +01:00
|
|
|
|
2022-03-23 02:20:07 +01:00
|
|
|
void move_backwards_in_time();
|
|
|
|
void move_forwards_in_time();
|
|
|
|
|
|
|
|
void undo(NotificationsQueue& nq);
|
|
|
|
void redo(NotificationsQueue& nq);
|
|
|
|
|
2022-04-01 01:41:47 +02:00
|
|
|
void save(const std::filesystem::path& path);
|
2022-03-31 03:50:15 +02:00
|
|
|
|
2022-04-04 04:30:02 +02:00
|
|
|
void open_chart(const std::string& name);
|
|
|
|
|
2022-04-07 00:14:01 +02:00
|
|
|
void update_visible_notes();
|
|
|
|
|
2022-03-16 02:10:18 +01:00
|
|
|
private:
|
2022-03-23 02:20:07 +01:00
|
|
|
|
2022-04-07 00:14:01 +02:00
|
|
|
int volume = 10; // 0 -> 10
|
|
|
|
int speed = 10; // 1 -> 20
|
|
|
|
|
2022-03-17 02:50:30 +01:00
|
|
|
/*
|
|
|
|
sf::Time bounds (in the audio file "coordinates") which are accessible
|
|
|
|
(and maybe editable) from the editor, can extend before and after
|
2022-03-23 02:20:07 +01:00
|
|
|
the audio file
|
2022-03-17 02:50:30 +01:00
|
|
|
*/
|
2022-03-26 00:23:13 +01:00
|
|
|
Interval<sf::Time> editable_range;
|
2022-03-17 02:50:30 +01:00
|
|
|
void reload_editable_range();
|
2022-04-19 02:07:56 +02:00
|
|
|
Interval<sf::Time> choose_editable_range();
|
2022-03-23 02:20:07 +01:00
|
|
|
void reload_jacket();
|
2022-03-16 02:10:18 +01:00
|
|
|
void reload_music();
|
2022-03-23 02:20:07 +01:00
|
|
|
void reload_preview_audio();
|
2022-03-16 02:10:18 +01:00
|
|
|
|
2022-03-17 02:50:30 +01:00
|
|
|
better::Timing& applicable_timing;
|
|
|
|
void reload_applicable_timing();
|
|
|
|
|
|
|
|
std::filesystem::path assets;
|
2019-01-03 23:20:35 +01:00
|
|
|
};
|
|
|
|
|
2022-04-01 02:30:32 +02:00
|
|
|
namespace feis {
|
2022-04-09 00:54:06 +02:00
|
|
|
void save(
|
|
|
|
std::optional<EditorState>& ed,
|
|
|
|
NotificationsQueue& nq
|
|
|
|
);
|
|
|
|
|
|
|
|
void save_ask_open(
|
|
|
|
std::optional<EditorState>& ed,
|
|
|
|
const std::filesystem::path& assets,
|
|
|
|
const std::filesystem::path& settings
|
|
|
|
);
|
|
|
|
|
|
|
|
void save_open(
|
|
|
|
std::optional<EditorState>& ed,
|
|
|
|
const std::filesystem::path& file,
|
|
|
|
const std::filesystem::path& assets,
|
|
|
|
const std::filesystem::path& settings
|
|
|
|
);
|
|
|
|
|
2022-04-03 15:59:05 +02:00
|
|
|
void open_from_file(
|
2022-01-04 01:31:17 +01:00
|
|
|
std::optional<EditorState>& ed,
|
2022-04-09 00:54:06 +02:00
|
|
|
const std::filesystem::path& file,
|
|
|
|
const std::filesystem::path& assets,
|
|
|
|
const std::filesystem::path& settings
|
2022-01-04 01:31:17 +01:00
|
|
|
);
|
2019-01-16 01:59:02 +01:00
|
|
|
|
2022-04-09 00:54:06 +02:00
|
|
|
void save_close(std::optional<EditorState>& ed);
|
|
|
|
|
2019-01-16 01:59:02 +01:00
|
|
|
class NewChartDialog {
|
|
|
|
public:
|
2022-04-04 04:30:02 +02:00
|
|
|
std::optional<std::pair<std::string, better::Chart>> display(EditorState& editorState);
|
2021-12-31 14:59:39 +01:00
|
|
|
void resetValues() {
|
|
|
|
level = 1;
|
|
|
|
difficulty = "";
|
2022-04-04 04:30:02 +02:00
|
|
|
combo_preview = "";
|
|
|
|
show_custom_dif_name = false;
|
2021-12-31 14:59:39 +01:00
|
|
|
};
|
2019-01-16 01:59:02 +01:00
|
|
|
|
|
|
|
private:
|
2022-04-04 04:30:02 +02:00
|
|
|
Decimal level = 1;
|
2019-01-16 01:59:02 +01:00
|
|
|
std::string difficulty;
|
2022-04-04 04:30:02 +02:00
|
|
|
std::string combo_preview;
|
|
|
|
bool show_custom_dif_name = false;
|
2019-01-16 01:59:02 +01:00
|
|
|
};
|
2019-01-16 19:12:01 +01:00
|
|
|
|
|
|
|
class ChartPropertiesDialog {
|
|
|
|
public:
|
2022-04-04 04:30:02 +02:00
|
|
|
void display(EditorState& editorState);
|
|
|
|
bool should_refresh_values = true;
|
2019-01-16 19:12:01 +01:00
|
|
|
|
|
|
|
private:
|
2022-04-04 04:30:02 +02:00
|
|
|
Decimal level;
|
2019-03-02 13:47:26 +01:00
|
|
|
std::string difficulty_name;
|
2022-04-04 04:30:02 +02:00
|
|
|
std::string combo_preview;
|
|
|
|
std::set<std::string> difficulty_names_in_use;
|
|
|
|
bool show_custom_dif_name = false;
|
2019-01-16 19:12:01 +01:00
|
|
|
};
|
2019-01-13 22:29:29 +01:00
|
|
|
}
|