Skip to content

Commit

Permalink
[WIP] Render notes
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletXF committed Sep 1, 2024
1 parent 4b0831f commit 5d84a03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/bms-parser-cpp.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
#if BMS_PARSER_VERBOSE == 1
midStartTime = std::chrono::high_resolution_clock::now();
#endif
for (auto i = 0; i <= lastMeasure; ++i) {
for (auto measureIdx = 0; measureIdx <= lastMeasure; ++measureIdx) {
if (bCancelled) {
return;
}
if (measures.find(i) == measures.end()) {
measures[i] = std::vector<std::pair<int, std::string>>();
if (measures.find(measureIdx) == measures.end()) {
measures[measureIdx] = std::vector<std::pair<int, std::string>>();
}

// gcd (int, int)
Expand All @@ -424,7 +424,7 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
// NOTE: this should be an ordered map
auto timelines = std::map<double, TimeLine *>();

for (auto &pair : measures[i]) {
for (auto &pair : measures[measureIdx]) {
if (bCancelled) {
break;
}
Expand Down Expand Up @@ -533,8 +533,8 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
int bpm = ParseHex(val);
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}");
// measureIdx << std::endl; Debug.Log($"BPM_CHANGE: {timeline.Bpm}, on
// measure {measureIdx}");
timeline->BpmChange = true;
break;
}
Expand All @@ -549,8 +549,8 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
break;
case BpmChangeExtend: {
const auto id = ParseInt(val);
// std::cout << "BPM_CHANGE_EXTEND: " << id << ", on measure " << i <<
// std::endl;
// std::cout << "BPM_CHANGE_EXTEND: " << id << ", on measure " <<
// measureIdx << std::endl;
if (!CheckResourceIdRange(id)) {
// UE_LOG(LogTemp, Warning, TEXT("Invalid BPM id: %s"), *val);
break;
Expand All @@ -561,8 +561,8 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
timeline->Bpm = 0;
// std::cout<<"Undefined BPM: "<<id<<std::endl;
}
// Debug.Log($"BPM_CHANGE_EXTEND: {timeline.Bpm}, on measure {i},
// {val}");
// Debug.Log($"BPM_CHANGE_EXTEND: {timeline.Bpm}, on measure
// {measureIdx}, {val}");
timeline->BpmChange = true;
break;
}
Expand All @@ -577,7 +577,7 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
} else {
timeline->Scroll = 1;
}
// Debug.Log($"SCROLL: {timeline.Scroll}, on measure {i}");
// Debug.Log($"SCROLL: {timeline.Scroll}, on measure {measureIdx}");
break;
}
case Stop: {
Expand All @@ -592,7 +592,7 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
} else {
timeline->StopLength = 0;
}
// Debug.Log($"STOP: {timeline.StopLength}, on measure {i}");
// Debug.Log($"STOP: {timeline.StopLength}, on measure {measureIdx}");
break;
}
case P1KeyBase: {
Expand Down Expand Up @@ -701,13 +701,14 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
const auto position = pair.first;
const auto timeline = pair.second;

// Debug.Log($"measure: {i}, position: {position}, lastPosition:
// Debug.Log($"measure: {measureIdx}, position: {position}, lastPosition:
// {lastPosition} bpm: {bpm} scale: {measure.scale} interval: {240 * 1000
// * 1000 * (position - lastPosition) * measure.scale / bpm}");
const auto interval =
240000000.0 * (position - lastPosition) * measure->Scale / currentBpm;
timePassed += interval;
timeline->Timing = static_cast<long long>(timePassed);
timeline->BeatPosition = measureIdx + position;
if (timeline->BpmChange) {
currentBpm = timeline->Bpm;
minBpm = std::min(minBpm, timeline->Bpm);
Expand All @@ -716,7 +717,7 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
timeline->Bpm = currentBpm;
}

// Debug.Log($"measure: {i}, position: {position}, lastPosition:
// Debug.Log($"measure: {measureIdx}, position: {position}, lastPosition:
// {lastPosition}, bpm: {currentBpm} scale: {measure.Scale} interval:
// {interval} stop: {timeline.GetStopDuration()}");

Expand All @@ -738,6 +739,7 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
if (!metaOnly && measure->TimeLines.empty()) {
auto timeline = new TimeLine(TempKey, metaOnly);
timeline->Timing = static_cast<long long>(timePassed);
timeline->BeatPosition = measureIdx;
timeline->Bpm = currentBpm;
measure->TimeLines.push_back(timeline);
}
Expand Down
8 changes: 6 additions & 2 deletions src/TimeLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ class TimeLine {
double StopLength = 0;
double Scroll = 1;

// musical timing in microseconds
long long Timing = 0;
double Pos = 0;

// beat position; measure number + position in
// measure. 1.25 means 1 measure and 1/4 beat
double BeatPosition = 0;

explicit TimeLine(int lanes, bool metaOnly);

TimeLine *SetNote(int lane, Note *note);

TimeLine *SetInvisibleNote(int lane, Note *note);
Expand Down

0 comments on commit 5d84a03

Please sign in to comment.