From 07caf85bf5f6ce3fce62ba29cca3cc61dd7f8c1d Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 10 Dec 2017 00:14:57 +0100 Subject: [PATCH] Remove GUI related code from Song::stop Add the new signal Song::stopped which is emitted when the song is stopped. Connect the new slot method MainWindow::onSongStopped to that signal. Remove all GUI updates from Song::stop and handle them in MainWindow::onSongStopped. --- include/MainWindow.h | 2 +- include/Song.h | 2 +- src/core/Song.cpp | 15 ++------------- src/gui/MainWindow.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index d60788a32..845a872ce 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -252,7 +252,7 @@ private slots: void onExportProject(); void onExportProjectTracks(); void onImportProject(); - + void onSongStopped(); signals: void periodicUpdate(); diff --git a/include/Song.h b/include/Song.h index b972761e3..fc4625eed 100644 --- a/include/Song.h +++ b/include/Song.h @@ -428,7 +428,7 @@ signals: void controllerAdded( Controller * ); void controllerRemoved( Controller * ); void updateSampleTracks(); - + void stopped(); } ; diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 2d25c3d24..9dc37a0b4 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -640,19 +640,13 @@ void Song::stop() m_paused = false; m_recording = true; - if( tl != NULL ) + if( tl ) { - switch( tl->behaviourAtStop() ) { case TimeLineWidget::BackToZero: m_playPos[m_playMode].setTicks(0); m_elapsedMilliSeconds[m_playMode] = 0; - if( gui && gui->songEditor() && - ( tl->autoScroll() == TimeLineWidget::AutoScrollEnabled ) ) - { - gui->songEditor()->m_editor->updatePosition(0); - } break; case TimeLineWidget::BackToStart: @@ -661,17 +655,11 @@ void Song::stop() m_playPos[m_playMode].setTicks(tl->savedPos().getTicks()); setToTime(tl->savedPos()); - if( gui && gui->songEditor() && - ( tl->autoScroll() == TimeLineWidget::AutoScrollEnabled ) ) - { - gui->songEditor()->m_editor->updatePosition( MidiTime(tl->savedPos().getTicks() ) ); - } tl->savePos( -1 ); } break; case TimeLineWidget::KeepStopPosition: - default: break; } } @@ -695,6 +683,7 @@ void Song::stop() m_playMode = Mode_None; + emit stopped(); emit playbackStateChanged(); } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 8adc538fe..954d9a5e8 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -63,6 +63,7 @@ #include "SideBar.h" #include "SongEditor.h" #include "TextFloat.h" +#include "TimeLineWidget.h" #include "ToolButton.h" #include "ToolPlugin.h" #include "VersionedSaveDialog.h" @@ -233,6 +234,8 @@ MainWindow::MainWindow() : connect( Engine::getSong(), SIGNAL( playbackStateChanged() ), this, SLOT( updatePlayPauseIcons() ) ); + + connect(Engine::getSong(), SIGNAL(stopped()), SLOT(onSongStopped())); } @@ -1764,3 +1767,39 @@ void MainWindow::onImportProject() song->setLoadOnLauch(false); } } + +void MainWindow::onSongStopped() +{ + Song * song = Engine::getSong(); + Song::PlayPos const & playPos = song->getPlayPos(); + + TimeLineWidget * tl = playPos.m_timeLine; + + if( tl ) + { + SongEditorWindow* songEditor = gui->songEditor(); + switch( tl->behaviourAtStop() ) + { + case TimeLineWidget::BackToZero: + if( songEditor && ( tl->autoScroll() == TimeLineWidget::AutoScrollEnabled ) ) + { + songEditor->m_editor->updatePosition(0); + } + break; + + case TimeLineWidget::BackToStart: + if( tl->savedPos() >= 0 ) + { + if(songEditor && ( tl->autoScroll() == TimeLineWidget::AutoScrollEnabled ) ) + { + songEditor->m_editor->updatePosition( MidiTime(tl->savedPos().getTicks() ) ); + } + tl->savePos( -1 ); + } + break; + + case TimeLineWidget::KeepStopPosition: + break; + } + } +}