Skip to content

Commit

Permalink
Use mixxx::Bpm type in trackSimilarity
Browse files Browse the repository at this point in the history
  • Loading branch information
danferns committed Aug 12, 2024
1 parent 453edeb commit d1a9c61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/track/keyutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
9 changes: 5 additions & 4 deletions src/track/keyutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d1a9c61

Please # to comment.