1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-25 08:58:06 +02:00

Bug144: Editing performance when Karaoke window is open and very many labels...

... in the first label track.

Problem was calling wxTextCtrl::AppendText once per label, per push of undo
stack, each call causing event handling.

Now call it only once per push.
This commit is contained in:
Paul Licameli 2016-01-21 22:03:28 -05:00
parent 97e8fe3864
commit 376fc0ebf2
3 changed files with 44 additions and 25 deletions

View File

@ -18,6 +18,7 @@
#include "Lyrics.h" #include "Lyrics.h"
#include "Internat.h" #include "Internat.h"
#include "Project.h" // for GetActiveProject #include "Project.h" // for GetActiveProject
#include "LabelTrack.h"
#include <wx/arrimpl.cpp> #include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(SyllableArray); WX_DEFINE_OBJARRAY(SyllableArray);
@ -131,43 +132,59 @@ void Lyrics::Clear()
mHighlightTextCtrl->Clear(); mHighlightTextCtrl->Clear();
} }
void Lyrics::Add(double t, wxString syllable) void Lyrics::AddLabels(const LabelTrack *pLT)
{
const size_t numLabels = pLT->GetNumLabels();
wxString highlightText;
for (size_t ii = 0; ii < numLabels; ++ii) {
const LabelStruct *const pLabel = pLT->GetLabel(ii);
Add(pLabel->getT0(), pLabel->title, highlightText);
}
mHighlightTextCtrl->AppendText(highlightText);
}
void Lyrics::Add(double t, wxString syllable, wxString &highlightText)
{ {
int i = mSyllables.GetCount(); int i = mSyllables.GetCount();
if (mSyllables[i-1].t == t) { {
Syllable &prevSyllable = mSyllables[i - 1];
if (prevSyllable.t == t) {
// We can't have two syllables with the same time, so append // We can't have two syllables with the same time, so append
// this to the end of the previous one if they're at the // this to the end of the previous one if they're at the
// same time. // same time.
mSyllables[i-1].text += syllable; prevSyllable.text += syllable;
mSyllables[i-1].textWithSpace += syllable; prevSyllable.textWithSpace += syllable;
mSyllables[i-1].char1 += syllable.Length(); prevSyllable.char1 += syllable.Length();
return; return;
} }
}
mSyllables.Add(Syllable()); mSyllables.Add(Syllable());
mSyllables[i].t = t; Syllable &thisSyllable = mSyllables[i];
mSyllables[i].text = syllable; thisSyllable.t = t;
thisSyllable.text = syllable;
mSyllables[i].char0 = mText.Length(); thisSyllable.char0 = mText.Length();
// Put a space between syllables unless the previous one // Put a space between syllables unless the previous one
// ended in a hyphen // ended in a hyphen
if (i > 0 && if (i > 0 &&
// mSyllables[i-1].text.Length() > 0 && // mSyllables[i-1].text.Length() > 0 &&
mSyllables[i - 1].text.Right(1) != wxT("-")) mSyllables[i - 1].text.Right(1) != wxT("-"))
mSyllables[i].textWithSpace = wxT(" ") + syllable; thisSyllable.textWithSpace = wxT(" ") + syllable;
else else
mSyllables[i].textWithSpace = syllable; thisSyllable.textWithSpace = syllable;
mText += mSyllables[i].textWithSpace; mText += thisSyllable.textWithSpace;
mSyllables[i].char1 = mText.Length(); thisSyllable.char1 = mText.Length();
int nTextLen = mSyllables[i].textWithSpace.Length(); int nTextLen = thisSyllable.textWithSpace.Length();
if ((nTextLen > 0) && (mSyllables[i].textWithSpace.Right(1) == wxT("_"))) if ((nTextLen > 0) && (thisSyllable.textWithSpace.Right(1) == wxT("_")))
mHighlightTextCtrl->AppendText(mSyllables[i].textWithSpace.Left(nTextLen - 1) + wxT("\n")); highlightText += (thisSyllable.textWithSpace.Left(nTextLen - 1) + wxT("\n"));
else else
mHighlightTextCtrl->AppendText(mSyllables[i].textWithSpace); highlightText += thisSyllable.textWithSpace;
} }
void Lyrics::Finish(double finalT) void Lyrics::Finish(double finalT)

View File

@ -18,6 +18,8 @@
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
class LabelTrack;
#define LYRICS_DEFAULT_WIDTH 608 #define LYRICS_DEFAULT_WIDTH 608
#define LYRICS_DEFAULT_HEIGHT 280 #define LYRICS_DEFAULT_HEIGHT 280
@ -73,7 +75,7 @@ class Lyrics : public wxPanel
virtual ~Lyrics(); virtual ~Lyrics();
void Clear(); void Clear();
void Add(double t, wxString syllable); void AddLabels(const LabelTrack *pLT);
void Finish(double finalT); void Finish(double finalT);
int FindSyllable(long startChar); // Find the syllable whose char0 <= startChar <= char1. int FindSyllable(long startChar); // Find the syllable whose char0 <= startChar <= char1.
@ -103,6 +105,8 @@ class Lyrics : public wxPanel
void HandleLayout(); void HandleLayout();
private: private:
void Add(double t, wxString syllable, wxString &highlightText);
unsigned int GetDefaultFontSize() const; // Depends on mLyricsStyle. Call only after mLyricsStyle is set. unsigned int GetDefaultFontSize() const; // Depends on mLyricsStyle. Call only after mLyricsStyle is set.
void SetDrawnFont(wxDC *dc); // for kBouncingBallLyrics void SetDrawnFont(wxDC *dc); // for kBouncingBallLyrics

View File

@ -4096,9 +4096,7 @@ void AudacityProject::UpdateLyrics()
Lyrics* pLyricsPanel = mLyricsWindow->GetLyricsPanel(); Lyrics* pLyricsPanel = mLyricsWindow->GetLyricsPanel();
pLyricsPanel->Clear(); pLyricsPanel->Clear();
for (int i = 0; i < pLabelTrack->GetNumLabels(); i++) pLyricsPanel->AddLabels(pLabelTrack);
pLyricsPanel->Add(pLabelTrack->GetLabel(i)->getT0(),
pLabelTrack->GetLabel(i)->title);
pLyricsPanel->Finish(pLabelTrack->GetEndTime()); pLyricsPanel->Finish(pLabelTrack->GetEndTime());
pLyricsPanel->Update(this->GetSel0()); pLyricsPanel->Update(this->GetSel0());
} }