Simplify time calc

This commit is contained in:
Joseph DiMaria 2026-01-31 02:51:39 -08:00
parent d1a2ac6ab9
commit 75a013b3ae
2 changed files with 2 additions and 12 deletions

View File

@ -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<Track> tracks;
};
int ticksToMilliseconds(int ticks, double tempo, int ppq) {
double microseconds = (ticks * tempo) / ppq;
// Convert to milliseconds with rounding
return static_cast<int>(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);
}
}

View File

@ -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);