From 0187e64ceb681ffb92663baa164a14e878104dcd Mon Sep 17 00:00:00 2001 From: regulus79 <117475203+regulus79@users.noreply.github.com> Date: Wed, 3 Dec 2025 16:29:12 -0500 Subject: [PATCH] Fix Track Moving not Updating PatternClipView (#8155) This bug was noticed when testing out #7559, but the PR had been open for over a year, so it was decided to merge it and fix it in this one. Basically, when adding or removing a track, the TrackContainer sends out signals such as trackAdded or trackRemoved which PatternClipView uses to know when to update. However, it does not send out a signal when a track has been moved. This is because for some reason, it's done by the GUI TrackContainerView instead of the core TrackContainer. This PR changes that by moving the core code to the core where it probably belongs, adding an appropriate trackMoved signal to TrackContainer, and connecting that to PatternClipView to update properly. --------- Co-authored-by: Fawn --- include/TrackContainer.h | 2 ++ src/core/TrackContainer.cpp | 7 +++++++ src/gui/clips/PatternClipView.cpp | 2 ++ src/gui/editors/TrackContainerView.cpp | 6 ++---- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/TrackContainer.h b/include/TrackContainer.h index 797b47289..4ffa0ad66 100644 --- a/include/TrackContainer.h +++ b/include/TrackContainer.h @@ -68,6 +68,7 @@ public: void addTrack( Track * _track ); void removeTrack( Track * _track ); + void moveTrack(Track* track, int indexTo); virtual void updateAfterTrackAdd(); @@ -100,6 +101,7 @@ public: signals: void trackAdded( lmms::Track * _track ); void trackRemoved(); + void trackMoved(); protected: static AutomatedValueMap automatedValuesFromTracks(const TrackList &tracks, TimePos timeStart, int clipNum = -1); diff --git a/src/core/TrackContainer.cpp b/src/core/TrackContainer.cpp index 5a68ac8db..7005362ca 100644 --- a/src/core/TrackContainer.cpp +++ b/src/core/TrackContainer.cpp @@ -214,6 +214,13 @@ void TrackContainer::removeTrack( Track * _track ) } } +void TrackContainer::moveTrack(Track* track, int indexTo) +{ + m_tracks.erase(std::find(m_tracks.begin(), m_tracks.end(), track)); + m_tracks.insert(m_tracks.begin() + indexTo, track); + + emit trackMoved(); +} diff --git a/src/gui/clips/PatternClipView.cpp b/src/gui/clips/PatternClipView.cpp index 1dd8ad683..a08d67172 100644 --- a/src/gui/clips/PatternClipView.cpp +++ b/src/gui/clips/PatternClipView.cpp @@ -54,6 +54,8 @@ PatternClipView::PatternClipView(Clip* _clip, TrackView* _tv) : this, &PatternClipView::update); connect(Engine::patternStore(), &TrackContainer::trackRemoved, this, &PatternClipView::update); + connect(Engine::patternStore(), &TrackContainer::trackMoved, + this, &PatternClipView::update); setStyle( QApplication::style() ); } diff --git a/src/gui/editors/TrackContainerView.cpp b/src/gui/editors/TrackContainerView.cpp index e85f4e866..1747e671d 100644 --- a/src/gui/editors/TrackContainerView.cpp +++ b/src/gui/editors/TrackContainerView.cpp @@ -199,13 +199,11 @@ void TrackContainerView::moveTrackView( TrackView * trackView, int indexTo ) PatternTrack::swapPatternTracks( trackView->getTrack(), m_trackViews[indexTo]->getTrack() ); + m_tc->moveTrack(trackView->getTrack(), indexTo); + m_scrollLayout->removeWidget( trackView ); m_scrollLayout->insertWidget( indexTo, trackView ); - Track * track = m_tc->m_tracks[indexFrom]; - - m_tc->m_tracks.erase(m_tc->m_tracks.begin() + indexFrom); - m_tc->m_tracks.insert(m_tc->m_tracks.begin() + indexTo, track); m_trackViews.move( indexFrom, indexTo ); realignTracks();