1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-24 00:18:07 +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 "Internat.h"
#include "Project.h" // for GetActiveProject
#include "LabelTrack.h"
#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(SyllableArray);
@ -131,43 +132,59 @@ void Lyrics::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();
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
// this to the end of the previous one if they're at the
// same time.
mSyllables[i-1].text += syllable;
mSyllables[i-1].textWithSpace += syllable;
mSyllables[i-1].char1 += syllable.Length();
prevSyllable.text += syllable;
prevSyllable.textWithSpace += syllable;
prevSyllable.char1 += syllable.Length();
return;
}
}
mSyllables.Add(Syllable());
mSyllables[i].t = t;
mSyllables[i].text = syllable;
Syllable &thisSyllable = mSyllables[i];
thisSyllable.t = t;
thisSyllable.text = syllable;
mSyllables[i].char0 = mText.Length();
thisSyllable.char0 = mText.Length();
// Put a space between syllables unless the previous one
// ended in a hyphen
if (i > 0 &&
// mSyllables[i-1].text.Length() > 0 &&
mSyllables[i - 1].text.Right(1) != wxT("-"))
mSyllables[i].textWithSpace = wxT(" ") + syllable;
thisSyllable.textWithSpace = wxT(" ") + syllable;
else
mSyllables[i].textWithSpace = syllable;
thisSyllable.textWithSpace = syllable;
mText += mSyllables[i].textWithSpace;
mSyllables[i].char1 = mText.Length();
mText += thisSyllable.textWithSpace;
thisSyllable.char1 = mText.Length();
int nTextLen = mSyllables[i].textWithSpace.Length();
if ((nTextLen > 0) && (mSyllables[i].textWithSpace.Right(1) == wxT("_")))
mHighlightTextCtrl->AppendText(mSyllables[i].textWithSpace.Left(nTextLen - 1) + wxT("\n"));
int nTextLen = thisSyllable.textWithSpace.Length();
if ((nTextLen > 0) && (thisSyllable.textWithSpace.Right(1) == wxT("_")))
highlightText += (thisSyllable.textWithSpace.Left(nTextLen - 1) + wxT("\n"));
else
mHighlightTextCtrl->AppendText(mSyllables[i].textWithSpace);
highlightText += thisSyllable.textWithSpace;
}
void Lyrics::Finish(double finalT)

View File

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

View File

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