From 75a013b3aefd65c3e3c829a00cf7f9fce012d255 Mon Sep 17 00:00:00 2001 From: Joseph DiMaria Date: Sat, 31 Jan 2026 02:51:39 -0800 Subject: [PATCH] Simplify time calc --- src/entities/song.h | 13 ++----------- src/main.cpp | 1 - 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/entities/song.h b/src/entities/song.h index 2018745..77be8c1 100644 --- a/src/entities/song.h +++ b/src/entities/song.h @@ -30,7 +30,6 @@ struct Header { std::string name; int ppq; float bpm; - double tempo; }; struct Song { @@ -38,13 +37,6 @@ struct Song { std::vector tracks; }; -int ticksToMilliseconds(int ticks, double tempo, int ppq) { - double microseconds = (ticks * tempo) / ppq; - - // Convert to milliseconds with rounding - return static_cast(microseconds / 1000.0 + 0.5); -} - Song parseSong(const rapidjson::Document& doc) { assert(doc.IsObject()); @@ -59,7 +51,6 @@ Song parseSong(const rapidjson::Document& doc) { if (h.HasMember("tempos") && h["tempos"].IsArray()) { const auto& tempos = h["tempos"].GetArray(); header.bpm = tempos[0]["bpm"].GetFloat(); - header.tempo = 60000000.0 / header.bpm; } song.header = header; } @@ -85,9 +76,9 @@ Song parseSong(const rapidjson::Document& doc) { note.name = n["name"].GetString(); note.midi = n["midi"].GetInt(); note.duration_ticks = n["durationTicks"].GetInt(); - note.duration_ms = ticksToMilliseconds(note.duration_ticks, song.header.tempo, song.header.ppq); + note.duration_ms = n["duration"].GetFloat() * 1000; note.ticks = n["ticks"].GetInt(); - note.position_ms = ticksToMilliseconds(note.ticks, song.header.tempo, song.header.ppq); + note.position_ms = n["time"].GetFloat() * 1000; track.notes.push_back(note); } } diff --git a/src/main.cpp b/src/main.cpp index cf4db39..eec3360 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,6 @@ int main(int argc, char** argv) Song& song = song_manager->load_song("mary_had_a_lil_lamb", "assets/songs/json/mary.json"); printf("Song name: %s\n", song.header.name.c_str()); printf("Song bpm: %f\n", song.header.bpm); - printf("Song tempo: %f\n", song.header.tempo); printf("First note duration: %d\n", song.tracks[0].notes[0].duration_ms);