Skip to content

Commit

Permalink
Merge pull request #14022 from daschuer/gh10890
Browse files Browse the repository at this point in the history
Key metadata track properties edit fix
  • Loading branch information
Swiftb0y authored Feb 24, 2025
2 parents 6a9dd27 + f0af653 commit 60d4617
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
24 changes: 8 additions & 16 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void DlgTrackInfo::saveTrack() {
// handlers manually to capture any changes. If the bpm or key was unchanged
// or invalid then the change will be ignored/rejected.
slotSpinBpmValueChanged(spinBpm->value());
static_cast<void>(updateKeyText()); // discard result
updateKeyText();

// Update the cached track
//
Expand Down Expand Up @@ -734,17 +734,12 @@ void DlgTrackInfo::slotSpinBpmValueChanged(double value) {
updateSpinBpmFromBeats();
}

mixxx::UpdateResult DlgTrackInfo::updateKeyText() {
const auto keyText = txtKey->text().trimmed();
const auto updateResult =
m_trackRecord.updateGlobalKeyNormalizeText(
keyText,
mixxx::track::io::key::USER);
if (updateResult == mixxx::UpdateResult::Rejected) {
// Restore the current key text
displayKeyText();
}
return updateResult;
void DlgTrackInfo::updateKeyText() {
const auto keyText = txtKey->text();
m_trackRecord.updateGlobalKeyNormalizeText(
keyText,
mixxx::track::io::key::USER);
displayKeyText();
}

void DlgTrackInfo::displayKeyText() {
Expand All @@ -758,10 +753,7 @@ void DlgTrackInfo::displayKeyText() {
}

void DlgTrackInfo::slotKeyTextChanged() {
if (updateKeyText() != mixxx::UpdateResult::Unchanged) {
// Ensure that the text field always reflects the actual value
displayKeyText();
}
updateKeyText();
}

void DlgTrackInfo::slotRatingChanged(int rating) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlgtrackinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
void clear();
void init();

mixxx::UpdateResult updateKeyText();
void updateKeyText();
void displayKeyText();

void updateFromTrack(const Track& track);
Expand Down
18 changes: 9 additions & 9 deletions src/library/dlgtrackinfomulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ void DlgTrackInfoMulti::saveTracks() {
rec.refMetadata().refTrackInfo().setYear(year);
}
if (!key.isNull()) {
static_cast<void>(rec.updateGlobalKeyNormalizeText(
rec.updateGlobalKeyNormalizeText(
key,
mixxx::track::io::key::USER));
mixxx::track::io::key::USER);
}
if (!num.isNull()) {
rec.refMetadata().refTrackInfo().setTrackNumber(num);
Expand Down Expand Up @@ -937,13 +937,13 @@ void DlgTrackInfoMulti::slotKeyTextChanged() {

const QString newTextInput = txtKey->currentText().trimmed();
QString newKeyText;
mixxx::track::io::key::ChromaticKey newKey =
KeyUtils::guessKeyFromText(newTextInput);
if (newKey != mixxx::track::io::key::INVALID) {
newKeyText = KeyUtils::keyToString(newKey);
} else if (newTextInput.isEmpty()) {
// Empty text is not a valid key but indicates we want to clear the key.
newKeyText = newTextInput;
// Empty text is not a valid key but indicates we want to clear the key.
if (!newTextInput.isEmpty()) {
mixxx::track::io::key::ChromaticKey newKey =
KeyUtils::guessKeyFromText(newTextInput);
if (newKey != mixxx::track::io::key::INVALID) {
newKeyText = KeyUtils::keyToString(newKey);
}
}

txtKey->blockSignals(true);
Expand Down
11 changes: 9 additions & 2 deletions src/track/trackrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ UpdateResult TrackRecord::updateGlobalKeyNormalizeText(
// Try to parse the input as a key.
mixxx::track::io::key::ChromaticKey newKey =
KeyUtils::guessKeyFromText(keyText);
if (newKey == mixxx::track::io::key::INVALID) {
if (newKey == mixxx::track::io::key::INVALID && !keyText.isEmpty()) {
// revert if we can't guess a valid key from it
return UpdateResult::Rejected;
}
Expand All @@ -48,7 +48,14 @@ UpdateResult TrackRecord::updateGlobalKeyNormalizeText(
return UpdateResult::Unchanged;
}

Keys newKeys = KeyFactory::makeBasicKeys(newKey, keySource);
Keys newKeys;
if (keySource == mixxx::track::io::key::FILE_METADATA) {
newKeys = KeyFactory::makeBasicKeysKeepText(
keyText,
mixxx::track::io::key::FILE_METADATA);
} else {
newKeys = KeyFactory::makeBasicKeys(newKey, keySource);
}
setKeys(newKeys);
return UpdateResult::Updated;
}
Expand Down
18 changes: 9 additions & 9 deletions src/track/trackrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class TrackDAO;
namespace mixxx {

/// Effect of updating a property with a new value.
enum class [[nodiscard]] UpdateResult{
/// The value has been updated and changed.
Updated,
enum class UpdateResult {
/// The value has been updated and changed.
Updated,

/// The value didn't change and has not been updated.
Unchanged,
/// The value didn't change and has not been updated.
Unchanged,

/// The provided value is invalid or insonsistent with
/// any existing value(s) and has been rejected, i.e.
/// the current value didn't change either.
Rejected,
/// The provided value is invalid or insonsistent with
/// any existing value(s) and has been rejected, i.e.
/// the current value didn't change either.
Rejected,
};

// Properties of tracks that are stored in the database.
Expand Down

0 comments on commit 60d4617

Please sign in to comment.