From d1a9c61598efd2e9a2c1d73ae7c7ca314fc8f950 Mon Sep 17 00:00:00 2001 From: danferns Date: Mon, 12 Aug 2024 17:28:45 +0530 Subject: [PATCH] Use mixxx::Bpm type in trackSimilarity --- src/track/keyutils.cpp | 16 +++++++++------- src/track/keyutils.h | 9 +++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/track/keyutils.cpp b/src/track/keyutils.cpp index 9642e182fb3d..763c382ec9d9 100644 --- a/src/track/keyutils.cpp +++ b/src/track/keyutils.cpp @@ -703,17 +703,17 @@ int KeyUtils::keyToCircleOfFifthsOrder(mixxx::track::io::key::ChromaticKey key, // same tempo. Assumes all inputs are valid. double KeyUtils::trackSyncPitchDifference( mixxx::track::io::key::ChromaticKey key1, - double bpm1, + mixxx::Bpm bpm1, mixxx::track::io::key::ChromaticKey key2, - double bpm2) { + mixxx::Bpm bpm2) { // convert minor keys to their relative majors // we are interested in the notes used, not the mode key1 = minorToRelativeMajor(key1); key2 = minorToRelativeMajor(key2); // calculate the pitch delta for each track when stretched to a tempo of 100BPM - const double delta1 = powerOf2ToSemitoneChange(100 / bpm1); - const double delta2 = powerOf2ToSemitoneChange(100 / bpm2); + const double delta1 = powerOf2ToSemitoneChange(100 / bpm1.value()); + const double delta2 = powerOf2ToSemitoneChange(100 / bpm2.value()); // get the resulting key for each track at 100BPM const double resPitch1 = normalizePitch(keyToNumericValue(key1) - 1 + delta1); @@ -725,10 +725,12 @@ double KeyUtils::trackSyncPitchDifference( // Calculates Similarity (0 to 1, -1 if invalid) between two tracks based on their key and BPM. double KeyUtils::trackSimilarity(mixxx::track::io::key::ChromaticKey key1, - double bpm1, + mixxx::Bpm bpm1, mixxx::track::io::key::ChromaticKey key2, - double bpm2) { - if (key1 == mixxx::track::io::key::INVALID || key2 == mixxx::track::io::key::INVALID) { + mixxx::Bpm bpm2) { + if (key1 == mixxx::track::io::key::INVALID || + key2 == mixxx::track::io::key::INVALID || !bpm1.isValid() || + !bpm2.isValid()) { return -1.0; } diff --git a/src/track/keyutils.h b/src/track/keyutils.h index 17bfa5497054..20b19e721970 100644 --- a/src/track/keyutils.h +++ b/src/track/keyutils.h @@ -7,6 +7,7 @@ #include "audio/types.h" #include "control/controlproxy.h" #include "proto/keys.pb.h" +#include "track/bpm.h" #include "track/keys.h" #include "util/math.h" #include "util/types.h" @@ -199,14 +200,14 @@ class KeyUtils { static double trackSyncPitchDifference( mixxx::track::io::key::ChromaticKey key1, - double bpm1, + mixxx::Bpm bpm1, mixxx::track::io::key::ChromaticKey key2, - double bpm2); + mixxx::Bpm bpm2); static double trackSimilarity(mixxx::track::io::key::ChromaticKey key1, - double bpm1, + mixxx::Bpm bpm1, mixxx::track::io::key::ChromaticKey key2, - double bpm2); + mixxx::Bpm bpm2); private: static QMutex s_notationMutex;