Etterna 0.74.4
Loading...
Searching...
No Matches
Song.h
1#ifndef SONG_H
2#define SONG_H
3
4#include "Etterna/Models/Misc/Difficulty.h"
5#include "RageUtil/Misc/RageTypes.h"
6#include "RageUtil/Utils/RageUtil_CachedObject.h"
7#include "Etterna/Models/StepsAndStyles/Steps.h"
8#include "Etterna/Models/Misc/TimingData.h"
9#include "Etterna/Models/Misc/DateTime.h"
10
11#include <set>
12
13class Calc;
14class Style;
15class StepsID;
16struct lua_State;
17struct BackgroundChange;
18
19void
20FixupPath(std::string& path, const std::string& sSongPath);
21auto
22GetSongAssetPath(const std::string& sPath, const std::string& sSongPath)
23 -> std::string;
24
26const static float STEPFILE_VERSION_NUMBER = 0.83F;
27
29enum BackgroundLayer
30{
31 BACKGROUND_LAYER_1,
32 BACKGROUND_LAYER_2,
33 // BACKGROUND_LAYER_3, // StepCollection get
34 NUM_BackgroundLayer,
35 BACKGROUND_LAYER_Invalid
36};
37
39#define FOREACH_BackgroundLayer(bl) FOREACH_ENUM(BackgroundLayer, bl)
40
42enum InstrumentTrack
43{
44 InstrumentTrack_Guitar,
45 InstrumentTrack_Rhythm,
46 InstrumentTrack_Bass,
47 NUM_InstrumentTrack,
48 InstrumentTrack_Invalid
49};
50auto
51InstrumentTrackToString(InstrumentTrack it) -> const std::string&;
52auto
53StringToInstrumentTrack(const std::string& s) -> InstrumentTrack;
54
57{
58 float m_fStartTime;
59 std::string m_sLyric;
61};
62
64class Song
65{
66 std::string m_sSongDir;
67
68 public:
69 void SetSongDir(const std::string& sDir) { m_sSongDir = sDir; }
70 auto GetSongDir() -> const std::string& { return m_sSongDir; }
71
74 {
78 } m_SelectionDisplay;
79
80 Song();
81 ~Song();
82 void Reset();
83 void DetachSteps();
84
90 void FinalizeLoading();
91 auto LoadFromSongDir(std::string sDir, Calc* calc = nullptr) -> bool;
92 // This one takes the effort to reuse Steps pointers as best as it can
93 auto ReloadFromSongDir(const std::string& sDir) -> bool;
94 auto ReloadFromSongDir() -> bool { return ReloadFromSongDir(GetSongDir()); }
95 void ReloadIfNoMusic();
96
97 std::string m_sFileHash;
98 auto GetFileHash() -> std::string;
99
101 auto GetDateAdded() const -> DateTime { return dateAdded; };
102
107 void TidyUpData(bool fromCache = false,
108 bool duringCache = false,
109 Calc* calc = nullptr);
110
116 void ReCalculateRadarValuesAndLastSecond(bool fromCache = false,
117 bool duringCache = false,
118 Calc* calc = nullptr);
122 void TranslateTitles();
123
129 auto SaveToSSCFile(const std::string& sPath, bool bSavingCache) -> bool;
130 auto SaveToETTFile(const std::string& sPath, bool bSavingCache) -> bool;
131
133 void Save();
137 auto SaveToCacheFile() -> bool;
141 auto SaveToSMFile() -> bool;
145 auto SaveToDWIFile() -> bool;
146
147 [[nodiscard]] auto GetSongFilePath() const -> const std::string&;
148 [[nodiscard]] auto GetCacheFilePath() const -> std::string;
149
150 // Directory this song data came from:
151 [[nodiscard]] auto GetSongDir() const -> const std::string&
152 {
153 return m_sSongDir;
154 }
155
161 std::string m_sSongFileName;
162
164 std::string m_sGroupName;
165
172 bool m_bEnabled;
173
175 std::string m_sMainTitle;
177 std::string m_sSubTitle;
179 std::string m_sArtist;
185 std::string m_sArtistTranslit;
186
187 /* If PREFSMAN->m_bShowNative is off, these are the same as GetTranslit*
188 * below. Otherwise, they return the main titles. */
189 [[nodiscard]] auto GetDisplayMainTitle() const -> const std::string&;
190 [[nodiscard]] auto GetDisplaySubTitle() const -> const std::string&;
191 [[nodiscard]] auto GetDisplayArtist() const -> const std::string&;
192 [[nodiscard]] auto GetMainTitle() const -> const std::string&;
193
198 [[nodiscard]] auto GetTranslitMainTitle() const -> const std::string&
199 {
200 return static_cast<unsigned int>(!m_sMainTitleTranslit.empty()) != 0U
202 : m_sMainTitle;
203 }
204
205 auto GetStepsToSave(bool bSavingCache = true, const std::string& path = "")
206 -> std::vector<Steps*>;
207
212 [[nodiscard]] auto GetTranslitSubTitle() const -> const std::string&
213 {
214 return static_cast<unsigned int>(!m_sSubTitleTranslit.empty()) != 0U
216 : m_sSubTitle;
217 }
222 [[nodiscard]] auto GetTranslitArtist() const -> const std::string&
223 {
224 return static_cast<unsigned int>(!m_sArtistTranslit.empty()) != 0U
226 : m_sArtist;
227 }
228
229 // "title subtitle"
230 std::string displayfulltitle;
231 std::string translitfulltitle;
232 [[nodiscard]] auto GetDisplayFullTitle() const -> const std::string&
233 {
234 return displayfulltitle;
235 }
236 [[nodiscard]] auto GetTranslitFullTitle() const -> const std::string&
237 {
238 return translitfulltitle;
239 }
240
244 std::string m_sGenre;
245
249 std::string m_sCredit;
250
251 std::string m_sOrigin; // song origin (for .ssc format)
252
253 std::string m_sMusicFile;
254 std::string m_PreviewFile;
255 std::string m_sInstrumentTrackFile[NUM_InstrumentTrack];
256
259 float m_fMusicSampleStartSeconds;
260 float m_fMusicSampleLengthSeconds;
261 DisplayBPM m_DisplayBPMType;
262 float m_fSpecifiedBPMMin;
263 float m_fSpecifiedBPMMax; // if a range, then Min != Max
264
265 std::string m_sBannerFile; // typically a 16:5 ratio graphic (e.g. 256x80)
266 std::string m_sJacketFile; // typically square (e.g. 192x192, 256x256)
267 std::string m_sCDFile; // square (e.g. 128x128 [DDR 1st-3rd])
268 std::string
269 m_sDiscFile; // rectangular (e.g. 256x192 [Pump], 200x150 [MGD3])
270 std::string m_sLyricsFile;
271 std::string m_sBackgroundFile;
272 std::string m_sCDTitleFile;
273 std::string m_sPreviewVidFile;
274
275 std::string m_sMusicPath;
276 std::string m_PreviewPath;
277 std::string m_sInstrumentTrackPath[NUM_InstrumentTrack];
278 std::string m_sBannerPath; // typically a 16:5 ratio graphic (e.g. 256x80)
279 std::string m_sJacketPath; // typically square (e.g. 192x192, 256x256)
280 std::string m_sCDPath; // square (e.g. 128x128 [DDR 1st-3rd])
281 std::string
282 m_sDiscPath; // rectangular (e.g. 256x192 [Pump], 200x150 [MGD3])
283 std::string m_sLyricsPath;
284 std::string m_sBackgroundPath;
285 std::string m_sCDTitlePath;
286 std::string m_sPreviewVidPath;
287
288 std::vector<std::string> ImageDir;
289
290 static auto GetSongAssetPath(std::string sPath,
291 const std::string& sSongPath) -> std::string;
292 [[nodiscard]] auto GetMusicPath() const -> const std::string&
293 {
294 return m_sMusicPath;
295 }
296 [[nodiscard]] auto GetInstrumentTrackPath(InstrumentTrack it) const
297 -> const std::string&
298
299 {
300 return m_sInstrumentTrackPath[it];
301 }
302 [[nodiscard]] auto GetBannerPath() const -> const std::string&
303 {
304 return m_sBannerPath;
305 }
306 [[nodiscard]] auto GetJacketPath() const -> const std::string&
307 {
308 return m_sJacketPath;
309 }
310 [[nodiscard]] auto GetCDImagePath() const -> const std::string&
311 {
312 return m_sCDPath;
313 }
314 [[nodiscard]] auto GetDiscPath() const -> const std::string&
315 {
316 return m_sDiscPath;
317 }
318 [[nodiscard]] auto GetLyricsPath() const -> const std::string&
319 {
320 return m_sLyricsPath;
321 }
322 [[nodiscard]] auto GetBackgroundPath() const -> const std::string&
323 {
324 return m_sBackgroundPath;
325 }
326 [[nodiscard]] auto GetCDTitlePath() const -> const std::string&
327 {
328 return m_sCDTitlePath;
329 }
330 [[nodiscard]] auto GetPreviewVidPath() const -> const std::string&
331 {
332 return m_sPreviewVidPath;
333 }
334 [[nodiscard]] auto GetPreviewMusicPath() const -> const std::string&
335 {
336 return m_PreviewPath;
337 }
338 [[nodiscard]] auto GetCredits() const -> const std::string&
339 {
340 return m_sCredit;
341 }
342 [[nodiscard]] auto GetPreviewStartSeconds() const -> float;
343 auto GetCacheFile(const std::string& sType) -> std::string;
344
345 // how have i not jammed anything here yet - mina
346
347 // Get the highest value for a specific skillset across all the steps
348 // objects for the song at a given rate
349 [[nodiscard]] auto HighestMSDOfSkillset(Skillset x,
350 float rate,
351 bool filtered_charts_only) const
352 -> float;
353 [[nodiscard]] auto IsSkillsetHighestOfChart(Steps* chart,
354 Skillset skill,
355 float rate) const -> bool;
358 [[nodiscard]] auto MatchesFilter(
359 float rate,
360 std::vector<Steps*>* vMatchingStepsOut = nullptr) const -> bool;
361 [[nodiscard]] auto ChartMatchesFilter(Steps* chart, float rate) const
362 -> bool;
363 [[nodiscard]] auto IsChartHighestDifficulty(Steps* chart,
364 Skillset skill,
365 float rate) const -> bool;
366 auto HasChartByHash(const std::string& hash) -> bool;
367
368 // For loading only:
369 bool m_bHasMusic, m_bHasBanner, m_bHasBackground;
370
371 [[nodiscard]] auto HasMusic() const -> bool;
372 [[nodiscard]] auto HasInstrumentTrack(InstrumentTrack it) const -> bool;
373 [[nodiscard]] auto HasBanner() const -> bool;
374 [[nodiscard]] auto HasBackground() const -> bool;
375 [[nodiscard]] auto HasJacket() const -> bool;
376 [[nodiscard]] auto HasCDImage() const -> bool;
377 [[nodiscard]] auto HasDisc() const -> bool;
378 [[nodiscard]] auto HasCDTitle() const -> bool;
379 [[nodiscard]] auto HasBGChanges() const -> bool;
380 [[nodiscard]] auto HasLyrics() const -> bool;
381 [[nodiscard]] auto HasPreviewVid() const -> bool;
382
383 [[nodiscard]] auto Matches(const std::string& sGroup,
384 const std::string& sSong) const -> bool;
385
388
389 [[nodiscard]] auto GetFirstBeat() const -> float;
390 [[nodiscard]] auto GetFirstSecond() const -> float;
391 [[nodiscard]] auto GetLastBeat() const -> float;
392 [[nodiscard]] auto GetLastSecond() const -> float;
393 [[nodiscard]] auto GetSpecifiedLastBeat() const -> float;
394 [[nodiscard]] auto GetSpecifiedLastSecond() const -> float;
395
396 void SetFirstSecond(float f);
397 void SetLastSecond(float f);
398 void SetSpecifiedLastSecond(float f);
399
400 using VBackgroundChange = std::vector<BackgroundChange>;
401
402 private:
404 float firstSecond;
406 float lastSecond;
408 float specifiedLastSecond;
414 std::shared_ptr<VBackgroundChange>
415 m_BackgroundChanges[NUM_BackgroundLayer];
421 std::shared_ptr<VBackgroundChange> m_ForegroundChanges;
422
423 [[nodiscard]] auto GetChangesToVectorString(
424 const std::vector<BackgroundChange>& changes) const
425 -> std::vector<std::string>;
426
427 public:
428 [[nodiscard]] auto GetBackgroundChanges(BackgroundLayer bl) const
429 -> const std::vector<BackgroundChange>&;
430 auto GetBackgroundChanges(BackgroundLayer bl)
431 -> std::vector<BackgroundChange>&;
432 [[nodiscard]] auto GetForegroundChanges() const
433 -> const std::vector<BackgroundChange>&;
434 auto GetForegroundChanges() -> std::vector<BackgroundChange>&;
435
436 [[nodiscard]] auto GetBGChanges1ToVectorString() const
437 -> std::vector<std::string>;
438 [[nodiscard]] auto GetBGChanges2ToVectorString() const
439 -> std::vector<std::string>;
440 [[nodiscard]] auto GetFGChanges1ToVectorString() const
441 -> std::vector<std::string>;
442
443 [[nodiscard]] auto GetInstrumentTracksToVectorString() const
444 -> std::vector<std::string>;
445
450
451 void AddBackgroundChange(BackgroundLayer blLayer,
452 const BackgroundChange& seg);
453 void AddForegroundChange(const BackgroundChange& seg);
454 void AddLyricSegment(const LyricSegment& seg);
455
456 void GetDisplayBpms(DisplayBpms& AddTo,
457 bool bIgnoreCurrentRate = false) const;
458 [[nodiscard]] auto GetBackgroundAtBeat(BackgroundLayer iLayer,
459 float fBeat) const
460 -> const BackgroundChange&;
461
462 auto CreateSteps() -> Steps*;
463 void InitSteps(Steps* pSteps);
464
465 auto GetOrTryAtLeastToGetSimfileAuthor() const -> const std::string;
466
467 [[nodiscard]] auto HasSignificantBpmChangesOrStops() const -> bool;
468 [[nodiscard]] auto GetStepsSeconds() const -> float;
469 [[nodiscard]] auto IsLong() const -> bool;
470 [[nodiscard]] auto IsMarathon() const -> bool;
471
472 // plays music for chart preview and is available to lua -mina
473 void PlaySampleMusicExtended();
474
475 auto SongCompleteForStyle(const Style* st) const -> bool;
476 [[nodiscard]] auto HasStepsType(StepsType st) const -> bool;
477 [[nodiscard]] auto HasStepsTypeAndDifficulty(StepsType st,
478 Difficulty dc) const -> bool;
479 [[nodiscard]] auto GetAllSteps() const -> const std::vector<Steps*>&
480 {
481 return m_vpSteps;
482 }
483 [[nodiscard]] auto GetStepsByStepsType(StepsType st) const
484 -> const std::vector<Steps*>&
485 {
486 return m_vpStepsByType[st];
487 }
489 [[nodiscard]] auto GetChartsOfCurrentGameMode() const
490 -> std::vector<Steps*>;
491 [[nodiscard]] auto GetChartsMatchingFilter() const -> std::vector<Steps*>;
492 [[nodiscard]] auto HasEdits(StepsType st) const -> bool;
493
494 auto HasFavoritedChart() const -> bool { return isfavorited; }
495 void SetHasFavoritedChart(bool b) { isfavorited = b; }
496 auto HasGoal() const -> bool { return hasgoal; }
497 void SetHasGoal(bool b) { hasgoal = b; }
498 auto HasPermaMirrorChart() const -> bool { return permamirror; }
499 void SetHasPermaMirrorChart(bool b) { permamirror = b; }
500
501 void SetEnabled(bool b) { m_bEnabled = b; }
502 [[nodiscard]] auto GetEnabled() const -> bool { return m_bEnabled; }
503
508 void AddSteps(Steps* pSteps);
509 void DeleteSteps(const Steps* pSteps, bool bReAutoGen = true);
510
511 auto IsEditAlreadyLoaded(Steps* pSteps) const -> bool;
512
513 auto IsStepsUsingDifferentTiming(Steps* pSteps) const -> bool;
514 [[nodiscard]] auto AnyChartUsesSplitTiming() const -> bool;
515 void UnloadAllCalcDebugOutput();
522 std::vector<std::string> m_vsKeysoundFile;
523
524 CachedObject<Song> m_CachedObject;
525
526 // Lua
527 void PushSelf(lua_State* L);
528
529 std::vector<Steps*> m_vpSteps;
530 std::vector<Steps*> m_UnknownStyleSteps;
531
532 private:
533 bool isfavorited = false;
534 bool permamirror = false;
535 bool hasgoal = false;
538 std::vector<Steps*> m_vpStepsByType[NUM_StepsType];
540};
541
542#endif
Cached object pointers with automatic invalidation.
Definition RageUtil_CachedObject.h:21
Main driver class for the difficulty calculator as a whole.
Definition MinaCalc.h:82
Holds all music metadata and steps for one song.
Definition Song.h:65
auto GetTranslitMainTitle() const -> const std::string &
Retrieve the transliterated title, or the main title if there is no translit.
Definition Song.h:198
auto SaveToSMFile() -> bool
Save the current Song to a SM file.
Definition Song.cpp:1188
std::string m_sSongFileName
Filename associated with this file. This will always have a .SSC extension. If we loaded a ....
Definition Song.h:161
TimingData m_SongTiming
The Song's TimingData.
Definition Song.h:387
std::string m_sGroupName
The group this Song is in.
Definition Song.h:164
std::string m_sMainTitle
The title of the Song.
Definition Song.h:175
std::string m_sGenre
The genre of the song/file.
Definition Song.h:244
void ReCalculateRadarValuesAndLastSecond(bool fromCache=false, bool duringCache=false, Calc *calc=nullptr)
Get the new radar values, and determine the last second at the same time. This is called by TidyUpDat...
Definition Song.cpp:1085
std::string m_sMainTitleTranslit
The transliterated title of the Song, if it exists.
Definition Song.h:181
float m_fVersion
The version of the song/file.
Definition Song.h:242
std::string m_sArtist
The artist of the Song, if it exists.
Definition Song.h:179
std::vector< LyricSegment > m_LyricSegments
The list of LyricSegments. This must be sorted before gameplay.
Definition Song.h:449
auto GetTranslitArtist() const -> const std::string &
Retrieve the transliterated artist, or the main artist if there is no translit.
Definition Song.h:222
auto SaveToSSCFile(const std::string &sPath, bool bSavingCache) -> bool
Save to the new SSC file format.
Definition Song.cpp:1223
std::string m_sSubTitle
The subtitle of the Song, if it exists.
Definition Song.h:177
std::string m_sCredit
The person who worked with the song file who should be credited. This is read and saved,...
Definition Song.h:249
void TranslateTitles()
Translate any titles that aren't in english. This is called by TidyUpData.
Definition Song.cpp:1064
void FinalizeLoading()
Load a song from the chosen directory.
Definition Song.cpp:395
bool m_bIsSymLink
Is the song file itself a symlink to another file?
Definition Song.h:171
ProfileSlot m_LoadedFromProfile
the Profile this came from. This is ProfileSlot_Invalid if it wasn't loaded from a profile.
Definition Song.h:169
std::string m_sArtistTranslit
The transliterated artist of the Song, if it exists.
Definition Song.h:185
auto SaveToCacheFile() -> bool
Save the current Song to a cache file using the preferred format.
Definition Song.cpp:1343
auto GetTranslitSubTitle() const -> const std::string &
Retrieve the transliterated subtitle, or the main subtitle if there is no translit.
Definition Song.h:212
auto SaveToDWIFile() -> bool
Save the current Song to a DWI file if possible.
Definition Song.cpp:1352
auto MatchesFilter(float rate, std::vector< Steps * > *vMatchingStepsOut=nullptr) const -> bool
This functions returns whether it has any chart of the given types with the given rate....
Definition Song.cpp:1738
void Save()
Save to the SSC and SM files no matter what.
Definition Song.cpp:1144
std::string m_sSubTitleTranslit
The transliterated subtitle of the Song, if it exists.
Definition Song.h:183
float m_fMusicLengthSeconds
The length of the music file.
Definition Song.h:258
SelectionDisplay
When should this song be displayed in the music wheel?
Definition Song.h:74
@ SHOW_NEVER
Definition Song.h:76
@ SHOW_ALWAYS
Definition Song.h:75
void TidyUpData(bool fromCache=false, bool duringCache=false, Calc *calc=nullptr)
Call this after loading a song to clean up invalid data.
Definition Song.cpp:538
auto GetChartsOfCurrentGameMode() const -> std::vector< Steps * >
Get the steps of all types within the current game mode.
Definition Song.cpp:1653
std::vector< std::string > m_vsKeysoundFile
An array of keysound file names (e.g. "beep.wav"). The index in this array corresponds to the index i...
Definition Song.h:522
void AddSteps(Steps *pSteps)
Add the chosen Steps to the Song. We are responsible for deleting the memory pointed to by pSteps!
Definition Song.cpp:1902
Definition StepsUtil.h:90
Holds note information for a Song.
Definition Steps.h:42
Definition Style.h:22
Holds data for translating beats<->seconds.
Definition TimingData.h:54
Definition BackgroundUtil.h:62
A standard way of determining the date and the time.
Definition DateTime.h:81
static auto GetNowDateTime() -> DateTime
Retrieve the current date and time.
Definition DateTime.cpp:72
The list of BPMs to display.
Definition GameConstantsAndTypes.h:402
The collection of lyrics for the Song.
Definition Song.h:57
std::string m_sLyric
When does the lyric show up?
Definition Song.h:59
RageColor m_Color
The lyrics themselves.
Definition Song.h:60
Definition RageTypes.h:332