Skip to content

Commit

Permalink
Fix check for unrelated decks playing when starting Auto DJ
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 13, 2024
1 parent f873f54 commit 6163754
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,20 @@ AutoDJProcessor::AutoDJError AutoDJProcessor::toggleAutoDJ(bool enable) {
return ADJ_BOTH_DECKS_PLAYING;
}

// TODO: This is a total bandaid for making Auto DJ work with decks 3
// and 4. We should design a nicer way to handle this.
for (int i = 2; i < m_decks.length(); ++i) {
if (m_decks[i] && m_decks[i]->isPlaying()) {
// TODO: This is a total bandaid for making Auto DJ work with four decks.
// We should design a nicer way to handle this.
for (const auto& pDeck : std::as_const(m_decks)) {
if (pDeck == pLeftDeck) {
continue;
}
if (pDeck == pRightDeck) {
continue;
}
if (pDeck->isPlaying()) {
// Keep the current state.
emitAutoDJStateChanged(m_eState);
emit autoDJError(ADJ_DECKS_3_4_PLAYING);
return ADJ_DECKS_3_4_PLAYING;
emit autoDJError(ADJ_UNUSED_DECK_PLAYING);
return ADJ_UNUSED_DECK_PLAYING;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/autodj/autodjprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class AutoDJProcessor : public QObject {
ADJ_IS_INACTIVE,
ADJ_QUEUE_EMPTY,
ADJ_BOTH_DECKS_PLAYING,
ADJ_DECKS_3_4_PLAYING,
ADJ_UNUSED_DECK_PLAYING,
ADJ_NOT_TWO_DECKS
};

Expand Down
4 changes: 2 additions & 2 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ void DlgAutoDJ::autoDJError(AutoDJProcessor::AutoDJError error) {
tr("One deck must be stopped to enable Auto DJ mode."),
QMessageBox::Ok);
break;
case AutoDJProcessor::ADJ_DECKS_3_4_PLAYING:
case AutoDJProcessor::ADJ_UNUSED_DECK_PLAYING:
QMessageBox::warning(nullptr,
tr("Auto DJ"),
tr("Decks 3 and 4 must be stopped to enable Auto DJ mode."),
tr("Decks not used for Auto DJ must be stopped to enable Auto DJ mode."),
QMessageBox::Ok);
break;
case AutoDJProcessor::ADJ_OK:
Expand Down
4 changes: 2 additions & 2 deletions src/test/autodjprocessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,12 @@ TEST_F(AutoDJProcessorTest, DecksPlayingWarning) {
TEST_F(AutoDJProcessorTest, Decks34PlayingWarning) {
deck3.play.set(1);
AutoDJProcessor::AutoDJError err = pProcessor->toggleAutoDJ(true);
EXPECT_EQ(AutoDJProcessor::ADJ_DECKS_3_4_PLAYING, err);
EXPECT_EQ(AutoDJProcessor::ADJ_UNUSED_DECK_PLAYING, err);

deck3.play.set(0);
deck4.play.set(1);
err = pProcessor->toggleAutoDJ(true);
EXPECT_EQ(AutoDJProcessor::ADJ_DECKS_3_4_PLAYING, err);
EXPECT_EQ(AutoDJProcessor::ADJ_UNUSED_DECK_PLAYING, err);
}

TEST_F(AutoDJProcessorTest, QueueEmpty) {
Expand Down

0 comments on commit 6163754

Please sign in to comment.