Skip to content

Commit

Permalink
HotcueControl: Add operations to control previewing
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Nov 28, 2020
1 parent e44d141 commit 4c2d90f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
48 changes: 22 additions & 26 deletions src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,14 +1095,13 @@ void CueControl::hotcueActivatePreview(HotcueControl* pControl, double value) {
CuePointer pCue(pControl->getCue());

if (value > 0) {
if (pCue && pCue->getPosition() != Cue::kNoPosition &&
pCue->getType() != mixxx::CueType::Invalid &&
pControl->getPreviewingType() == mixxx::CueType::Invalid) {
if (pCue &&
HotcueControl::canPreview(*pCue) &&
!pControl->isPreviewing()) {
m_iCurrentlyPreviewingHotcues++;
double position = pCue->getPosition();
m_bypassCueSetByPlay = true;
pControl->setPreviewingType(pCue->getType());
pControl->setPreviewingPosition(position);
pControl->startPreviewing(pCue->getType(), position);
if (pCue->getType() == mixxx::CueType::Loop) {
setCurrentSavedLoopControlAndActivate(pControl);
} else if (pControl->getStatus() == HotcueControl::Status::Set) {
Expand All @@ -1115,29 +1114,26 @@ void CueControl::hotcueActivatePreview(HotcueControl* pControl, double value) {
seekAbs(position);
m_pPlay->set(1.0);
}
} else if (m_iCurrentlyPreviewingHotcues) {
// This is a activate release and we are previewing at least one
// hotcue. If this hotcue is previewing:
mixxx::CueType cueType = pControl->getPreviewingType();
if (cueType != mixxx::CueType::Invalid) {
// If this is the last hotcue to leave preview.
if (--m_iCurrentlyPreviewingHotcues == 0 && !m_bPreviewing) {
// Mark this hotcue as not previewing.
double position = pControl->getPreviewingPosition();
pControl->setPreviewingType(mixxx::CueType::Invalid);
pControl->setPreviewingPosition(Cue::kNoPosition);
} else if (pControl->isPreviewing() &&
// If this is the last hotcue to leave preview
m_iCurrentlyPreviewingHotcues > Cue::kFirstHotCue &&
--m_iCurrentlyPreviewingHotcues == Cue::kFirstHotCue &&
// This is a activate release and we are previewing at least one
// hotcue. If this hotcue is previewing:
!m_bPreviewing) {
// Mark this hotcue as not previewing.
double position = pControl->getPreviewingPosition();
pControl->stopPreviewing();

m_pPlay->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
if (cueType == mixxx::CueType::Loop) {
m_pLoopEnabled->set(0);
} else if (pControl->getStatus() == HotcueControl::Status::Active) {
pControl->setStatus(HotcueControl::Status::Set);
}
seekExact(position);
}
m_pPlay->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
if (pControl->getPreviewingType() == mixxx::CueType::Loop) {
m_pLoopEnabled->set(0);
} else if (pControl->getStatus() == HotcueControl::Status::Active) {
pControl->setStatus(HotcueControl::Status::Set);
}
seekExact(position);
}
setHotcueFocusIndex(pControl->getHotcueIndex());
}
Expand Down
26 changes: 20 additions & 6 deletions src/engine/controls/cuecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,32 @@ class HotcueControl : public QObject {
mixxx::RgbColor::optional_t getColor() const;

// Used for caching the preview state of this hotcue control.
mixxx::CueType getPreviewingType() const {
return m_previewingType;
static bool canPreview(const Cue& cue) {
return cue.getType() != mixxx::CueType::Invalid &&
cue.getPosition() != Cue::kNoPosition;
}
bool isPreviewing() const {
return m_previewingType != mixxx::CueType::Invalid &&
m_previewingPosition != Cue::kNoPosition;
}
void setPreviewingType(mixxx::CueType type) {
void startPreviewing(mixxx::CueType type, double position) {
m_previewingType = type;
m_previewingPosition = position;
DEBUG_ASSERT(isPreviewing());
}
void stopPreviewing() {
m_previewingType = mixxx::CueType::Invalid;
m_previewingPosition = Cue::kNoPosition;
DEBUG_ASSERT(!isPreviewing());
}
mixxx::CueType getPreviewingType() const {
DEBUG_ASSERT(isPreviewing());
return m_previewingType;
}
double getPreviewingPosition() const {
DEBUG_ASSERT(isPreviewing());
return m_previewingPosition;
}
void setPreviewingPosition(double position) {
m_previewingPosition = position;
}

private slots:
void slotHotcueSet(double v);
Expand Down

0 comments on commit 4c2d90f

Please sign in to comment.