forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotesLoaderSM.h
249 lines (224 loc) · 9.76 KB
/
NotesLoaderSM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef NotesLoaderSM_H
#define NotesLoaderSM_H
#include "GameConstantsAndTypes.h"
#include "BackgroundUtil.h"
#include "Attack.h"
#include "MsdFile.h" // we require the struct from here.
class Song;
class Steps;
class TimingData;
/**
* @brief The highest allowable speed before Warps come in.
*
* This was brought in from StepMania 4's recent betas. */
const float FAST_BPM_WARP = 9999999.f;
/** @brief The maximum file size for edits. */
const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB
/** @brief Reads a Song from an .SM file. */
struct SMLoader
{
SMLoader() : fileExt(".sm"), songTitle() {}
SMLoader(std::string ext) : fileExt(ext), songTitle() {}
virtual ~SMLoader() {}
/**
* @brief Attempt to load a song from a specified path.
* @param sPath a const reference to the path on the hard drive to check.
* @param out a reference to the Song that will retrieve the song information.
* @return its success or failure.
*/
virtual bool LoadFromDir( const std::string &sPath, Song &out, bool load_autosave= false );
/**
* @brief Perform some cleanup on the loaded song.
* @param song a reference to the song that may need cleaning up.
* @param bFromCache a flag to determine if this song is loaded from a cache file.
*/
virtual void TidyUpData( Song &song, bool bFromCache );
/**
* @brief Retrieve the relevant notedata from the simfile.
* @param path the path where the simfile lives.
* @param out the Steps we are loading the data into. */
virtual bool LoadNoteDataFromSimfile(const std::string &path, Steps &out );
/**
* @brief Attempt to load the specified sm file.
* @param sPath a const reference to the path on the hard drive to check.
* @param out a reference to the Song that will retrieve the song information.
* @param bFromCache a check to see if we are getting certain information from the cache file.
* @return its success or failure.
*/
virtual bool LoadFromSimfile( const std::string &sPath, Song &out, bool bFromCache = false );
/**
* @brief Retrieve the list of .sm files.
* @param sPath a const reference to the path on the hard drive to check.
* @param out a vector of files found in the path.
*/
virtual void GetApplicableFiles( std::string const &sPath, std::vector<std::string> &out, bool load_autosave= false );
virtual bool LoadEditFromFile( std::string sEditFilePath, ProfileSlot slot, bool bAddStepsToSong, Song *givenSong=nullptr );
virtual bool LoadEditFromBuffer( const std::string &sBuffer, const std::string &sEditFilePath, ProfileSlot slot, Song *givenSong=nullptr );
virtual bool LoadEditFromMsd( const MsdFile &msd, const std::string &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong, Song *givenSong=nullptr );
virtual bool LoadFromBGChangesString(BackgroundChange &change,
const std::string &sBGChangeExpression );
/**
* @brief Parse BPM Changes data from a string.
* @param out the vector to put the data in.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
void ParseBPMs(std::vector< std::pair<float, float> > &out,
const std::string line,
const int rowsPerBeat = -1);
/**
* @brief Process the BPM Segments from the string.
* @param out the TimingData being modified.
* @param vBPMChanges the vector of BPM Changes data. */
void ProcessBPMs(TimingData & out,
const std::vector< std::pair<float, float> > &vBPMChanges);
/**
* @brief Parse Stops data from a string.
* @param out the vector to put the data in.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
void ParseStops(std::vector< std::pair<float, float> > &out,
const std::string line,
const int rowsPerBeat = -1);
/**
* @brief Process the Stop Segments from the data.
* @param out the TimingData being modified.
* @param vStops the vector of Stops data. */
void ProcessStops(TimingData & out,
const std::vector< std::pair<float, float> > &vStops);
/**
* @brief Process BPM and stop segments from the data.
* @param out the TimingData being modified.
* @param vBPMs the vector of BPM changes.
* @param vStops the vector of stops. */
void ProcessBPMsAndStops(TimingData &out,
std::vector< std::pair<float, float> > &vBPMs,
std::vector< std::pair<float, float> > &vStops);
/**
* @brief Process the Delay Segments from the string.
* @param out the TimingData being modified.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
void ProcessDelays(TimingData & out,
const std::string line,
const int rowsPerBeat = -1);
/**
* @brief Process the Time Signature Segments from the string.
* @param out the TimingData being modified.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
void ProcessTimeSignatures(TimingData & out,
const std::string line,
const int rowsPerBeat = -1);
/**
* @brief Process the Tickcount Segments from the string.
* @param out the TimingData being modified.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
void ProcessTickcounts(TimingData & out,
const std::string line,
const int rowsPerBeat = -1);
/**
* @brief Process the Speed Segments from the string.
* @param out the TimingData being modified.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
virtual void ProcessSpeeds(TimingData & out,
const std::string line,
const int rowsPerBeat = -1);
virtual void ProcessCombos(TimingData & /* out */,
const std::string,
const int /* rowsPerBeat */ = -1) {}
/**
* @brief Process the Fake Segments from the string.
* @param out the TimingData being modified.
* @param line the string in question.
* @param rowsPerBeat the number of rows per beat for this purpose. */
virtual void ProcessFakes(TimingData & out,
const std::string line,
const int rowsPerBeat = -1);
virtual void ProcessBGChanges( Song &out, const std::string &sValueName,
const std::string &sPath, const std::string &sParam );
/**
* @brief Put the attacks in the attacks string.
* @param attacks the attack string.
* @param params the params from the simfile. */
virtual void ProcessAttackString(std::vector<std::string> &attacks, MsdFile::value_t params);
/**
* @brief Put the attacks in the attacks array.
* @param attacks the attacks array.
* @param params the params from the simfile. */
void ProcessAttacks( AttackArray &attacks, MsdFile::value_t params );
void ProcessInstrumentTracks( Song &out, const std::string &sParam );
/**
* @brief Convert a row value to the proper beat value.
*
* This is primarily used for assistance with converting SMA files.
* @param line The line that contains the value.
* @param rowsPerBeat the number of rows per beat according to the original file.
* @return the converted beat value. */
float RowToBeat(std::string line, const int rowsPerBeat);
protected:
/**
* @brief Process the different tokens we have available to get NoteData.
* @param stepsType The current StepsType.
* @param description The description of the chart.
* @param difficulty The difficulty (in words) of the chart.
* @param meter the difficulty (in numbers) of the chart.
* @param radarValues the calculated radar values.
* @param noteData the note data itself.
* @param out the Steps getting the data. */
virtual void LoadFromTokens(std::string sStepsType,
std::string sDescription,
std::string sDifficulty,
std::string sMeter,
std::string sRadarValues,
std::string sNoteData,
Steps &out);
/**
* @brief Retrieve the file extension associated with this loader.
* @return the file extension. */
std::string GetFileExtension() const { return fileExt; }
public:
// SetSongTitle and GetSongTitle changed to public to allow the functions
// used by the parser helper to access them. -Kyz
/**
* @brief Set the song title.
* @param t the song title. */
virtual void SetSongTitle(const std::string & title);
/**
* @brief Get the song title.
* @return the song title. */
virtual std::string GetSongTitle() const;
private:
/** @brief The file extension in use. */
const std::string fileExt;
/** @brief The song title that is being processed. */
std::string songTitle;
};
#endif
/**
* @file
* @author Chris Danford, Glenn Maynard (c) 2001-2004
* @section LICENSE
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/