Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track menu: enable Lock BPM action if any selected track BPM is unlocked #12385

Merged
merged 1 commit into from Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/widget/wtrackmenu.cpp
Expand Up @@ -660,23 +660,29 @@ void WTrackMenu::setupActions() {
}
}

bool WTrackMenu::isAnyTrackBpmLocked() const {
std::pair<bool, bool> WTrackMenu::getTrackBpmLockStates() const {
bool anyBpmLocked = false;
bool anyBpmNotLocked = false;
if (m_pTrackModel) {
const int column =
m_pTrackModel->fieldIndex(LIBRARYTABLE_BPM_LOCK);
const int column = m_pTrackModel->fieldIndex(LIBRARYTABLE_BPM_LOCK);
for (const auto& trackIndex : m_trackIndexList) {
QModelIndex bpmLockedIndex =
trackIndex.sibling(trackIndex.row(), column);
QModelIndex bpmLockedIndex = trackIndex.sibling(trackIndex.row(), column);
if (bpmLockedIndex.data().toBool()) {
return true;
anyBpmLocked = true;
} else {
anyBpmNotLocked = true;
}
if (anyBpmLocked && anyBpmNotLocked) {
break;
}
}
} else {
if (m_pTrack && m_pTrack->isBpmLocked()) {
return true;
if (m_pTrack) {
anyBpmLocked = m_pTrack->isBpmLocked();
anyBpmNotLocked = !anyBpmLocked;
}
}
return false;
return std::pair<bool, bool>(anyBpmLocked, anyBpmNotLocked);
}

std::optional<std::optional<mixxx::RgbColor>> WTrackMenu::getCommonTrackColor() const {
Expand Down Expand Up @@ -875,13 +881,15 @@ void WTrackMenu::updateMenus() {

if (featureIsEnabled(Feature::Reset) ||
featureIsEnabled(Feature::BPM)) {
const bool anyBpmLocked = isAnyTrackBpmLocked();
bool anyBpmLocked;
bool anyBpmNotLocked;
std::tie(anyBpmLocked, anyBpmNotLocked) = getTrackBpmLockStates();
if (featureIsEnabled(Feature::Reset)) {
m_pClearBeatsAction->setEnabled(!anyBpmLocked);
}
if (featureIsEnabled(Feature::BPM)) {
m_pBpmUnlockAction->setEnabled(anyBpmLocked);
m_pBpmLockAction->setEnabled(!anyBpmLocked);
m_pBpmLockAction->setEnabled(anyBpmNotLocked);
m_pBpmDoubleAction->setEnabled(!anyBpmLocked);
m_pBpmHalveAction->setEnabled(!anyBpmLocked);
m_pBpmTwoThirdsAction->setEnabled(!anyBpmLocked);
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wtrackmenu.h
Expand Up @@ -201,7 +201,7 @@ class WTrackMenu : public QMenu {
void loadSelectionToGroup(const QString& group, bool play = false);
void clearTrackSelection();

bool isAnyTrackBpmLocked() const;
std::pair<bool, bool> getTrackBpmLockStates() const;

/// Get the common track color of all tracks this menu is shown for, or
/// return `nullopt` if there is no common color. Tracks may have no color
Expand Down