Audacity  2.3.1
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
LyricsPanel Class Referencefinal

LyricsPanel is a panel that paints the bouncing ball and the lyrics text. More...

#include <Lyrics.h>

Inheritance diagram for LyricsPanel:
wxPanelWrapper wxTabTraversalWrapper< wxPanel >

Public Member Functions

 LyricsPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
virtual ~LyricsPanel ()
 
void Clear ()
 
void AddLabels (const LabelTrack *pLT)
 
void Finish (double finalT)
 
int FindSyllable (long startChar)
 
int GetCurrentSyllableIndex ()
 
SyllableGetSyllable (int nSyl)
 
void SetCurrentSyllableIndex (int nSyl)
 
LyricsStyle GetLyricsStyle ()
 
void SetLyricsStyle (const LyricsStyle newLyricsStyle)
 
void Update (double t)
 
void OnKeyEvent (wxKeyEvent &event)
 
void DoPaint (wxDC &dc)
 
void OnPaint (wxPaintEvent &evt)
 
void OnSize (wxSizeEvent &evt)
 
void HandlePaint (wxDC &dc)
 
void HandlePaint_BouncingBall (wxDC &dc)
 
void HandleLayout ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&...args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Types

enum  LyricsStyle { kBouncingBallLyrics, kHighlightLyrics }
 

Private Member Functions

void Add (double t, const wxString &syllable, wxString &highlightText)
 
unsigned int GetDefaultFontSize () const
 
void SetDrawnFont (wxDC *dc)
 
void SetHighlightFont ()
 
void Measure (wxDC *dc)
 
int FindSyllable (double t)
 
void GetKaraokePosition (double t, int *outX, double *outY)
 

Private Attributes

int mWidth
 
int mHeight
 
int mKaraokeHeight
 
unsigned int mKaraokeFontSize
 
LyricsStyle mLyricsStyle
 
HighlightTextCtrlmHighlightTextCtrl
 
double mT
 
int mCurrentSyllable
 
std::vector< SyllablemSyllables
 
wxString mText
 
int mTextHeight
 
bool mMeasurementsDone
 

Detailed Description

LyricsPanel is a panel that paints the bouncing ball and the lyrics text.

Definition at line 71 of file Lyrics.h.

Member Enumeration Documentation

Enumerator
kBouncingBallLyrics 
kHighlightLyrics 

Definition at line 75 of file Lyrics.h.

75  {
76  kBouncingBallLyrics, // Lyrics move from right to left with bouncing ball.
77  // kGuitarTab, //v <<future>> Guitar Tablature moves from right to left.
78  kHighlightLyrics, // Lyrics show in scrolling page and syllables highlight successively.
79  };

Constructor & Destructor Documentation

LyricsPanel::LyricsPanel ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize 
)

Definition at line 81 of file Lyrics.cpp.

References safenew.

83  :
84  wxPanelWrapper(parent, id, pos, size, wxWANTS_CHARS),
85  mWidth(size.x), mHeight(size.y)
86 {
88  mLyricsStyle = kBouncingBallLyrics; // default
89  mKaraokeFontSize = this->GetDefaultFontSize(); // Call only after mLyricsPanelStyle is set.
90 
91  this->SetBackgroundColour(*wxWHITE);
92 
94  safenew HighlightTextCtrl(this, -1, // wxWindow* parent, wxWindowID id,
95  wxT(""), // const wxString& value = wxT(""),
96  wxPoint(0, 0), // const wxPoint& pos = wxDefaultPosition,
97  size); // const wxSize& size = wxDefaultSize
98  this->SetHighlightFont();
99  mHighlightTextCtrl->Show(mLyricsStyle == kHighlightLyrics); // test, in case we conditionalize the default, above
100 
101 
102  mT = 0.0;
103 
104  Clear();
105  Finish(0.0);
106 
107  #ifdef __WXMAC__
108  wxSizeEvent dummyEvent;
109  OnSize(dummyEvent);
110  #endif
111 }
int mHeight
Definition: Lyrics.h:132
void SetHighlightFont()
Definition: Lyrics.cpp:251
double mT
Definition: Lyrics.h:140
void Finish(double finalT)
Definition: Lyrics.cpp:188
#define safenew
Definition: Audacity.h:230
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:241
int mKaraokeHeight
Definition: Lyrics.h:134
void OnSize(wxSizeEvent &evt)
Definition: Lyrics.cpp:500
int mWidth
Definition: Lyrics.h:131
unsigned int mKaraokeFontSize
Definition: Lyrics.h:135
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
void Clear()
Definition: Lyrics.cpp:119
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
LyricsPanel::~LyricsPanel ( )
virtual

Definition at line 113 of file Lyrics.cpp.

114 {
115 }

Member Function Documentation

void LyricsPanel::Add ( double  t,
const wxString &  syllable,
wxString &  highlightText 
)
private

Definition at line 144 of file Lyrics.cpp.

References Syllable::char0, Syllable::char1, mSyllables, mText, Syllable::t, Syllable::text, and Syllable::textWithSpace.

Referenced by AddLabels().

145 {
146  int i = mSyllables.size();
147 
148  {
149  Syllable &prevSyllable = mSyllables[i - 1];
150 
151  if (prevSyllable.t == t) {
152  // We can't have two syllables with the same time, so append
153  // this to the end of the previous one if they're at the
154  // same time.
155  prevSyllable.text += syllable;
156  prevSyllable.textWithSpace += syllable;
157  prevSyllable.char1 += syllable.Length();
158  return;
159  }
160  }
161 
162  mSyllables.push_back(Syllable());
163  Syllable &thisSyllable = mSyllables[i];
164  thisSyllable.t = t;
165  thisSyllable.text = syllable;
166 
167  thisSyllable.char0 = mText.Length();
168 
169  // Put a space between syllables unless the previous one
170  // ended in a hyphen
171  if (i > 0 &&
172  // mSyllables[i-1].text.Length() > 0 &&
173  mSyllables[i - 1].text.Right(1) != wxT("-"))
174  thisSyllable.textWithSpace = wxT(" ") + syllable;
175  else
176  thisSyllable.textWithSpace = syllable;
177 
178  mText += thisSyllable.textWithSpace;
179  thisSyllable.char1 = mText.Length();
180 
181  int nTextLen = thisSyllable.textWithSpace.Length();
182  if ((nTextLen > 0) && (thisSyllable.textWithSpace.Right(1) == wxT("_")))
183  highlightText += (thisSyllable.textWithSpace.Left(nTextLen - 1) + wxT("\n"));
184  else
185  highlightText += thisSyllable.textWithSpace;
186 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
int char0
Definition: Lyrics.h:37
int char1
Definition: Lyrics.h:38
double t
Definition: Lyrics.h:34
wxString text
Definition: Lyrics.h:35
wxString textWithSpace
Definition: Lyrics.h:36
wxString mText
Definition: Lyrics.h:144
void LyricsPanel::AddLabels ( const LabelTrack pLT)

Definition at line 133 of file Lyrics.cpp.

References Add(), LabelTrack::GetLabel(), LabelTrack::GetNumLabels(), LabelStruct::getT0(), mHighlightTextCtrl, and LabelStruct::title.

Referenced by AudacityProject::UpdateLyrics().

134 {
135  const size_t numLabels = pLT->GetNumLabels();
136  wxString highlightText;
137  for (size_t ii = 0; ii < numLabels; ++ii) {
138  const LabelStruct *const pLabel = pLT->GetLabel(ii);
139  Add(pLabel->getT0(), pLabel->title, highlightText);
140  }
141  mHighlightTextCtrl->AppendText(highlightText);
142 }
void Add(double t, const wxString &syllable, wxString &highlightText)
Definition: Lyrics.cpp:144
wxString title
Definition: LabelTrack.h:92
int GetNumLabels() const
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
const LabelStruct * GetLabel(int index) const
double getT0() const
Definition: LabelTrack.h:61
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
void LyricsPanel::Clear ( )

Definition at line 119 of file Lyrics.cpp.

References mHighlightTextCtrl, mSyllables, and mText.

Referenced by AudacityProject::UpdateLyrics().

120 {
121  mSyllables.clear();
122  mText = wxT("");
123 
124  // Add two dummy syllables at the beginning
125  mSyllables.push_back(Syllable());
126  mSyllables[0].t = -2.0;
127  mSyllables.push_back(Syllable());
128  mSyllables[1].t = -1.0;
129 
130  mHighlightTextCtrl->Clear();
131 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
wxString mText
Definition: Lyrics.h:144
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
void LyricsPanel::DoPaint ( wxDC &  dc)

Definition at line 471 of file Lyrics.cpp.

References HandlePaint(), kBouncingBallLyrics, Measure(), mKaraokeHeight, mLyricsStyle, mMeasurementsDone, and mWidth.

Referenced by OnPaint(), and OnSize().

472 {
473  if (!this->GetParent()->IsShown())
474  return;
475 
477  {
478  if (!mMeasurementsDone)
479  Measure(&dc);
480 
481  #ifdef __WXMAC__
482  // Mac OS X automatically double-buffers the screen for you,
483  // so our bitmap is unneccessary
484  HandlePaint(dc);
485  #else
486  wxBitmap bitmap(mWidth, mKaraokeHeight);
487  wxMemoryDC memDC;
488  memDC.SelectObject(bitmap);
489  HandlePaint(memDC);
490  dc.Blit(0, 0, mWidth, mKaraokeHeight, &memDC, 0, 0, wxCOPY, FALSE);
491  #endif
492  }
493  else // (mLyricsStyle == kHighlightLyrics)
494  {
495  //v causes flicker in ported version
496  // this->SetHighlightFont();
497  }
498 }
void HandlePaint(wxDC &dc)
Definition: Lyrics.cpp:536
int mKaraokeHeight
Definition: Lyrics.h:134
void Measure(wxDC *dc)
Definition: Lyrics.cpp:259
int mWidth
Definition: Lyrics.h:131
bool mMeasurementsDone
Definition: Lyrics.h:147
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
int LyricsPanel::FindSyllable ( long  startChar)

Definition at line 206 of file Lyrics.cpp.

References mSyllables.

Referenced by GetKaraokePosition(), HighlightTextCtrl::OnMouseEvent(), and Update().

207 {
208  int i1, i2;
209 
210  i1 = 0;
211  i2 = mSyllables.size();
212  while (i2 > i1+1) {
213  int pmid = (i1+i2)/2;
214  if (mSyllables[pmid].char0 > startChar)
215  i2 = pmid;
216  else
217  i1 = pmid;
218  }
219 
220  if (i1 < 2)
221  i1 = 2;
222  if (i1 > (int)(mSyllables.size()) - 3)
223  i1 = mSyllables.size() - 3;
224 
225  return i1;
226 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
int LyricsPanel::FindSyllable ( double  t)
private

Definition at line 314 of file Lyrics.cpp.

References mSyllables.

315 {
316  int i1, i2;
317 
318  i1 = 0;
319  i2 = mSyllables.size();
320  while (i2 > i1+1) {
321  int pmid = (i1+i2)/2;
322  if (mSyllables[pmid].t > t)
323  i2 = pmid;
324  else
325  i1 = pmid;
326  }
327 
328  if (i1 < 2)
329  i1 = 2;
330  if (i1 > (int)(mSyllables.size()) - 3)
331  i1 = mSyllables.size() - 3;
332 
333  return i1;
334 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
void LyricsPanel::Finish ( double  finalT)

Definition at line 188 of file Lyrics.cpp.

References mCurrentSyllable, mHighlightTextCtrl, mMeasurementsDone, and mSyllables.

Referenced by AudacityProject::UpdateLyrics().

189 {
190  // Add 3 dummy syllables at the end
191  int i = mSyllables.size();
192  mSyllables.push_back(Syllable());
193  mSyllables[i].t = finalT + 1.0;
194  mSyllables.push_back(Syllable());
195  mSyllables[i+1].t = finalT + 2.0;
196  mSyllables.push_back(Syllable());
197  mSyllables[i+2].t = finalT + 3.0;
198 
199  // Mark measurements as invalid
200  mMeasurementsDone = false; // only for drawn text
201  mCurrentSyllable = 0;
202  mHighlightTextCtrl->ShowPosition(0);
203 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
int mCurrentSyllable
Definition: Lyrics.h:142
bool mMeasurementsDone
Definition: Lyrics.h:147
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
int LyricsPanel::GetCurrentSyllableIndex ( )
inline

Definition at line 92 of file Lyrics.h.

References mCurrentSyllable.

Referenced by HighlightTextCtrl::OnMouseEvent().

92 { return mCurrentSyllable; };
int mCurrentSyllable
Definition: Lyrics.h:142
unsigned int LyricsPanel::GetDefaultFontSize ( ) const
private

Definition at line 241 of file Lyrics.cpp.

References kBouncingBallLyrics, and mLyricsStyle.

Referenced by OnSize().

242 {
243  return (mLyricsStyle == kBouncingBallLyrics) ? 48 : 10;
244 }
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
void LyricsPanel::GetKaraokePosition ( double  t,
int *  outX,
double *  outY 
)
private

Definition at line 343 of file Lyrics.cpp.

References FindSyllable(), I_FIRST_REAL_SYLLABLE, M_PI, and mSyllables.

Referenced by HandlePaint_BouncingBall().

345 {
346  *outX = 0;
347  *outY = 0;
348 
349  if (t < mSyllables[I_FIRST_REAL_SYLLABLE].t || t > mSyllables[mSyllables.size() - 3].t)
350  return;
351 
352  int i0, i1, i2, i3;
353  int x0, x1, x2, x3;
354  double t0, t1, t2, t3;
355  i1 = FindSyllable(t);
356  i2 = i1 + 1;
357 
358  // Because we've padded the syllables with two dummies at the beginning
359  // and end, we know that i0...i3 will always exist. Also, we've made
360  // sure that we don't ever have two of the same time, so t2>t1 strictly.
361  //
362  // t
363  // \/
364  // time: t0 t1 t2 t3
365  // pos: x0 x1 x2 x3
366  // index: i0 i1 i2 i3
367  // vel: vel1 vel2
368 
369  i0 = i1 - 1;
370  i3 = i2 + 1;
371 
372  x0 = mSyllables[i0].x;
373  x1 = mSyllables[i1].x;
374  x2 = mSyllables[i2].x;
375  x3 = mSyllables[i3].x;
376 
377  t0 = mSyllables[i0].t;
378  t1 = mSyllables[i1].t;
379  t2 = mSyllables[i2].t;
380  t3 = mSyllables[i3].t;
381 
382  double linear_vel0 = (x1 - x0) / (t1 - t0);
383  double linear_vel1 = (x2 - x1) / (t2 - t1);
384  double linear_vel2 = (x3 - x2) / (t3 - t2);
385 
386  // average velocities
387  double v1 = (linear_vel0 + linear_vel1) / 2;
388  double v2 = (linear_vel1 + linear_vel2) / 2;
389 
390  // Solve a cubic equation f(t) = at^3 + bt^2 + ct + d
391  // which gives the position x as a function of
392  // (t - t1), by constraining f(0), f'(0), f(t2-t1), f'(t2-t1)
393  double delta_t = t2 - t1;
394  double delta_x = x2 - x1;
395  v1 *= delta_t;
396  v2 *= delta_t;
397  double a = v1 + v2 - 2*delta_x;
398  double b = 3*delta_x - 2*v1 - v2;
399  double c = v1;
400  double d = x1;
401 
402  t = (t - t1) / (t2 - t1);
403  double xx = a*t*t*t + b*t*t + c*t + d;
404 
405  // Unfortunately sometimes our cubic goes backwards. This is a quick
406  // hack to stop that from happening.
407  if (xx < x1)
408  xx = x1;
409 
410  *outX = (int)xx;
411 
412  // The y position is a simple cosine curve; the max height is a
413  // function of the time.
414  double height = t2 - t1 > 4.0? 1.0: sqrt((t2-t1)/4.0);
415  *outY = height * sin(M_PI * t);
416 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
#define I_FIRST_REAL_SYLLABLE
Definition: Lyrics.cpp:117
int FindSyllable(long startChar)
Definition: Lyrics.cpp:206
#define M_PI
Definition: Distortion.cpp:28
LyricsStyle LyricsPanel::GetLyricsStyle ( )
inline

Definition at line 96 of file Lyrics.h.

References mLyricsStyle.

96 { return mLyricsStyle; };
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
Syllable* LyricsPanel::GetSyllable ( int  nSyl)
inline

Definition at line 93 of file Lyrics.h.

References mSyllables.

Referenced by HighlightTextCtrl::OnMouseEvent().

93 { return &(mSyllables[nSyl]); };
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
void LyricsPanel::HandleLayout ( )
void LyricsPanel::HandlePaint ( wxDC &  dc)

Definition at line 536 of file Lyrics.cpp.

References HandlePaint_BouncingBall(), kBouncingBallLyrics, mKaraokeHeight, mLyricsStyle, and mWidth.

Referenced by DoPaint().

537 {
538  wxASSERT(mLyricsStyle == kBouncingBallLyrics);
539  dc.SetBrush(*wxWHITE_BRUSH);
540  dc.DrawRectangle(0, 0, mWidth, mKaraokeHeight);
541 
542  this->HandlePaint_BouncingBall(dc);
543 }
void HandlePaint_BouncingBall(wxDC &dc)
Definition: Lyrics.cpp:545
int mKaraokeHeight
Definition: Lyrics.h:134
int mWidth
Definition: Lyrics.h:131
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
void LyricsPanel::HandlePaint_BouncingBall ( wxDC &  dc)

Definition at line 545 of file Lyrics.cpp.

References GetKaraokePosition(), mKaraokeHeight, mSyllables, mT, mTextHeight, mWidth, and SetDrawnFont().

Referenced by HandlePaint().

546 {
547  int ctr = mWidth / 2;
548  int x;
549  double y;
550  GetKaraokePosition(mT, &x, &y);
551 
552  dc.SetTextForeground(wxColour(238, 0, 102));
553  bool changedColor = false;
554 
555  SetDrawnFont(&dc);
556  unsigned int i;
557  wxCoord yTextTop = mKaraokeHeight - mTextHeight - 4;
558  for(i = 0; i < mSyllables.size(); i++) {
559  if (mSyllables[i].x + mSyllables[i].width < (x - ctr))
560  continue;
561  if (mSyllables[i].x > x + ctr)
562  continue;
563 
564  if (!changedColor && mSyllables[i].x >= x) {
565  dc.SetTextForeground(*wxBLACK);
566  changedColor = true;
567  }
568 
569  wxString text = mSyllables[i].text;
570  if (text.Length() > 0 && text.Right(1) == wxT("_")) {
571  text = text.Left(text.Length() - 1);
572  }
573 
574  dc.DrawText(text,
575  mSyllables[i].leftX + ctr - x,
576  yTextTop);
577  }
578 
579  int ballRadius = (int)(mTextHeight / 8.0);
580  int bounceTop = ballRadius * 2;
581  int bounceHeight = yTextTop - bounceTop;
582  int yi = (int)(yTextTop - 4 - (y * bounceHeight));
583 
584  if (mT >= 0.0) {
585  wxRect ball(ctr - ballRadius, yi - ballRadius, 2 * ballRadius, 2 * ballRadius);
586  dc.SetBrush(wxBrush(wxColour(238, 0, 102), wxBRUSHSTYLE_SOLID));
587  dc.DrawEllipse(ball);
588  }
589 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
double mT
Definition: Lyrics.h:140
int mKaraokeHeight
Definition: Lyrics.h:134
void SetDrawnFont(wxDC *dc)
Definition: Lyrics.cpp:246
int mTextHeight
Definition: Lyrics.h:146
int mWidth
Definition: Lyrics.h:131
void GetKaraokePosition(double t, int *outX, double *outY)
Definition: Lyrics.cpp:343
void LyricsPanel::Measure ( wxDC *  dc)
private

Definition at line 259 of file Lyrics.cpp.

References I_FIRST_REAL_SYLLABLE, mMeasurementsDone, mSyllables, mTextHeight, and SetDrawnFont().

Referenced by DoPaint().

260 {
261  this->SetDrawnFont(dc);
262  int width = 0, height = 0;
263 
264  const int kIndent = 4;
265  int x = 2*kIndent;
266 
267  unsigned int i;
268  for(i = 0; i < mSyllables.size(); i++) {
269  if ((i < I_FIRST_REAL_SYLLABLE) || // Clear() starts the list with I_FIRST_REAL_SYLLABLE dummies.
270  (i >= mSyllables.size() - 3)) // Finish() ends with 3 dummies.
271  {
272  dc->GetTextExtent(wxT("DUMMY"), &width, &height); // Get the correct height even if we're at i=0.
273  width = 0;
274  }
275  else {
276  dc->GetTextExtent(mSyllables[i].textWithSpace, &width, &height);
277  }
278 
279  // Add some space between words; the space is normally small but
280  // when there's a long pause relative to the previous word, insert
281  // extra space.
282  int extraWidth;
283  if (i >= I_FIRST_REAL_SYLLABLE && i < mSyllables.size() - 2)
284  {
285  double deltaThis = mSyllables[i+1].t - mSyllables[i].t;
286  double deltaPrev = mSyllables[i].t - mSyllables[i-1].t;
287 
288  double ratio;
289  if (deltaPrev > 0.0)
290  ratio = deltaThis / deltaPrev;
291  else
292  ratio = deltaThis;
293 
294  if (ratio > 2.0)
295  extraWidth = 15 + (int)(15.0 * ratio);
296  else
297  extraWidth = 15;
298  }
299  else
300  extraWidth = 20;
301 
302  mSyllables[i].width = width + extraWidth;
303  mSyllables[i].leftX = x;
304  mSyllables[i].x = x + width/2;
305  x += mSyllables[i].width;
306  }
307 
308  mTextHeight = height;
309 
310  mMeasurementsDone = true;
311 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
#define I_FIRST_REAL_SYLLABLE
Definition: Lyrics.cpp:117
void SetDrawnFont(wxDC *dc)
Definition: Lyrics.cpp:246
int mTextHeight
Definition: Lyrics.h:146
bool mMeasurementsDone
Definition: Lyrics.h:147
void LyricsPanel::OnKeyEvent ( wxKeyEvent &  event)

Definition at line 458 of file Lyrics.cpp.

References CommandManager::FilterKeyEvent(), GetActiveProject(), and AudacityProject::GetCommandManager().

459 {
460  AudacityProject *project = GetActiveProject();
461  project->GetCommandManager()->FilterKeyEvent(project, event, true);
462  event.Skip();
463 }
bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent &evt, bool permit=false)
CommandManager * GetCommandManager()
Definition: Project.h:347
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:175
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:312
void LyricsPanel::OnPaint ( wxPaintEvent &  evt)

Definition at line 465 of file Lyrics.cpp.

References DoPaint().

466 {
467  wxPaintDC dc(this);
468  DoPaint(dc);
469 }
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:471
void LyricsPanel::OnSize ( wxSizeEvent &  evt)

Definition at line 500 of file Lyrics.cpp.

References DoPaint(), GetDefaultFontSize(), kBouncingBallLyrics, LYRICS_DEFAULT_HEIGHT, mHeight, mHighlightTextCtrl, mKaraokeFontSize, mKaraokeHeight, mLyricsStyle, mMeasurementsDone, mWidth, and SetHighlightFont().

Referenced by SetLyricsStyle().

501 {
502  GetClientSize(&mWidth, &mHeight);
503 
505 
507  (int)((float)(this->GetDefaultFontSize() * mHeight) / (float)LYRICS_DEFAULT_HEIGHT);
508  // Usually don't get the size window we want, usually less than
509  // LYRICS_DEFAULT_HEIGHT, so bump it a little.
510  mKaraokeFontSize += 2;
511 
513  {
514  mMeasurementsDone = false;
515  wxClientDC dc(this);
516  this->DoPaint(dc);
517  }
518  else // (mLyricsStyle == kHighlightLyrics)
519  {
521  this->SetHighlightFont();
522  }
523 
524  this->Refresh(false);
525 }
int mHeight
Definition: Lyrics.h:132
void SetHighlightFont()
Definition: Lyrics.cpp:251
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:241
int mKaraokeHeight
Definition: Lyrics.h:134
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:471
int mWidth
Definition: Lyrics.h:131
#define LYRICS_DEFAULT_HEIGHT
Definition: Lyrics.h:25
bool mMeasurementsDone
Definition: Lyrics.h:147
unsigned int mKaraokeFontSize
Definition: Lyrics.h:135
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
void LyricsPanel::SetCurrentSyllableIndex ( int  nSyl)
inline

Definition at line 94 of file Lyrics.h.

References mCurrentSyllable.

94 { mCurrentSyllable = nSyl; };
int mCurrentSyllable
Definition: Lyrics.h:142
void LyricsPanel::SetDrawnFont ( wxDC *  dc)
private

Definition at line 246 of file Lyrics.cpp.

References mKaraokeFontSize.

Referenced by HandlePaint_BouncingBall(), and Measure().

247 {
248  dc->SetFont(wxFont(mKaraokeFontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
249 }
unsigned int mKaraokeFontSize
Definition: Lyrics.h:135
void LyricsPanel::SetHighlightFont ( )
private

Definition at line 251 of file Lyrics.cpp.

References mHighlightTextCtrl, and mKaraokeFontSize.

Referenced by OnSize().

252 {
253  wxFont newFont(mKaraokeFontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
254  mHighlightTextCtrl->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, newFont));
255  mHighlightTextCtrl->SetStyle(0, mHighlightTextCtrl->GetLastPosition(),
256  wxTextAttr(wxNullColour, wxNullColour, newFont));
257 }
unsigned int mKaraokeFontSize
Definition: Lyrics.h:135
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
void LyricsPanel::SetLyricsStyle ( const LyricsStyle  newLyricsStyle)

Definition at line 228 of file Lyrics.cpp.

References kHighlightLyrics, mHighlightTextCtrl, mLyricsStyle, and OnSize().

Referenced by LyricsWindow::OnStyle_BouncingBall(), and LyricsWindow::OnStyle_Highlight().

229 {
230  if (mLyricsStyle == newLyricsStyle)
231  return;
232 
233  mLyricsStyle = newLyricsStyle;
235 
236  wxSizeEvent ignore;
237  this->OnSize(ignore);
238 }
void OnSize(wxSizeEvent &evt)
Definition: Lyrics.cpp:500
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138
void LyricsPanel::Update ( double  t)

Definition at line 418 of file Lyrics.cpp.

References FindSyllable(), GetActiveProject(), AudacityProject::GetSel0(), kBouncingBallLyrics, kHighlightLyrics, mCurrentSyllable, mHighlightTextCtrl, mKaraokeHeight, mLyricsStyle, mSyllables, mT, and mWidth.

Referenced by LyricsWindow::OnTimer(), and AudacityProject::UpdateLyrics().

419 {
420  if (t < 0.0)
421  {
422  // TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive().
423  // In that case, use the selection start time.
425  mT = pProj->GetSel0();
426  }
427  else
428  mT = t;
429 
431  {
432  wxRect karaokeRect(0, 0, mWidth, mKaraokeHeight);
433  this->Refresh(false, &karaokeRect);
434  }
435 
436  int i = FindSyllable(mT);
437  if (i == mCurrentSyllable)
438  return;
439 
440  mCurrentSyllable = i;
441 
443  {
444  mHighlightTextCtrl->SetSelection(mSyllables[i].char0, mSyllables[i].char1);
445 
446  //v No trail for now.
448  //if (i == I_FIRST_REAL_SYLLABLE)
449  // // Reset the trail to zero.
450  // mHighlightTextCtrl->SetStyle(0, mHighlightTextCtrl->GetLastPosition(), wxTextAttr(wxNullColour, *wxWHITE));
452  //mHighlightTextCtrl->SetStyle(mSyllables[i].char0, mSyllables[i].char1, wxTextAttr(wxNullColour, *wxLIGHT_GREY));
453 
454  //v Too much flicker: mHighlightTextCtrl->ShowPosition(mSyllables[i].char0);
455  }
456 }
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
int mCurrentSyllable
Definition: Lyrics.h:142
double GetSel0() const
Definition: Project.h:204
double mT
Definition: Lyrics.h:140
int FindSyllable(long startChar)
Definition: Lyrics.cpp:206
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:175
int mKaraokeHeight
Definition: Lyrics.h:134
int mWidth
Definition: Lyrics.h:131
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:312
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138

Member Data Documentation

int LyricsPanel::mCurrentSyllable
private

Definition at line 142 of file Lyrics.h.

Referenced by Finish(), GetCurrentSyllableIndex(), SetCurrentSyllableIndex(), and Update().

int LyricsPanel::mHeight
private

Definition at line 132 of file Lyrics.h.

Referenced by OnSize().

HighlightTextCtrl* LyricsPanel::mHighlightTextCtrl
private

Definition at line 138 of file Lyrics.h.

Referenced by AddLabels(), Clear(), Finish(), OnSize(), SetHighlightFont(), SetLyricsStyle(), and Update().

unsigned int LyricsPanel::mKaraokeFontSize
private

Definition at line 135 of file Lyrics.h.

Referenced by OnSize(), SetDrawnFont(), and SetHighlightFont().

int LyricsPanel::mKaraokeHeight
private

Definition at line 134 of file Lyrics.h.

Referenced by DoPaint(), HandlePaint(), HandlePaint_BouncingBall(), OnSize(), and Update().

LyricsStyle LyricsPanel::mLyricsStyle
private
bool LyricsPanel::mMeasurementsDone
private

Definition at line 147 of file Lyrics.h.

Referenced by DoPaint(), Finish(), Measure(), and OnSize().

std::vector<Syllable> LyricsPanel::mSyllables
private
double LyricsPanel::mT
private

Definition at line 140 of file Lyrics.h.

Referenced by HandlePaint_BouncingBall(), and Update().

wxString LyricsPanel::mText
private

Definition at line 144 of file Lyrics.h.

Referenced by Add(), and Clear().

int LyricsPanel::mTextHeight
private

Definition at line 146 of file Lyrics.h.

Referenced by HandlePaint_BouncingBall(), and Measure().

int LyricsPanel::mWidth
private

Definition at line 131 of file Lyrics.h.

Referenced by DoPaint(), HandlePaint(), HandlePaint_BouncingBall(), OnSize(), and Update().


The documentation for this class was generated from the following files: