Skip to content

Commit

Permalink
ControllerEngine: stop scratching if no track is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Mar 29, 2022
1 parent 6ebce1b commit 7148301
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/controllers/controllerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,18 @@ void ControllerEngine::stopDeck(const QString& group) {
pPlay->set(0.0);
}

bool ControllerEngine::isTrackLoaded(const QString& group) {
ControlObjectScript* pTrackLoaded = getControlObjectScript(group, "track_loaded");

if (pTrackLoaded == nullptr) {
QString error = QString("Could not getControlObjectScript()");
scriptErrorDialog(error, error);
return false;
}

return pTrackLoaded->get() > 0.0;
}

/* -------- ------------------------------------------------------
Purpose: Enables scratching for relative controls
Input: Virtual deck to scratch,
Expand Down Expand Up @@ -1359,7 +1371,6 @@ void ControllerEngine::scratchTick(int deck, int interval) {
Output: -
-------- ------------------------------------------------------ */
void ControllerEngine::scratchProcess(int timerId) {
// TODO(ronso0) Refuse scratching if no track is loaded
int deck = m_scratchTimers[timerId];
// PlayerManager::groupForDeck is 0-indexed.
QString group = PlayerManager::groupForDeck(deck - 1);
Expand Down Expand Up @@ -1415,7 +1426,9 @@ void ControllerEngine::scratchProcess(int timerId) {
(m_brakeActive[deck] && newRate < m_rampTo[deck]) ||
((m_spinbackActive[deck] || m_softStartActive[deck]) && newRate > m_rampTo[deck]) ||
// or if the deck was stopped manually during brake or softStart
((m_brakeActive[deck] || m_softStartActive[deck]) && (!isDeckPlaying(group)))) {
((m_brakeActive[deck] || m_softStartActive[deck]) && (!isDeckPlaying(group))) ||
// or if there is track loaded (anymore)
!isTrackLoaded(group)) {
// Not ramping no mo'
m_ramp[deck] = false;

Expand Down
1 change: 1 addition & 0 deletions src/controllers/controllerengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class ControllerEngine : public QObject {

bool isDeckPlaying(const QString& group);
void stopDeck(const QString& group);
bool isTrackLoaded(const QString& group);
double getDeckRate(const QString& group);

Controller* m_pController;
Expand Down

0 comments on commit 7148301

Please sign in to comment.