Skip to content

Commit

Permalink
Show key occurrence in debug message as seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Jun 9, 2019
1 parent 169ca80 commit dd388c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/track/keyutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,25 +395,25 @@ ChromaticKey KeyUtils::scaleKeySteps(ChromaticKey key, int key_changes) {

// static
mixxx::track::io::key::ChromaticKey KeyUtils::calculateGlobalKey(
const KeyChangeList& key_changes, const int iTotalSamples) {
const KeyChangeList& key_changes, const int iTotalSamples, const int iSampleRate) {
const int iTotalFrames = iTotalSamples / 2;
QMap<mixxx::track::io::key::ChromaticKey, double> key_histogram;
QMap<mixxx::track::io::key::ChromaticKey, double> key_occurrence;

for (int i = 0; i < key_changes.size(); ++i) {
mixxx::track::io::key::ChromaticKey key = key_changes[i].first;
const double start_frame = key_changes[i].second;
const double next_frame = (i == key_changes.size() - 1) ?
iTotalFrames : key_changes[i+1].second;
key_histogram[key] += (next_frame - start_frame);
key_occurrence[key] += (next_frame - start_frame);
}


double max_delta = 0;
mixxx::track::io::key::ChromaticKey max_key = mixxx::track::io::key::INVALID;
qDebug() << "Key Histogram";
for (auto it = key_histogram.constBegin();
it != key_histogram.constEnd(); ++it) {
qDebug() << it.key() << ":" << keyDebugName(it.key()) << it.value();
qDebug() << "Key Occurrence";
for (auto it = key_occurrence.constBegin();
it != key_occurrence.constEnd(); ++it) {
qDebug() << it.key() << ":" << keyDebugName(it.key()) << it.value() / iSampleRate;
if (it.value() > max_delta) {
max_key = it.key();
max_delta = it.value();
Expand Down
2 changes: 1 addition & 1 deletion src/track/keyutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class KeyUtils {
static mixxx::track::io::key::ChromaticKey guessKeyFromText(const QString& text);

static mixxx::track::io::key::ChromaticKey calculateGlobalKey(
const KeyChangeList& key_changes, int iTotalSamples);
const KeyChangeList& key_changes, int iTotalSamples, const int iSampleRate);

static void setNotation(
const QMap<mixxx::track::io::key::ChromaticKey, QString>& notation);
Expand Down

0 comments on commit dd388c3

Please sign in to comment.