F.E.I.S/src/better_notes.hpp

74 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
#include <algorithm>
#include <array>
2022-04-09 00:54:06 +02:00
#include <cstddef>
#include <type_traits>
#include <utility>
2022-04-14 01:26:31 +02:00
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <interval_tree.hpp>
#include <json.hpp>
#include "better_note.hpp"
#include "better_timing.hpp"
#include "generic_interval.hpp"
#include "json.hpp"
#include "special_numeric_types.hpp"
namespace better {
2022-04-14 00:13:38 +02:00
class Notes : public interval_tree<Fraction, Note> {
public:
// try to insert a note, the boolean is true on success
2022-04-14 00:13:38 +02:00
std::pair<iterator, bool> insert(const Note& note);
2022-04-19 23:13:18 +02:00
// insert a note, erasing any other note it collides with,
// returns the set of erased notes
Notes overwriting_insert(const Note& note);
// insert each note in other
void merge(Notes&& other);
// returns at iterator to a note exactly equal, if found
2022-04-14 00:13:38 +02:00
const_iterator find(const Note& note) const;
2022-03-25 02:20:22 +01:00
bool contains(const Note& note) const;
void erase(const Note& note);
/*
Returns true if the given note (assumed to already be in the container)
is colliding with ANOTHER note. This means notes exactly equal to the
one passed as an argument are NOT taken into account.
*/
bool is_colliding(const better::Note& note, const better::Timing& timing, const sf::Time& collision_zone) const;
Notes between(const Interval<Fraction>& bounds);
2022-04-09 00:54:06 +02:00
std::size_t count_between(const Interval<Fraction>& bounds);
2022-04-02 04:10:09 +02:00
nlohmann::ordered_json dump_to_memon_1_0_0() const;
2022-04-11 01:50:25 +02:00
static Notes load_from_memon_1_0_0(const nlohmann::json& json, std::uint64_t resolution = 240);
static Notes load_from_memon_legacy(const nlohmann::json& json, std::uint64_t resolution);
2022-04-14 01:26:31 +02:00
friend std::ostream& operator<<(std::ostream& out, const Notes& ns);
};
2022-04-14 01:26:31 +02:00
}
template <>
struct fmt::formatter<better::Notes>: formatter<string_view> {
// parse is inherited from formatter<string_view>.
template <typename FormatContext>
auto format(const better::Notes& n, FormatContext& ctx) {
std::vector<better::Note> notes;
for (const auto& [_, note] : n) {
notes.push_back(note);
}
2022-04-14 01:26:31 +02:00
return format_to(
ctx.out(),
"[{}]",
fmt::join(
notes,
", "
)
);
}
};