Skip to content

Commit

Permalink
Stop sample previews on mouse release or browser focus loss (#5764)
Browse files Browse the repository at this point in the history
Stop previews on mouse up and focus loss.
  • Loading branch information
Spekular committed Nov 8, 2020
1 parent a6e3958 commit 437172a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/FileBrowser.h
Expand Up @@ -108,6 +108,7 @@ class FileBrowserTreeWidget : public QTreeWidget
void keyPressEvent( QKeyEvent * ke ) override;
void keyReleaseEvent( QKeyEvent * ke ) override;
void hideEvent( QHideEvent * he ) override;
void focusOutEvent( QFocusEvent * fe ) override;


private:
Expand Down
28 changes: 12 additions & 16 deletions src/gui/FileBrowser.cpp
Expand Up @@ -433,6 +433,16 @@ void FileBrowserTreeWidget::hideEvent(QHideEvent* he)



void FileBrowserTreeWidget::focusOutEvent(QFocusEvent* fe)
{
// Cancel previews when the user clicks outside the browser
stopPreview();
QTreeWidget::focusOutEvent(fe);
}




void FileBrowserTreeWidget::contextMenuEvent(QContextMenuEvent * e )
{
FileItem * file = dynamic_cast<FileItem *>( itemAt( e->pos() ) );
Expand Down Expand Up @@ -674,22 +684,8 @@ void FileBrowserTreeWidget::mouseReleaseEvent(QMouseEvent * me )

QMutexLocker previewLocker(&m_pphMutex);

if (m_previewPlayHandle != nullptr)
{
// If less than 3 seconds remain of the sample, we don't
// stop them if the user releases mouse-button...
if (m_previewPlayHandle->type() == PlayHandle::TypeSamplePlayHandle)
{
SamplePlayHandle* s = dynamic_cast<SamplePlayHandle*>(m_previewPlayHandle);
auto second = static_cast<f_cnt_t>(Engine::mixer()->processingSampleRate());
if (s && s->totalFrames() - s->framesDone() <= second * 3)
{
s->setDoneMayReturnTrue(true);
}
else { stopPreview(); }
}
else { stopPreview(); }
}
//TODO: User setting to allow samples to play until completion instead
if (m_previewPlayHandle != nullptr) { stopPreview(); }
}


Expand Down

0 comments on commit 437172a

Please sign in to comment.