1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 17:09:26 +02:00

Bug:406 Amelioration of slowdown when editing labels with long audio.

This commit is contained in:
james.k.crook@gmail.com 2011-05-22 13:41:01 +00:00
parent 391920624d
commit 74490b02c7
8 changed files with 82 additions and 43 deletions

View File

@ -318,7 +318,7 @@ void MixerTrackCluster::HandleSliderGain(const bool bWantPushState /*= false*/)
mProject->RefreshTPTrack(mTrack); mProject->RefreshTPTrack(mTrack);
if (bWantPushState) if (bWantPushState)
mProject->TP_PushState(_("Moved gain slider"), _("Gain"), true /* consolidate */); mProject->TP_PushState(_("Moved gain slider"), _("Gain"), PUSH_CONSOLIDATE );
} }
void MixerTrackCluster::HandleSliderPan(const bool bWantPushState /*= false*/) void MixerTrackCluster::HandleSliderPan(const bool bWantPushState /*= false*/)
@ -333,7 +333,7 @@ void MixerTrackCluster::HandleSliderPan(const bool bWantPushState /*= false*/)
mProject->RefreshTPTrack(mTrack); mProject->RefreshTPTrack(mTrack);
if (bWantPushState) if (bWantPushState)
mProject->TP_PushState(_("Moved pan slider"), _("Pan"), true /* consolidate */); mProject->TP_PushState(_("Moved pan slider"), _("Pan"), PUSH_CONSOLIDATE );
} }
void MixerTrackCluster::ResetMeter(const bool bResetClipping) void MixerTrackCluster::ResetMeter(const bool bResetClipping)

View File

@ -3579,10 +3579,10 @@ void AudacityProject::InitialState()
void AudacityProject::PushState(wxString desc, void AudacityProject::PushState(wxString desc,
wxString shortDesc, wxString shortDesc,
bool consolidate) int flags )
{ {
mUndoManager.PushState(mTracks, mViewInfo.sel0, mViewInfo.sel1, mUndoManager.PushState(mTracks, mViewInfo.sel0, mViewInfo.sel1,
desc, shortDesc, consolidate); desc, shortDesc, flags);
mDirty = true; mDirty = true;
@ -3606,8 +3606,8 @@ void AudacityProject::PushState(wxString desc,
if (GetTracksFitVerticallyZoomed()) if (GetTracksFitVerticallyZoomed())
this->DoZoomFitV(); this->DoZoomFitV();
if( (flags & PUSH_AUTOSAVE)!= 0)
AutoSave(); AutoSave();
} }
void AudacityProject::ModifyState() void AudacityProject::ModifyState()
@ -3685,17 +3685,16 @@ void AudacityProject::SetStateTo(unsigned int n)
void AudacityProject::UpdateLyrics() void AudacityProject::UpdateLyrics()
{ {
// JKC: Previously we created a lyrics window,
// if it did not exist. But we don't need to.
if (!mLyricsWindow)
return;
TrackListOfKindIterator iter(Track::Label, mTracks); TrackListOfKindIterator iter(Track::Label, mTracks);
LabelTrack* pLabelTrack = (LabelTrack*)(iter.First()); // Lyrics come from only the first label track. LabelTrack* pLabelTrack = (LabelTrack*)(iter.First()); // Lyrics come from only the first label track.
if (!pLabelTrack) if (!pLabelTrack)
return; return;
if (!mLyricsWindow)
{
mLyricsWindow = new LyricsWindow(this);
mLyricsWindow->Show(false); // Don't show it. Need to update content regardless.
}
// The code that updates the lyrics is rather expensive when there // The code that updates the lyrics is rather expensive when there
// are a lot of labels. // are a lot of labels.
// So - bail out early if the lyrics window is not visible. // So - bail out early if the lyrics window is not visible.
@ -4275,9 +4274,9 @@ void AudacityProject::TP_OnPlayKey()
// TrackPanel callback method // TrackPanel callback method
void AudacityProject::TP_PushState(wxString desc, wxString shortDesc, void AudacityProject::TP_PushState(wxString desc, wxString shortDesc,
bool consolidate) int flags)
{ {
PushState(desc, shortDesc, consolidate); PushState(desc, shortDesc, flags);
} }
// TrackPanel callback method // TrackPanel callback method
@ -4336,6 +4335,7 @@ void AudacityProject::ReleaseKeyboard(wxWindow *w)
void AudacityProject::AutoSave() void AudacityProject::AutoSave()
{ {
return;
// To minimize the possibility of race conditions, we first write to a // To minimize the possibility of race conditions, we first write to a
// file with the extension ".tmp", then rename the file to .autosave // file with the extension ".tmp", then rename the file to .autosave
SonifyBeginAutoSave(); SonifyBeginAutoSave();

View File

@ -334,7 +334,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
virtual void TP_OnPlayKey(); virtual void TP_OnPlayKey();
virtual void TP_PushState(wxString longDesc, wxString shortDesc, virtual void TP_PushState(wxString longDesc, wxString shortDesc,
bool consolidate); int flags);
virtual void TP_ModifyState(); virtual void TP_ModifyState();
virtual void TP_RedrawScrollbars(); virtual void TP_RedrawScrollbars();
virtual void TP_ScrollLeft(); virtual void TP_ScrollLeft();
@ -397,7 +397,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
static void AllProjectsDeleteUnlock(); static void AllProjectsDeleteUnlock();
void PushState(wxString desc, wxString shortDesc, void PushState(wxString desc, wxString shortDesc,
bool consolidate = false); int flags = PUSH_AUTOSAVE | PUSH_CALC_SPACE);
private: private:

View File

@ -1329,9 +1329,9 @@ void TrackPanel::OnPaint(wxPaintEvent & /* event */)
/// Makes our Parent (well, whoever is listening to us) push their state. /// Makes our Parent (well, whoever is listening to us) push their state.
/// this causes application state to be preserved on a stack for undo ops. /// this causes application state to be preserved on a stack for undo ops.
void TrackPanel::MakeParentPushState(wxString desc, wxString shortDesc, void TrackPanel::MakeParentPushState(wxString desc, wxString shortDesc,
bool consolidate) int flags)
{ {
mListener->TP_PushState(desc, shortDesc, consolidate); mListener->TP_PushState(desc, shortDesc, flags);
} }
void TrackPanel::MakeParentModifyState() void TrackPanel::MakeParentModifyState()
@ -1963,7 +1963,7 @@ void TrackPanel::SelectionHandleClick(wxMouseEvent & event,
&mViewInfo->sel0, &mViewInfo->sel1)) { &mViewInfo->sel0, &mViewInfo->sel1)) {
MakeParentPushState(_("Modified Label"), MakeParentPushState(_("Modified Label"),
_("Label Edit"), _("Label Edit"),
true /* consolidate */); PUSH_CONSOLIDATE);
} }
// IF the user clicked a label, THEN select all other tracks by Label // IF the user clicked a label, THEN select all other tracks by Label
@ -2036,7 +2036,7 @@ void TrackPanel::SelectionHandleClick(wxMouseEvent & event,
mStretching = true; mStretching = true;
mStretched = false; mStretched = false;
MakeParentPushState(_("Stretch Note Track"), _("Stretch"), false); MakeParentPushState(_("Stretch Note Track"), _("Stretch"));
// Full refresh since the label area may need to indicate // Full refresh since the label area may need to indicate
// newly selected tracks. (I'm really not sure if the label area // newly selected tracks. (I'm really not sure if the label area
@ -2263,7 +2263,8 @@ void TrackPanel::Stretch(int mouseXCoordinate, int trackLeftEdge,
wxASSERT(false); wxASSERT(false);
break; break;
} }
MakeParentPushState(_("Stretch Note Track"), _("Stretch"), true); MakeParentPushState(_("Stretch Note Track"), _("Stretch"),
PUSH_CONSOLIDATE | PUSH_AUTOSAVE | PUSH_CALC_SPACE);
mStretched = true; mStretched = true;
Refresh(false); Refresh(false);
} }
@ -2397,8 +2398,7 @@ void TrackPanel::HandleEnvelope(wxMouseEvent & event)
mCapturedTrack = NULL; mCapturedTrack = NULL;
MakeParentPushState( MakeParentPushState(
_("Adjusted envelope."), _("Adjusted envelope."),
_("Envelope"), _("Envelope")
false /* do not consolidate these actions */
); );
} }
} }
@ -2557,7 +2557,8 @@ void TrackPanel::HandleSlide(wxMouseEvent & event)
direction.c_str(), fabs(mHSlideAmount)); direction.c_str(), fabs(mHSlideAmount));
consolidate = true; consolidate = true;
} }
MakeParentPushState(msg, _("Time-Shift"), consolidate); MakeParentPushState(msg, _("Time-Shift"),
consolidate ? (PUSH_CONSOLIDATE) : (PUSH_AUTOSAVE|PUSH_CALC_SPACE));
} }
} }
@ -3778,7 +3779,7 @@ void TrackPanel::HandleSampleEditingButtonUp( wxMouseEvent & event )
mDrawingTrack=NULL; //Set this to NULL so it will catch improper drag events. mDrawingTrack=NULL; //Set this to NULL so it will catch improper drag events.
MakeParentPushState(_("Moved Sample"), MakeParentPushState(_("Moved Sample"),
_("Sample Edit"), _("Sample Edit"),
true /* consolidate */); PUSH_CONSOLIDATE|PUSH_AUTOSAVE|PUSH_CALC_SPACE);
} }
@ -4052,7 +4053,7 @@ void TrackPanel::HandleSliders(wxMouseEvent &event, bool pan)
#endif #endif
MakeParentPushState(pan ? _("Moved pan slider") : _("Moved gain slider"), MakeParentPushState(pan ? _("Moved pan slider") : _("Moved gain slider"),
pan ? _("Pan") : _("Gain"), pan ? _("Pan") : _("Gain"),
true /* consolidate */); PUSH_CONSOLIDATE);
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
} else { } else {
MakeParentPushState(_("Moved velocity slider"), _("Velocity"), true); MakeParentPushState(_("Moved velocity slider"), _("Velocity"), true);
@ -4661,7 +4662,7 @@ void TrackPanel::OnKeyDown(wxKeyEvent & event)
if (lt->OnKeyDown(mViewInfo->sel0, mViewInfo->sel1, event)) if (lt->OnKeyDown(mViewInfo->sel0, mViewInfo->sel1, event))
MakeParentPushState(_("Modified Label"), MakeParentPushState(_("Modified Label"),
_("Label Edit"), _("Label Edit"),
true /* consolidate */); PUSH_CONSOLIDATE);
// Make sure caret is in view // Make sure caret is in view
int x; int x;
@ -4699,7 +4700,7 @@ void TrackPanel::OnChar(wxKeyEvent & event)
if (((LabelTrack *)t)->OnChar(mViewInfo->sel0, mViewInfo->sel1, event)) if (((LabelTrack *)t)->OnChar(mViewInfo->sel0, mViewInfo->sel1, event))
MakeParentPushState(_("Modified Label"), MakeParentPushState(_("Modified Label"),
_("Label Edit"), _("Label Edit"),
true /* consolidate */); PUSH_CONSOLIDATE);
// If selection modified, refresh // If selection modified, refresh
// Otherwise, refresh track display if the keystroke was handled // Otherwise, refresh track display if the keystroke was handled
@ -4865,7 +4866,7 @@ bool TrackPanel::HandleTrackLocationMouseEvent(WaveTrack * track, wxRect &r, wxM
mViewInfo->sel0 = cutlineStart; mViewInfo->sel0 = cutlineStart;
mViewInfo->sel1 = cutlineEnd; mViewInfo->sel1 = cutlineEnd;
DisplaySelection(); DisplaySelection();
MakeParentPushState(_("Expanded Cut Line"), _("Expand"), false ); MakeParentPushState(_("Expanded Cut Line"), _("Expand"));
handled = true; handled = true;
} }
} else if (mCapturedTrackLocation.typ == WaveTrack::locationMergePoint) } else if (mCapturedTrackLocation.typ == WaveTrack::locationMergePoint)
@ -4874,7 +4875,7 @@ bool TrackPanel::HandleTrackLocationMouseEvent(WaveTrack * track, wxRect &r, wxM
WaveTrack* linked = (WaveTrack*)mTracks->GetLink(track); WaveTrack* linked = (WaveTrack*)mTracks->GetLink(track);
if (linked) if (linked)
linked->MergeClips(mCapturedTrackLocation.clipidx1, mCapturedTrackLocation.clipidx2); linked->MergeClips(mCapturedTrackLocation.clipidx1, mCapturedTrackLocation.clipidx2);
MakeParentPushState(_("Merged Clips"),_("Merge"), true ); MakeParentPushState(_("Merged Clips"),_("Merge"), PUSH_CONSOLIDATE|PUSH_CALC_SPACE);
handled = true; handled = true;
} }
} }
@ -4885,7 +4886,7 @@ bool TrackPanel::HandleTrackLocationMouseEvent(WaveTrack * track, wxRect &r, wxM
WaveTrack* linked = (WaveTrack*)mTracks->GetLink(track); WaveTrack* linked = (WaveTrack*)mTracks->GetLink(track);
if (linked) if (linked)
linked->RemoveCutLine(mCapturedTrackLocation.pos); linked->RemoveCutLine(mCapturedTrackLocation.pos);
MakeParentPushState(_("Removed Cut Line"), _("Remove"), false ); MakeParentPushState(_("Removed Cut Line"), _("Remove") );
handled = true; handled = true;
} }
@ -4966,7 +4967,7 @@ bool TrackPanel::HandleLabelTrackMouseEvent(LabelTrack * lTrack, wxRect &r, wxMo
MakeParentPushState(_("Modified Label"), MakeParentPushState(_("Modified Label"),
_("Label Edit"), _("Label Edit"),
true /* consolidate */); PUSH_CONSOLIDATE);
} }
@ -6542,7 +6543,7 @@ void TrackPanel::SetTrackPan(Track * t, LWSlider * s)
if (link) if (link)
link->SetPan(newValue); link->SetPan(newValue);
MakeParentPushState(_("Adjusted Pan"), _("Pan"), true ); MakeParentPushState(_("Adjusted Pan"), _("Pan"), PUSH_CONSOLIDATE );
RefreshTrack(t); RefreshTrack(t);
} }
@ -6596,7 +6597,7 @@ void TrackPanel::SetTrackGain(Track * t, LWSlider * s)
if (link) if (link)
link->SetGain(newValue); link->SetGain(newValue);
MakeParentPushState(_("Adjusted gain"), _("Gain"), true ); MakeParentPushState(_("Adjusted gain"), _("Gain"), PUSH_CONSOLIDATE);
RefreshTrack(t); RefreshTrack(t);
} }
@ -7330,7 +7331,7 @@ void TrackPanel::OnCutSelectedText(wxCommandEvent &event)
if (lt->CutSelectedText()) { if (lt->CutSelectedText()) {
MakeParentPushState(_("Modified Label"), MakeParentPushState(_("Modified Label"),
_("Label Edit"), _("Label Edit"),
true /* consolidate */); PUSH_CONSOLIDATE);
} }
RefreshTrack(lt); RefreshTrack(lt);
} }

View File

@ -67,7 +67,7 @@ class AUDACITY_DLL_API TrackPanelListener {
virtual void TP_OnPlayKey() = 0; virtual void TP_OnPlayKey() = 0;
virtual void TP_PushState(wxString shortDesc, wxString longDesc, virtual void TP_PushState(wxString shortDesc, wxString longDesc,
bool consolidate = false) = 0; int flags = PUSH_AUTOSAVE | PUSH_CALC_SPACE) = 0;
virtual void TP_ModifyState() = 0; virtual void TP_ModifyState() = 0;
virtual void TP_RedrawScrollbars() = 0; virtual void TP_RedrawScrollbars() = 0;
virtual void TP_ScrollLeft() = 0; virtual void TP_ScrollLeft() = 0;
@ -395,7 +395,7 @@ class TrackPanel:public wxPanel {
// AS: Pushing the state preserves state for Undo operations. // AS: Pushing the state preserves state for Undo operations.
void MakeParentPushState(wxString desc, wxString shortDesc, void MakeParentPushState(wxString desc, wxString shortDesc,
bool consolidate = false); int flags = PUSH_AUTOSAVE | PUSH_CALC_SPACE);
void MakeParentModifyState(); void MakeParentModifyState();
void MakeParentResize(); void MakeParentResize();

View File

@ -210,13 +210,12 @@ void UndoManager::ModifyState(TrackList * l, double sel0, double sel1)
void UndoManager::PushState(TrackList * l, double sel0, double sel1, void UndoManager::PushState(TrackList * l, double sel0, double sel1,
wxString longDescription, wxString longDescription,
wxString shortDescription, wxString shortDescription,
bool consolidate) int flags)
{ {
unsigned int i; unsigned int i;
// If consolidate is set to true, group up to 3 identical operations. // If consolidate is set to true, group up to 3 identical operations.
if (((flags&PUSH_CONSOLIDATE)!=0) && lastAction == longDescription &&
if (consolidate && lastAction == longDescription &&
consolidationCount < 2) { consolidationCount < 2) {
consolidationCount++; consolidationCount++;
ModifyState(l, sel0, sel1); ModifyState(l, sel0, sel1);
@ -253,7 +252,8 @@ void UndoManager::PushState(TrackList * l, double sel0, double sel1,
stack.Add(push); stack.Add(push);
current++; current++;
push->spaceUsage = this->CalculateSpaceUsage(current); if( (flags&PUSH_CALC_SPACE)!=0)
push->spaceUsage = this->CalculateSpaceUsage(current);
if (saved >= current) { if (saved >= current) {
saved = -1; saved = -1;

View File

@ -66,6 +66,14 @@ struct UndoStackElem {
WX_DEFINE_USER_EXPORTED_ARRAY(UndoStackElem *, UndoStack, class AUDACITY_DLL_API); WX_DEFINE_USER_EXPORTED_ARRAY(UndoStackElem *, UndoStack, class AUDACITY_DLL_API);
// These flags control what extra to do on a PushState
// Default is PUSH_AUTOSAVE | PUSH_CALC_SPACE
// Frequent/faster actions use PUSH_CONSOLIDATE
const int PUSH_MINIMAL = 0;
const int PUSH_CONSOLIDATE = 1;
const int PUSH_CALC_SPACE = 2;
const int PUSH_AUTOSAVE = 4;
class AUDACITY_DLL_API UndoManager { class AUDACITY_DLL_API UndoManager {
public: public:
UndoManager(); UndoManager();
@ -73,7 +81,7 @@ class AUDACITY_DLL_API UndoManager {
void PushState(TrackList * l, double sel0, double sel1, void PushState(TrackList * l, double sel0, double sel1,
wxString longDescription, wxString shortDescription, wxString longDescription, wxString shortDescription,
bool consolidate = false); int flags = PUSH_CALC_SPACE|PUSH_AUTOSAVE );
void ModifyState(TrackList * l, double sel0, double sel1); void ModifyState(TrackList * l, double sel0, double sel1);
void ClearStates(); void ClearStates();
void RemoveStates(int num); // removes the 'num' oldest states void RemoveStates(int num); // removes the 'num' oldest states

View File

@ -71,6 +71,36 @@ BEGIN_EVENT_TABLE(PrefsDialog, wxDialog)
EVT_TREE_KEY_DOWN(wxID_ANY, PrefsDialog::OnTreeKeyDown) // Handles key events when tree has focus EVT_TREE_KEY_DOWN(wxID_ANY, PrefsDialog::OnTreeKeyDown) // Handles key events when tree has focus
END_EVENT_TABLE() END_EVENT_TABLE()
class wxTreebookExt : public wxTreebook
{
public:
wxTreebookExt( wxWindow *parent,
wxWindowID id) : wxTreebook( parent, id )
{;};
~wxTreebookExt(){;};
virtual int ChangeSelection(size_t n);
virtual int SetSelection(size_t n);
};
int wxTreebookExt::ChangeSelection(size_t n) {
int i = wxTreebook::ChangeSelection(n);
wxString Temp = GetPageText( n );
((wxDialog*)GetParent())->SetTitle( Temp );
return i;
};
int wxTreebookExt::SetSelection(size_t n)
{
int i = wxTreebook::SetSelection(n);
wxString Temp = wxString(wxT("Preferences: ")) + GetPageText( n );
((wxDialog*)GetParent())->SetTitle( Temp );
return i;
}
PrefsDialog::PrefsDialog(wxWindow * parent) PrefsDialog::PrefsDialog(wxWindow * parent)
: wxDialog(parent, wxID_ANY, wxString(_("Audacity Preferences")), : wxDialog(parent, wxID_ANY, wxString(_("Audacity Preferences")),
wxDefaultPosition, wxDefaultPosition,
@ -83,7 +113,7 @@ PrefsDialog::PrefsDialog(wxWindow * parent)
{ {
S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true); S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true);
{ {
mCategories = new wxTreebook(this, wxID_ANY); mCategories = new wxTreebookExt(this, wxID_ANY);
S.Prop(1); S.Prop(1);
S.AddWindow(mCategories, wxEXPAND); S.AddWindow(mCategories, wxEXPAND);