From 750fc34faca9a02368e7fec5aaf31717588be572 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 25 Jun 2017 01:33:31 -0400 Subject: [PATCH] Clarify what the TrackList events are for... Also fixes this bug: Vertical rulers did not narrow as needed after deletion of the lowest track. --- src/Project.cpp | 10 ++++----- src/Project.h | 2 +- src/Track.cpp | 51 +++++++++++++++++----------------------------- src/Track.h | 19 +++++++---------- src/TrackPanel.cpp | 31 +++++++++++++--------------- src/TrackPanel.h | 4 ++-- 6 files changed, 48 insertions(+), 69 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 37a423537..d870ff7e1 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -944,8 +944,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, mLastSavedTracks = NULL; // Register for tracklist updates - mTracks->Connect(EVT_TRACKLIST_UPDATED, - wxCommandEventHandler(AudacityProject::OnTrackListUpdated), + mTracks->Connect(EVT_TRACKLIST_DELETION, + wxCommandEventHandler(AudacityProject::OnTrackListDeletion), NULL, this); @@ -2222,7 +2222,7 @@ void AudacityProject::OnToolBarUpdate(wxCommandEvent & event) } // The projects tracklist has been updated -void AudacityProject::OnTrackListUpdated(wxCommandEvent & event) +void AudacityProject::OnTrackListDeletion(wxCommandEvent & event) { GetSelectionState().TrackListUpdated( *GetTracks() ); @@ -2694,8 +2694,8 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event) mImportXMLTagHandler.reset(); // Unregister for tracklist updates - mTracks->Disconnect(EVT_TRACKLIST_UPDATED, - wxCommandEventHandler(AudacityProject::OnTrackListUpdated), + mTracks->Disconnect(EVT_TRACKLIST_DELETION, + wxCommandEventHandler(AudacityProject::OnTrackListDeletion), NULL, this); diff --git a/src/Project.h b/src/Project.h index fcb152e1a..f21b5fbc0 100644 --- a/src/Project.h +++ b/src/Project.h @@ -355,7 +355,7 @@ public: void OnOpenAudioFile(wxCommandEvent & event); void OnODTaskUpdate(wxCommandEvent & event); void OnODTaskComplete(wxCommandEvent & event); - void OnTrackListUpdated(wxCommandEvent & event); + void OnTrackListDeletion(wxCommandEvent & event); void HandleResize(); void UpdateLayout(); diff --git a/src/Track.cpp b/src/Track.cpp index 21f3fe5ea..d268906a9 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -212,7 +212,7 @@ void Track::SetHeight(int h) mHeight = h; if (mList) { mList->RecalcPositions(mNode); - mList->ResizedEvent(mNode); + mList->ResizingEvent(mNode); } } #endif // EXPERIMENTAL_OUTPUT_DISPLAY @@ -227,7 +227,7 @@ void Track::SetMinimized(bool isMinimized) mMinimized = isMinimized; if (mList) { mList->RecalcPositions(mNode); - mList->ResizedEvent(mNode); + mList->ResizingEvent(mNode); } } @@ -236,7 +236,7 @@ void Track::SetLinked(bool l) mLinked = l; if (mList) { mList->RecalcPositions(mNode); - mList->ResizedEvent(mNode); + mList->ResizingEvent(mNode); } } @@ -739,12 +739,12 @@ Track *SyncLockedTracksIterator::Last(bool skiplinked) // TrackList // -// The TrackList sends itself events whenever an update occurs to the list it +// The TrackList sends events whenever certain updates occur to the list it // is managing. Any other classes that may be interested in get these updates // should use TrackList::Connect() and TrackList::Disconnect(). // -DEFINE_EVENT_TYPE(EVT_TRACKLIST_RESIZED); -DEFINE_EVENT_TYPE(EVT_TRACKLIST_UPDATED); +DEFINE_EVENT_TYPE(EVT_TRACKLIST_RESIZING); +DEFINE_EVENT_TYPE(EVT_TRACKLIST_DELETION); TrackList::TrackList() : wxEvtHandler() @@ -858,28 +858,21 @@ void TrackList::RecalcPositions(TrackNodePointer node) #endif // EXPERIMENTAL_OUTPUT_DISPLAY } -void TrackList::UpdatedEvent(TrackNodePointer node) +void TrackList::DeletionEvent() { - wxCommandEvent e(EVT_TRACKLIST_UPDATED); - if (!isNull(node)) { - e.SetClientData(node->get()); - } - else { - e.SetClientData(NULL); - } + wxCommandEvent e(EVT_TRACKLIST_DELETION); // PRL: ProcessEvent, not QueueEvent! Listeners may need their last // chance to examine some removed tracks that are about to be destroyed. ProcessEvent(e); } -void TrackList::ResizedEvent(TrackNodePointer node) +void TrackList::ResizingEvent(TrackNodePointer node) { - if (!isNull(node)) { - wxCommandEvent e(EVT_TRACKLIST_RESIZED); + wxCommandEvent e(EVT_TRACKLIST_RESIZING); + if (!isNull(node)) e.SetClientData(node->get()); - ProcessEvent(e); - } + ProcessEvent(e); } void TrackList::Permute(const std::vector &permutation) @@ -892,8 +885,6 @@ void TrackList::Permute(const std::vector &permutation) } auto n = begin(); RecalcPositions(n); - UpdatedEvent(n); - ResizedEvent(n); } template @@ -905,7 +896,7 @@ Track *TrackList::Add(std::unique_ptr &&t) --n; pTrack->SetOwner(this, n); RecalcPositions(n); - UpdatedEvent(n); + ResizingEvent(n); return back().get(); } @@ -926,8 +917,7 @@ Track *TrackList::AddToHead(std::unique_ptr &&t) auto n = begin(); pTrack->SetOwner(this, n); RecalcPositions(n); - UpdatedEvent(n); - ResizedEvent(n); + ResizingEvent(n); return front().get(); } @@ -942,7 +932,7 @@ Track *TrackList::Add(std::shared_ptr &&t) --n; t->SetOwner(this, n); RecalcPositions(n); - UpdatedEvent(n); + ResizingEvent(n); return back().get(); } @@ -964,8 +954,8 @@ auto TrackList::Replace(Track * t, value_type &&with) -> value_type // PRL: Note: Send the event while t (now in holder) is not yet // destroyed, so pointers to t that listeners may have are not dangling. - UpdatedEvent(node); - ResizedEvent(node); + DeletionEvent(); + ResizingEvent(node); } return holder; } @@ -986,8 +976,7 @@ TrackNodePointer TrackList::Remove(Track *t) // PRL: Note: Send the event while t (now in holder) is not yet // destroyed, so pointers to t that listeners may have are not dangling. - UpdatedEvent(end()); - ResizedEvent(result); + DeletionEvent(); } } return result; @@ -1001,7 +990,7 @@ void TrackList::Clear(bool sendEvent) // PRL: Note: Send the event while tempList is not yet // destroyed, so pointers to tracks that listeners may have are not // dangling. - UpdatedEvent(end()); + DeletionEvent(); } void TrackList::Select(Track * t, bool selected /* = true */ ) @@ -1170,8 +1159,6 @@ void TrackList::SwapNodes(TrackNodePointer s1, TrackNodePointer s2) // Now correct the Index in the tracks, and other things RecalcPositions(s1); - UpdatedEvent(s1); - ResizedEvent(s1); } bool TrackList::MoveUp(Track * t) diff --git a/src/Track.h b/src/Track.h index cf99dc71a..351a9fea5 100644 --- a/src/Track.h +++ b/src/Track.h @@ -462,21 +462,16 @@ class AUDACITY_DLL_API SyncLockedTracksIterator final : public TrackListIterator * Clear, and Contains, plus serialization of the list of tracks. */ -// Posted when the horizontal positions within tracks have beed updated. The -// wxCommandEvent::GetClientData() method can be used to retrieve the first -// track that was updated. All positions following that track will have been -// updated as well. -DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACKLIST_RESIZED, -1); +// Posted when some track was added or changed its height. +// The wxCommandEvent::GetClientData() method can be used to retrieve it. +DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACKLIST_RESIZING, -1); -// Posted when tracks have been added or deleted from a tracklist. The pointer -// wxCommandEvent::GetClientData() returns will be NULL for deletions or the -// track that was added. +// Posted when a track has been deleted from a tracklist. // Also posted when one track replaces another -// Also posted when the list of tracks is permuted, but no addition or deletion // When a track has been removed, the event is processed before the track // is destroyed, so that listeners that stored a pointer to the track can still // use it and correctly check whether the list still contains it. -DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACKLIST_UPDATED, -1); +DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACKLIST_DELETION, -1); class TrackList final : public wxEvtHandler, public ListOfTracks { @@ -594,8 +589,8 @@ private: void DoAssign(const TrackList &that); void RecalcPositions(TrackNodePointer node); - void UpdatedEvent(TrackNodePointer node); - void ResizedEvent(TrackNodePointer node); + void DeletionEvent(); + void ResizingEvent(TrackNodePointer node); void SwapNodes(TrackNodePointer s1, TrackNodePointer s2); }; diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 10e63430b..c4d8940cc 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -341,12 +341,12 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id, GetProject()->Bind(wxEVT_IDLE, &TrackPanel::OnIdle, this); // Register for tracklist updates - mTracks->Connect(EVT_TRACKLIST_RESIZED, - wxCommandEventHandler(TrackPanel::OnTrackListResized), + mTracks->Connect(EVT_TRACKLIST_RESIZING, + wxCommandEventHandler(TrackPanel::OnTrackListResizing), NULL, this); - mTracks->Connect(EVT_TRACKLIST_UPDATED, - wxCommandEventHandler(TrackPanel::OnTrackListUpdated), + mTracks->Connect(EVT_TRACKLIST_DELETION, + wxCommandEventHandler(TrackPanel::OnTrackListDeletion), NULL, this); wxTheApp->Connect(EVT_AUDIOIO_PLAYBACK, @@ -361,12 +361,12 @@ TrackPanel::~TrackPanel() mTimer.Stop(); // Unregister for tracklist updates - mTracks->Disconnect(EVT_TRACKLIST_UPDATED, - wxCommandEventHandler(TrackPanel::OnTrackListUpdated), + mTracks->Disconnect(EVT_TRACKLIST_DELETION, + wxCommandEventHandler(TrackPanel::OnTrackListDeletion), NULL, this); - mTracks->Disconnect(EVT_TRACKLIST_RESIZED, - wxCommandEventHandler(TrackPanel::OnTrackListResized), + mTracks->Disconnect(EVT_TRACKLIST_RESIZING, + wxCommandEventHandler(TrackPanel::OnTrackListResizing), NULL, this); wxTheApp->Disconnect(EVT_AUDIOIO_PLAYBACK, @@ -987,16 +987,15 @@ void TrackPanel::OnPlayback(wxCommandEvent &e) // The tracks positions within the list have changed, so update the vertical // ruler size for the track that triggered the event. -void TrackPanel::OnTrackListResized(wxCommandEvent & e) +void TrackPanel::OnTrackListResizing(wxCommandEvent & e) { Track *t = (Track *) e.GetClientData(); UpdateVRuler(t); e.Skip(); } -// Tracks have been added or removed from the list. Handle adds as if -// a resize has taken place. -void TrackPanel::OnTrackListUpdated(wxCommandEvent & e) +// Tracks have been removed from the list. +void TrackPanel::OnTrackListDeletion(wxCommandEvent & e) { if (mUIHandle) mUIHandle->OnProjectChange(GetProject()); @@ -1006,10 +1005,7 @@ void TrackPanel::OnTrackListUpdated(wxCommandEvent & e) SetFocusedTrack(NULL); } - if (e.GetClientData()) { - OnTrackListResized(e); - return; - } + UpdateVRulerSize(); e.Skip(); } @@ -2275,7 +2271,8 @@ void TrackPanel::UpdateVRulers() void TrackPanel::UpdateVRuler(Track *t) { - UpdateTrackVRuler(t); + if (t) + UpdateTrackVRuler(t); UpdateVRulerSize(); } diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 9dd93c36d..6e64e4303 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -279,8 +279,8 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel { void OnContextMenu(wxContextMenuEvent & event); void OnPlayback(wxCommandEvent &); - void OnTrackListResized(wxCommandEvent & event); - void OnTrackListUpdated(wxCommandEvent & event); + void OnTrackListResizing(wxCommandEvent & event); + void OnTrackListDeletion(wxCommandEvent & event); void UpdateViewIfNoTracks(); // Call this to update mViewInfo, etc, after track(s) removal, before Refresh(). double GetMostRecentXPos();