Skip to content

Commit

Permalink
Fix bpm
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletXF committed Apr 24, 2024
1 parent c1f1966 commit 65df464
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC=g++
CCFLAGS=-std=c++17 -DBMS_PARSER_VERBOSE=0
CCFLAGS=-std=c++17 -O2 -DBMS_PARSER_VERBOSE=0
SRC_FILES = $(wildcard src/*.cpp)
OBJ_PATH=obj
BUILD_PATH=build
Expand Down
14 changes: 7 additions & 7 deletions src/Chart.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace bms_parser
std::wstring Folder;
std::wstring Artist = L"";
std::wstring SubArtist = L"";
double Bpm;
double Bpm = 0;
std::wstring Genre = L"";
std::wstring Title = L"";
std::wstring SubTitle = L"";
Expand All @@ -48,15 +48,15 @@ namespace bms_parser
bool BgaPoorDefault = false;
int Difficulty = 0;
double PlayLevel = 3;
double MinBpm;
double MaxBpm;
double MinBpm = 0;
double MaxBpm = 0;
int Player = 1;
int KeyMode = 5;
bool IsDP = false;
int TotalNotes;
int TotalLongNotes;
int TotalScratchNotes;
int TotalBackSpinNotes;
int TotalNotes = 0;
int TotalLongNotes = 0;
int TotalScratchNotes = 0;
int TotalBackSpinNotes = 0;
int LnMode = 0; // 0: user decides, 1: LN, 2: CN, 3: HCN

int GetKeyLaneCount() const { return KeyMode; }
Expand Down
38 changes: 27 additions & 11 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace bms_parser

int Parser::NoWav = -1;
int Parser::MetronomeWav = -2;
bool Parser::MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper)
inline bool Parser::MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper)
{
auto size = headerUpper.length();
if (str.length() < size)
Expand Down Expand Up @@ -598,12 +598,8 @@ namespace bms_parser
break;
case BpmChange:
{
std::wstringstream ss;
ss << std::hex << val_view;
int bpm;
ss >> bpm;
// parse hex number
timeline->Bpm = bpm;
int bpm = ParseHex(val_view);
timeline->Bpm = static_cast<double>(bpm);
// std::cout << "BPM_CHANGE: " << timeline->Bpm << ", on measure " << i << std::endl;
// Debug.Log($"BPM_CHANGE: {timeline.Bpm}, on measure {i}");
timeline->BpmChange = true;
Expand Down Expand Up @@ -1112,7 +1108,7 @@ namespace bms_parser
}
}

int Parser::Gcd(int A, int B)
inline int Parser::Gcd(int A, int B)
{
while (true)
{
Expand All @@ -1131,7 +1127,7 @@ namespace bms_parser
return Id >= 0 && Id < (UseBase62 ? 62*62 : 36*36);
}

int Parser::ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly)
inline int Parser::ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly)
{
if (metaOnly)
{
Expand All @@ -1151,8 +1147,28 @@ namespace bms_parser

return Chart->WavTable.find(decoded) != Chart->WavTable.end() ? decoded : NoWav;
}

int Parser::ParseInt(std::wstring_view Str, bool forceBase36)
inline int Parser::ParseHex(std::wstring_view Str)
{
auto result = 0;
for (auto i = 0; i < Str.length(); ++i)
{
auto c = Str[i];
if (c >= '0' && c <= '9')
{
result = result * 16 + c - '0';
}
else if (c >= 'A' && c <= 'F')
{
result = result * 16 + c - 'A' + 10;
}
else if (c >= 'a' && c <= 'f')
{
result = result * 16 + c - 'a' + 10;
}
}
return result;
}
inline int Parser::ParseInt(std::wstring_view Str, bool forceBase36)
{
if(forceBase36 || !UseBase62) {
auto result = static_cast<int>(std::wcstol(Str.data(), nullptr, 36));
Expand Down
9 changes: 5 additions & 4 deletions src/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ namespace bms_parser
int Lnobj = -1;
int Lntype = 1;
int Seed;
int ParseInt(std::wstring_view Str, bool forceBase32 = false);
inline int ParseHex(std::wstring_view Str);
inline int ParseInt(std::wstring_view Str, bool forceBase32 = false);
void ParseHeader(Chart *Chart, std::wstring_view cmd, std::wstring_view Xx, const std::wstring &Value);
bool MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper);
static int Gcd(int A, int B);
inline bool MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper);
inline int Gcd(int A, int B);
inline bool CheckResourceIdRange(int Id);
int ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly);
inline int ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly);
};
}

0 comments on commit 65df464

Please sign in to comment.