Skip to content

Commit

Permalink
Merge pull request #178 from KotRikD/feature/realtimebpm
Browse files Browse the repository at this point in the history
RealTime BPM
  • Loading branch information
cyperdark authored Aug 27, 2024
2 parents df3f405 + da28dd6 commit 28498f0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/node": "^18.18.11",
"@types/node": "^20.11.1",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0",
Expand Down
1 change: 1 addition & 0 deletions packages/tosu/src/api/types/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export interface Hp {
}

export interface Bpm {
realtime: number;
common: number;
min: number;
max: number;
Expand Down
1 change: 1 addition & 0 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => {
},

bpm: {
realtime: fixDecimals(beatmapPpData.realtimeBPM),
common: fixDecimals(beatmapPpData.commonBPM),
min: fixDecimals(beatmapPpData.minBPM),
max: fixDecimals(beatmapPpData.maxBPM)
Expand Down
14 changes: 14 additions & 0 deletions packages/tosu/src/entities/BeatmapPpData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class BeatmapPPData extends AbstractEntity {
beatmapContent?: string;
strains: number[];
strainsAll: BeatmapStrains;
realtimeBPM: number;
commonBPM: number;
minBPM: number;
maxBPM: number;
Expand Down Expand Up @@ -94,6 +95,7 @@ export class BeatmapPPData extends AbstractEntity {
xaxis: []
};
this.Mode = 0;
this.realtimeBPM = 0.0;
this.commonBPM = 0.0;
this.minBPM = 0.0;
this.maxBPM = 0.0;
Expand Down Expand Up @@ -563,4 +565,16 @@ export class BeatmapPPData extends AbstractEntity {
wLogger.debug(exc);
}
}

updateRealTimeBPM(timeMS: number) {
if (!this.lazerBeatmap) return;

this.realtimeBPM =
this.lazerBeatmap.controlPoints.timingPoints
// @ts-ignore
.toReversed()
.find((r) => r.startTime <= timeMS && r.bpm !== 0)?.bpm ||
this.lazerBeatmap.controlPoints.timingPoints[0]?.bpm ||
0.0;
}
}
2 changes: 2 additions & 0 deletions packages/tosu/src/objects/instanceManager/osuInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ export class OsuInstance {
this.previousMP3Length = menuData.MP3Length;
}

beatmapPpData.updateRealTimeBPM(allTimesData.PlayTime);

switch (allTimesData.Status) {
case 0:
bassDensityData.updateState();
Expand Down
10 changes: 8 additions & 2 deletions pnpm-lock.yaml

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

0 comments on commit 28498f0

Please sign in to comment.