Skip to content

Commit 7045f61

Browse files
authored
Merge pull request #16029 from Swarnadip-Kar/add-tuning-field-trackinfo
DlgTrackInfo: add editable tuning field
2 parents f3a86d7 + 8ad1378 commit 7045f61

3 files changed

Lines changed: 181 additions & 27 deletions

File tree

src/library/dlgtrackinfo.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QSignalBlocker>
44
#include <QStyleFactory>
55
#include <QtDebug>
6+
#include <cmath>
67

78
#include "defs_urls.h"
89
#include "library/coverartcache.h"
@@ -34,6 +35,9 @@ const mixxx::Duration kMaxInterval = mixxx::Duration::fromMillis(
3435
static_cast<qint64>(1000.0 * (60.0 / kMinBpm)));
3536
const QString kBpmPropertyName = QStringLiteral("bpm");
3637

38+
constexpr double kStandardTuningHz = 440.0;
39+
constexpr double kCentsPerOctave = 1200.0;
40+
3741
} // namespace
3842

3943
DlgTrackInfo::DlgTrackInfo(
@@ -174,6 +178,11 @@ void DlgTrackInfo::init() {
174178
this,
175179
&DlgTrackInfo::slotKeyTextChanged);
176180

181+
connect(spinTuning,
182+
QOverload<double>::of(&QDoubleSpinBox::valueChanged),
183+
this,
184+
&DlgTrackInfo::slotTuningValueChanged);
185+
177186
connect(bpmTap,
178187
&QPushButton::pressed,
179188
&m_tapFilter,
@@ -440,6 +449,7 @@ void DlgTrackInfo::updateTrackMetadataFields() {
440449
txtBpm->setText(
441450
m_trackRecord.getMetadata().getTrackInfo().getBpmText());
442451
displayKeyText();
452+
displayTuningFields();
443453

444454
// Non-editable fields
445455
txtDuration->setText(
@@ -663,6 +673,7 @@ void DlgTrackInfo::saveTrack() {
663673
slotSpinBpmValueChanged(spinBpm->value());
664674
updateKeyText();
665675

676+
slotTuningValueChanged(spinTuning->value());
666677
m_trackRecord.setBpmLocked(m_bpmLocked);
667678

668679
// Update the cached track
@@ -805,6 +816,53 @@ void DlgTrackInfo::displayKeyText() {
805816
txtKey->setText(keyText);
806817
}
807818

819+
void DlgTrackInfo::displayTuningFields() {
820+
const double tuningHz =
821+
m_trackRecord.getKeys().getGlobalTuningFrequencyHz();
822+
const QSignalBlocker blocker(spinTuning);
823+
if (tuningHz > 0.0) {
824+
// Block signals to avoid triggering slotTuningValueChanged
825+
// while we are just loading data into the widget.
826+
spinTuning->setValue(tuningHz);
827+
828+
const double cents = kCentsPerOctave *
829+
std::log2(tuningHz / kStandardTuningHz);
830+
const int centsRounded = static_cast<int>(std::lround(cents));
831+
const QString offsetText = centsRounded >= 0
832+
? QStringLiteral("+%1 ct").arg(centsRounded)
833+
: QStringLiteral("%1 ct").arg(centsRounded);
834+
txtTuningCents->setText(offsetText);
835+
} else {
836+
// No tuning data: set to minimum (triggers specialValueText = blank)
837+
spinTuning->setValue(spinTuning->minimum());
838+
txtTuningCents->clear();
839+
}
840+
}
841+
842+
void DlgTrackInfo::slotTuningValueChanged(double value) {
843+
// Store the user-entered Hz value in the Keys protobuf
844+
Keys keys = m_trackRecord.getKeys();
845+
if (value <= spinTuning->minimum()) {
846+
// Special value (minimum) means "no tuning set" — store 0 Hz
847+
keys.setGlobalTuningFrequencyHz(0.0);
848+
m_trackRecord.setKeys(std::move(keys));
849+
txtTuningCents->clear();
850+
return;
851+
}
852+
853+
keys.setGlobalTuningFrequencyHz(value);
854+
m_trackRecord.setKeys(std::move(keys));
855+
856+
// Update the cents offset label so the user gets immediate feedback
857+
const double cents = kCentsPerOctave *
858+
std::log2(value / kStandardTuningHz);
859+
const int centsRounded = static_cast<int>(std::lround(cents));
860+
const QString offsetText = centsRounded >= 0
861+
? QStringLiteral("+%1 ct").arg(centsRounded)
862+
: QStringLiteral("%1 ct").arg(centsRounded);
863+
txtTuningCents->setText(offsetText);
864+
}
865+
808866
void DlgTrackInfo::slotKeyTextChanged() {
809867
updateKeyText();
810868
}

src/library/dlgtrackinfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
7070
void slotSpinBpmValueChanged(double value);
7171

7272
void slotKeyTextChanged();
73+
void slotTuningValueChanged(double value);
7374
void slotRatingChanged(int rating);
7475
void slotImportMetadataFromFile();
7576
void slotImportMetadataFromMusicBrainz();
@@ -97,6 +98,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
9798

9899
void updateKeyText();
99100
void displayKeyText();
101+
void displayTuningFields();
100102

101103
void updateFromTrack(const Track& track);
102104

src/library/dlgtrackinfo.ui

Lines changed: 121 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,17 @@
303303
</item>
304304

305305
<item row="5" column="2">
306-
<widget class="QLabel" name="lblKey">
306+
<widget class="QLabel" name="lblTrackNumber">
307307
<property name="text">
308-
<string>Key</string>
308+
<string>Track #</string>
309309
</property>
310310
<property name="alignment">
311311
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
312312
</property>
313313
</widget>
314314
</item>
315315
<item row="5" column="3">
316-
<widget class="QLineEdit" name="txtKey">
316+
<widget class="QLineEdit" name="txtTrackNumber">
317317
<property name="sizePolicy">
318318
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
319319
<horstretch>0</horstretch>
@@ -356,34 +356,125 @@
356356
</widget>
357357
</item>
358358

359-
<item row="6" column="2">
360-
<widget class="QLabel" name="lblTrackNumber">
359+
<item row="7" column="0">
360+
<widget class="QLabel" name="lblKey">
361361
<property name="text">
362-
<string>Track #</string>
362+
<string>Key</string>
363363
</property>
364364
<property name="alignment">
365365
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
366366
</property>
367367
</widget>
368368
</item>
369-
<item row="6" column="3">
370-
<widget class="QLineEdit" name="txtTrackNumber">
371-
<property name="sizePolicy">
372-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
373-
<horstretch>0</horstretch>
374-
<verstretch>0</verstretch>
375-
</sizepolicy>
369+
<item row="7" column="1">
370+
<widget class="QWidget">
371+
<layout class="QHBoxLayout" name="key_layout">
372+
373+
<item>
374+
<widget class="QLineEdit" name="txtKey">
375+
<property name="sizePolicy">
376+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
377+
<horstretch>1</horstretch>
378+
<verstretch>0</verstretch>
379+
</sizepolicy>
380+
</property>
381+
</widget>
382+
</item>
383+
<item>
384+
<spacer name="keyTuningSpacerItem">
385+
<property name="orientation">
386+
<enum>Qt::Horizontal</enum>
387+
</property>
388+
<property name="sizeType">
389+
<enum>QSizePolicy::Fixed</enum>
390+
</property>
391+
<property name="sizeHint" stdset="0">
392+
<size>
393+
<width>25</width>
394+
<height>0</height>
395+
</size>
396+
</property>
397+
</spacer>
398+
</item>
399+
<item>
400+
<widget class="QLabel" name="lblTuning">
401+
<property name="text">
402+
<string>Tuning</string>
403+
</property>
404+
<property name="alignment">
405+
<set>Qt::AlignRight|Qt::AlignVCenter</set>
406+
</property>
407+
</widget>
408+
</item>
409+
410+
<item>
411+
<widget class="QDoubleSpinBox" name="spinTuning">
412+
<property name="sizePolicy">
413+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
414+
<horstretch>1</horstretch>
415+
<verstretch>0</verstretch>
416+
</sizepolicy>
417+
</property>
418+
<property name="toolTip">
419+
<string>A4 tuning frequency in Hz. Standard tuning is 440 Hz.</string>
420+
</property>
421+
<property name="suffix">
422+
<string> Hz</string>
423+
</property>
424+
<property name="decimals">
425+
<number>1</number>
426+
</property>
427+
<property name="minimum">
428+
<double>400.000000000000000</double>
429+
</property>
430+
<property name="maximum">
431+
<double>480.000000000000000</double>
432+
</property>
433+
<property name="singleStep">
434+
<double>0.100000000000000</double>
435+
</property>
436+
<property name="value">
437+
<double>400.000000000000000</double>
438+
</property>
439+
<property name="specialValueText">
440+
<string/>
441+
</property>
442+
</widget>
443+
</item>
444+
445+
</layout>
446+
</widget>
447+
</item>
448+
449+
<item row="7" column="2">
450+
<widget class="QLabel" name="lblTuningCents">
451+
<property name="text">
452+
<string>Offset:</string>
376453
</property>
377-
<property name="minimumSize">
378-
<size>
379-
<width>0</width>
380-
<height>0</height>
381-
</size>
454+
<property name="alignment">
455+
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
456+
</property>
457+
</widget>
458+
</item>
459+
<item row="7" column="3">
460+
<widget class="QLabel" name="txtTuningCents">
461+
<property name="font">
462+
<font>
463+
<weight>75</weight>
464+
<bold>true</bold>
465+
</font>
466+
</property>
467+
<property name="text">
468+
<string/>
469+
</property>
470+
<property name="toolTip">
471+
<string>Offset from A440 standard tuning in cents.</string>
382472
</property>
383473
</widget>
384474
</item>
385475

386-
<item row="7" column="0">
476+
477+
<item row="8" column="0">
387478
<widget class="QLabel" name="lblTrackComment">
388479
<property name="text">
389480
<string>Comments</string>
@@ -393,15 +484,15 @@
393484
</property>
394485
</widget>
395486
</item>
396-
<item row="7" column="1" colspan="3">
487+
<item row="8" column="1" colspan="3">
397488
<widget class="QPlainTextEdit" name="txtComment">
398489
<property name="tabChangesFocus">
399490
<bool>true</bool>
400491
</property>
401492
</widget>
402493
</item>
403494

404-
<item row="8" column="0">
495+
<item row="9" column="0">
405496
<widget class="QLabel" name="lblTrackColor">
406497
<property name="text">
407498
<string>Color</string>
@@ -411,7 +502,7 @@
411502
</property>
412503
</widget>
413504
</item>
414-
<item row="8" column="1" colspan="3">
505+
<item row="9" column="1" colspan="3">
415506
<widget class="QPushButton" name="btnColorPicker">
416507
<property name="sizePolicy">
417508
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
@@ -421,7 +512,8 @@
421512
</property>
422513
</widget>
423514
</item>
424-
<item row="9" column="0">
515+
516+
<item row="10" column="0">
425517
<spacer name="horizontalSpacer_5">
426518
<property name="orientation">
427519
<enum>Qt::Horizontal</enum>
@@ -434,7 +526,8 @@
434526
</property>
435527
</spacer>
436528
</item>
437-
<item row="10" column="0" colspan="4">
529+
530+
<item row="11" column="0" colspan="4">
438531
<layout class="QHBoxLayout" name="meatdata_buttons_layout">
439532
<item>
440533
<widget class="QPushButton" name="btnImportMetadataFromMusicBrainz">
@@ -1095,12 +1188,13 @@ Often results in higher quality beatgrids, but will not do well on tracks that h
10951188
<tabstop>txtAlbum</tabstop>
10961189
<tabstop>txtAlbumArtist</tabstop>
10971190
<tabstop>txtComposer</tabstop>
1191+
<tabstop>txtYear</tabstop>
10981192
<tabstop>txtGenre</tabstop>
1193+
<tabstop>txtTrackNumber</tabstop>
10991194
<tabstop>txtGrouping</tabstop>
1100-
<tabstop>txtComment</tabstop>
1101-
<tabstop>txtYear</tabstop>
11021195
<tabstop>txtKey</tabstop>
1103-
<tabstop>txtTrackNumber</tabstop>
1196+
<tabstop>spinTuning</tabstop>
1197+
<tabstop>txtComment</tabstop>
11041198
<tabstop>btnColorPicker</tabstop>
11051199
<tabstop>btnImportMetadataFromMusicBrainz</tabstop>
11061200
<tabstop>btnImportMetadataFromFile</tabstop>

0 commit comments

Comments
 (0)