From 961d8cdeca2455e937383c410b0b9dac13bc85d2 Mon Sep 17 00:00:00 2001 From: "v.audacity" Date: Mon, 30 Aug 2010 03:24:40 +0000 Subject: [PATCH] Review calls to AudacityProject::ModifyState() and TrackPanel::MakeParentModifyState() to possibly add param to make AudacityProject::ModifyState() optionally not call AutoSave(). There is only one place (TrackPanel::OnSetDisplay()) where autosave is definitely not necessary, so don't change it now. Also made a few places (e.g., AudacityProject::OnSetLeftSelection()) call AudacityProject::ModifyState() only if the selection actually changed. --- src/Menus.cpp | 129 +++++++++++++++++++++++++-------------------- src/Project.cpp | 2 + src/TrackPanel.cpp | 4 +- 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index f41c7415b..7e79fb803 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -1279,8 +1279,8 @@ void AudacityProject::RebuildMenuBar() // sync with wxWidgets idea of what it should be. #if defined(__WXMAC__) && defined(__WXDEBUG__) { - wxDialog *d = wxDynamicCast(wxGetTopLevelParent(FindFocus()), wxDialog); - wxASSERT((!d || !d->IsModal())); + wxDialog *dlg = wxDynamicCast(wxGetTopLevelParent(FindFocus()), wxDialog); + wxASSERT((!dlg || !dlg->IsModal())); } #endif @@ -1889,9 +1889,8 @@ void AudacityProject::OnStopSelect() mViewInfo.sel1 = mViewInfo.sel0; } GetControlToolBar()->OnStop(evt); + ModifyState(); } - - ModifyState(); } void AudacityProject::OnToggleSoundActivated() @@ -2186,73 +2185,87 @@ void AudacityProject::OnSelContractRight() //the current play position. void AudacityProject::OnSetLeftSelection() { - if (GetAudioIOToken()>0 && - gAudioIO->IsStreamActive(GetAudioIOToken())) - { - double indicator = gAudioIO->GetStreamTime(); - mViewInfo.sel0 = indicator; - } + bool bSelChanged = false; + if ((GetAudioIOToken() > 0) && gAudioIO->IsStreamActive(GetAudioIOToken())) + { + double indicator = gAudioIO->GetStreamTime(); + mViewInfo.sel0 = indicator; + bSelChanged = true; + } else + { + TimeDialog dlg(this, _("Set Left Selection Boundary"), _("Position")); + wxString fmt = gPrefs->Read(wxT("/SelectionFormat"), wxT("")); + dlg.SetFormatString(fmt); + dlg.SetSampleRate(mRate); + dlg.SetTimeValue(mViewInfo.sel0); + if (wxID_OK == dlg.ShowModal()) { - wxString fmt = gPrefs->Read(wxT("/SelectionFormat"), wxT("")); + //Get the value from the dialog + mViewInfo.sel0 = dlg.GetTimeValue(); + + //Make sure it is 'legal' + if (mViewInfo.sel0 < 0.0) + mViewInfo.sel0 = 0.0; - TimeDialog D(this, _("Set Left Selection Boundary"), _("Position")); - D.SetSampleRate(mRate); - D.SetFormatString(fmt); - D.SetTimeValue(mViewInfo.sel0); - if(wxID_OK==D.ShowModal() ) - { - //Get the value from the dialog - mViewInfo.sel0 = D.GetTimeValue(); - - //Make sure it is 'legal' - if(mViewInfo.sel0 < 0.0) - mViewInfo.sel0 = 0.0; - } + bSelChanged = true; } + } - if(mViewInfo.sel1 < mViewInfo.sel0) + if (mViewInfo.sel1 < mViewInfo.sel0) + { mViewInfo.sel1 = mViewInfo.sel0; + bSelChanged = true; + } - ModifyState(); - - mTrackPanel->Refresh(false); + if (bSelChanged) + { + ModifyState(); + mTrackPanel->Refresh(false); + } } void AudacityProject::OnSetRightSelection() { - if (GetAudioIOToken()>0 && - gAudioIO->IsStreamActive(GetAudioIOToken())) - { - double indicator = gAudioIO->GetStreamTime(); - mViewInfo.sel1 = indicator; - } + bool bSelChanged = false; + if ((GetAudioIOToken() > 0) && gAudioIO->IsStreamActive(GetAudioIOToken())) + { + double indicator = gAudioIO->GetStreamTime(); + mViewInfo.sel1 = indicator; + bSelChanged = true; + } else + { + TimeDialog dlg(this, _("Set Right Selection Boundary"), _("Position")); + wxString fmt = gPrefs->Read(wxT("/SelectionFormat"), wxT("")); + dlg.SetFormatString(fmt); + dlg.SetSampleRate(mRate); + dlg.SetTimeValue(mViewInfo.sel1); + if (wxID_OK == dlg.ShowModal()) { - wxString fmt = gPrefs->Read(wxT("/SelectionFormat"), wxT("")); + //Get the value from the dialog + mViewInfo.sel1 = dlg.GetTimeValue(); + + //Make sure it is 'legal' + if(mViewInfo.sel1 < 0) + mViewInfo.sel1 = 0; - TimeDialog D(this, _("Set Right Selection Boundary"), _("Position")); - D.SetSampleRate(mRate); - D.SetFormatString(fmt); - D.SetTimeValue(mViewInfo.sel1); - if(wxID_OK==D.ShowModal() ) - { - //Get the value from the dialog - mViewInfo.sel1 = D.GetTimeValue(); - - //Make sure it is 'legal' - if(mViewInfo.sel1 < 0) - mViewInfo.sel1 = 0; - } + bSelChanged = true; } + } - if(mViewInfo.sel0 > mViewInfo.sel1) + if (mViewInfo.sel0 > mViewInfo.sel1) + { mViewInfo.sel0 = mViewInfo.sel1; + bSelChanged = true; + } - ModifyState(); - - mTrackPanel->Refresh(false); + if (bSelChanged) + { + ModifyState(); + mTrackPanel->Refresh(false); + } } void AudacityProject::NextFrame() @@ -5167,9 +5180,9 @@ void AudacityProject::OnAddLabelPlaying() void AudacityProject::OnEditLabels() { - LabelDialog d(this, mDirManager, mTracks, mViewInfo, mRate); + LabelDialog dlg(this, mDirManager, mTracks, mViewInfo, mRate); - if (d.ShowModal() == wxID_OK) { + if (dlg.ShowModal() == wxID_OK) { PushState(_("Edited labels"), _("Label")); RedrawProject(); } @@ -5341,8 +5354,8 @@ void AudacityProject::OnImportCleanSpeechPresets() void AudacityProject::OnApplyChain() { - BatchProcessDialog d(this); - d.ShowModal(); + BatchProcessDialog dlg(this); + dlg.ShowModal(); // LL: See comments in ModifyUndoMenuItems() for info about this... // @@ -5352,8 +5365,8 @@ void AudacityProject::OnApplyChain() void AudacityProject::OnEditChains() { - EditChainsDialog d(this); - d.ShowModal(); + EditChainsDialog dlg(this); + dlg.ShowModal(); } wxString AudacityProject::BuildCleanFileName(wxString fileName) diff --git a/src/Project.cpp b/src/Project.cpp index fb8fe0444..ad16e7a95 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3543,6 +3543,8 @@ void AudacityProject::ModifyState() } // LL: Is there a memory leak here as "l" and "t" are not deleted??? +// Vaughan, 2010-08-29: No, as "l" is a TrackList* of an Undo stack state. +// Need to keep it and its tracks "t" available for Undo/Redo/SetStateTo. void AudacityProject::PopState(TrackList * l) { mTracks->Clear(true); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index c1e70eddd..bddf90f10 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -4017,7 +4017,7 @@ void TrackPanel::HandleResizeButtonUp(wxMouseEvent & event) { SetCapturedTrack( NULL ); MakeParentRedrawScrollbars(); - MakeParentModifyState(); + MakeParentModifyState(); //v Probably doesn't really warrant AutoSave. Maybe add bWantAutoSave param if there are more. } /// Resize dragging means that the mouse button IS down and has moved @@ -6479,7 +6479,7 @@ void TrackPanel::OnSetDisplay(wxCommandEvent & event) UpdateVRuler(wt); } - MakeParentModifyState(); + MakeParentModifyState(); //v Doesn't really warrant AutoSave. Maybe add bWantAutoSave param if there are more. mPopupMenuTarget = NULL; Refresh(false); }