RhythmGame 1.4.3
Loading...
Searching...
No Matches
BmsNotes.h
Go to the documentation of this file.
1//
2// Created by bobini on 24.08.23.
3//
4
5#ifndef RHYTHMGAME_BMSNOTES_H
6#define RHYTHMGAME_BMSNOTES_H
7#include <QObject>
8#include "support/Sha256.h"
9#include "db/SqliteCppDb.h"
10
11namespace gameplay_logic {
12
13class Time
14{
15 Q_GADGET
17 Q_PROPERTY(int64_t timestamp MEMBER timestamp)
19 Q_PROPERTY(double position MEMBER position)
21 Q_PROPERTY(double beatPosition MEMBER beatPosition)
22 public:
23 // Timestamp in nanoseconds
24 int64_t timestamp{};
25 // Position in beats after applying scrolls
26 double position{};
27 // Position in beats
28 double beatPosition{};
29 auto operator+(const Time& other) const -> Time
30 {
31 return { timestamp + other.timestamp,
32 position + other.position,
33 beatPosition + other.beatPosition };
34 }
35 auto operator<=>(const Time& other) const = default;
36};
37
38inline auto
39operator<<(QDataStream& stream, const Time& time) -> QDataStream&
40{
41 return stream << static_cast<qint64>(time.timestamp) << time.position
42 << time.beatPosition;
43}
44
45inline auto
46operator>>(QDataStream& stream, Time& time) -> QDataStream&
47{
48 auto timestamp = qint64{};
49 auto& ret = stream >> timestamp >> time.position >> time.beatPosition;
50 time.timestamp = timestamp;
51 return ret;
52}
53
55{
56 Q_GADGET
57 Q_PROPERTY(Time time MEMBER time)
58 Q_PROPERTY(double bpm MEMBER bpm)
59 Q_PROPERTY(double scroll MEMBER scroll)
60 public:
61 Time time;
62 double bpm;
63 double scroll;
64 BpmChange() = default;
65 BpmChange(Time time, double bpm, double scroll)
66 : time(time)
67 , bpm(bpm)
68 , scroll(scroll)
69 {
70 }
71 auto operator<=>(const BpmChange& other) const = default;
72};
73
74inline auto
75operator<<(QDataStream& stream, const BpmChange& bpmChange) -> QDataStream&
76{
77 return stream << bpmChange.time << bpmChange.bpm << bpmChange.scroll;
78}
79
80inline auto
81operator>>(QDataStream& stream, BpmChange& bpmChange) -> QDataStream&
82{
83 return stream >> bpmChange.time >> bpmChange.bpm >> bpmChange.scroll;
84}
85
89class Snap
90{
91 Q_GADGET
95 Q_PROPERTY(double numerator MEMBER numerator)
99 Q_PROPERTY(double denominator MEMBER denominator)
100 public:
101 double numerator;
102 double denominator;
103 auto operator<=>(const Snap& other) const = default;
104};
105
106inline auto
107operator<<(QDataStream& stream, const Snap& snap) -> QDataStream&
108{
109 return stream << snap.numerator << snap.denominator;
110}
111
112inline auto
113operator>>(QDataStream& stream, Snap& snap) -> QDataStream&
114{
115 return stream >> snap.numerator >> snap.denominator;
116}
117
118class Note
119{
120 Q_GADGET
121 public:
122 enum class Type
123 {
124 Normal,
125 LongNoteBegin,
126 LongNoteEnd,
127 Landmine,
128 Invisible
129 };
130 Q_ENUM(Type)
131 private:
132 Q_PROPERTY(Time time MEMBER time)
133 Q_PROPERTY(Snap snap MEMBER snap)
134 Q_PROPERTY(Type type MEMBER type)
135 public:
136 Time time;
137 Snap snap;
138 Type type;
139 auto operator<=>(const Note& other) const = default;
140};
141
142inline auto
143operator<<(QDataStream& stream, const Note& note) -> QDataStream&
144{
145 return stream << note.time << note.snap << note.type;
146}
147
148inline auto
149operator>>(QDataStream& stream, Note& note) -> QDataStream&
150{
151 return stream >> note.time >> note.snap >> note.type;
152}
153
154class BmsNotes : public QObject
155{
156 Q_OBJECT
157 Q_PROPERTY(QList<QList<Note>> notes READ getNotes CONSTANT)
158 Q_PROPERTY(QList<Time> barLines READ getBarLines CONSTANT)
159
160 QList<QList<Note>> notes;
161 QList<Time> barLines;
162
163 public:
164 BmsNotes() = default;
165 explicit BmsNotes(QList<QList<Note>> visibleNotes,
166 QList<Time> barLines,
167 QObject* parent = nullptr);
168
169 auto getNotes() -> QList<QList<Note>>&;
170
171 auto getNotes() const -> const QList<QList<Note>>&;
172 auto getBarLines() const -> const QList<Time>&;
173
174 friend auto operator<<(QDataStream& stream, const BmsNotes& notes)
175 -> QDataStream&
176 {
177 return stream << notes.notes << notes.barLines;
178 }
179
180 friend auto operator>>(QDataStream& stream, BmsNotes& notes) -> QDataStream&
181 {
182 return stream >> notes.notes >> notes.barLines;
183 }
184
185 static auto load(db::SqliteCppDb& db, const support::Sha256& sha256)
186 -> std::unique_ptr<BmsNotes>;
187 auto serialize() const -> QByteArray;
188 auto save(db::SqliteCppDb& db, const support::Sha256& sha256) const -> void;
189};
190} // namespace gameplay_logic
191
192#endif // RHYTHMGAME_BMSNOTES_H
QString sha256
Definition BeatorajaReplayImporter.cpp:72
Type type
Definition BmsNotesData.cpp:33
int64_t timestamp
Definition ImportedScoreImporter.cpp:58
Database wrapper for SQLiteCpp.
Definition SqliteCppDb.h:30
Definition BmsNotes.h:155
friend auto operator>>(QDataStream &stream, BmsNotes &notes) -> QDataStream &
Definition BmsNotes.h:180
Definition BmsNotes.h:55
auto operator<=>(const BpmChange &other) const =default
double bpm
Definition BmsNotes.h:58
Time time
Definition BmsNotes.h:57
double scroll
Definition BmsNotes.h:59
Definition BmsNotes.h:119
Type
Definition BmsNotes.h:123
Represents the position of the note in a measure.
Definition BmsNotes.h:90
double numerator
The position of the note in a measure, expressed in whole notes.
Definition BmsNotes.h:95
double denominator
How many whole notes fit into a measure.
Definition BmsNotes.h:99
Definition BmsNotes.h:14
double position
Position expressed in beats after applying scrolls.
Definition BmsNotes.h:19
double beatPosition
Position expressed in beats.
Definition BmsNotes.h:21
auto operator+(const Time &other) const -> Time
Definition BmsNotes.h:29
int64_t timestamp
Timestamp expressed in nanoseconds.
Definition BmsNotes.h:17
auto operator<=>(const Time &other) const =default
Namespace for database related classes and functions.
Definition QtArenaRoundLoader.h:15
Classes and functions mostly related to gameplay.
Definition ArenaGameplaySource.h:10
auto operator>>(QDataStream &stream, BmsGaugeInfo &gaugeInfo) -> QDataStream &
Definition BmsGaugeHistory.cpp:29
auto operator<<(QDataStream &stream, const BmsGaugeInfo &gaugeInfo) -> QDataStream &
Definition BmsGaugeHistory.cpp:23
Contains various helper classes and functions.
Definition Capitalize.h:9
std::string Sha256
Definition Sha256.h:10