Skip to content

Commit

Permalink
Bug144: Editing performance when Karaoke window is open and very many…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Paul-Licameli committed Jan 22, 2016
1 parent 97e8fe3 commit 376fc0e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
59 changes: 38 additions & 21 deletions src/Lyrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
// 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();
return;
{
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.
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;
mSyllables[i - 1].text.Right(1) != wxT("-"))
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)
Expand Down
6 changes: 5 additions & 1 deletion src/Lyrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <wx/panel.h>
#include <wx/textctrl.h>

class LabelTrack;


#define LYRICS_DEFAULT_WIDTH 608
#define LYRICS_DEFAULT_HEIGHT 280
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 376fc0e

Please sign in to comment.