Audacity  2.2.2
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 80 of file Lyrics.cpp.

References safenew.

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

Definition at line 112 of file Lyrics.cpp.

113 {
114 }

Member Function Documentation

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

Definition at line 143 of file Lyrics.cpp.

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

Referenced by AddLabels().

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

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

Referenced by AudacityProject::UpdateLyrics().

133 {
134  const size_t numLabels = pLT->GetNumLabels();
135  wxString highlightText;
136  for (size_t ii = 0; ii < numLabels; ++ii) {
137  const LabelStruct *const pLabel = pLT->GetLabel(ii);
138  Add(pLabel->getT0(), pLabel->title, highlightText);
139  }
140  mHighlightTextCtrl->AppendText(highlightText);
141 }
void Add(double t, const wxString &syllable, wxString &highlightText)
Definition: Lyrics.cpp:143
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 118 of file Lyrics.cpp.

References mHighlightTextCtrl, mSyllables, and mText.

Referenced by AudacityProject::UpdateLyrics().

119 {
120  mSyllables.clear();
121  mText = wxT("");
122 
123  // Add two dummy syllables at the beginning
124  mSyllables.push_back(Syllable());
125  mSyllables[0].t = -2.0;
126  mSyllables.push_back(Syllable());
127  mSyllables[1].t = -1.0;
128 
129  mHighlightTextCtrl->Clear();
130 }
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 470 of file Lyrics.cpp.

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

Referenced by OnPaint(), and OnSize().

471 {
472  if (!this->GetParent()->IsShown())
473  return;
474 
476  {
477  if (!mMeasurementsDone)
478  Measure(&dc);
479 
480  #ifdef __WXMAC__
481  // Mac OS X automatically double-buffers the screen for you,
482  // so our bitmap is unneccessary
483  HandlePaint(dc);
484  #else
485  wxBitmap bitmap(mWidth, mKaraokeHeight);
486  wxMemoryDC memDC;
487  memDC.SelectObject(bitmap);
488  HandlePaint(memDC);
489  dc.Blit(0, 0, mWidth, mKaraokeHeight, &memDC, 0, 0, wxCOPY, FALSE);
490  #endif
491  }
492  else // (mLyricsStyle == kHighlightLyrics)
493  {
494  //v causes flicker in ported version
495  // this->SetHighlightFont();
496  }
497 }
void HandlePaint(wxDC &dc)
Definition: Lyrics.cpp:535
int mKaraokeHeight
Definition: Lyrics.h:134
void Measure(wxDC *dc)
Definition: Lyrics.cpp:258
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 205 of file Lyrics.cpp.

References mSyllables.

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

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

Definition at line 313 of file Lyrics.cpp.

References mSyllables.

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

Definition at line 187 of file Lyrics.cpp.

References mCurrentSyllable, mHighlightTextCtrl, mMeasurementsDone, and mSyllables.

Referenced by AudacityProject::UpdateLyrics().

188 {
189  // Add 3 dummy syllables at the end
190  int i = mSyllables.size();
191  mSyllables.push_back(Syllable());
192  mSyllables[i].t = finalT + 1.0;
193  mSyllables.push_back(Syllable());
194  mSyllables[i+1].t = finalT + 2.0;
195  mSyllables.push_back(Syllable());
196  mSyllables[i+2].t = finalT + 3.0;
197 
198  // Mark measurements as invalid
199  mMeasurementsDone = false; // only for drawn text
200  mCurrentSyllable = 0;
201  mHighlightTextCtrl->ShowPosition(0);
202 }
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 240 of file Lyrics.cpp.

References kBouncingBallLyrics, and mLyricsStyle.

Referenced by OnSize().

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

Definition at line 342 of file Lyrics.cpp.

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

Referenced by HandlePaint_BouncingBall().

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

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

Referenced by DoPaint().

536 {
537  wxASSERT(mLyricsStyle == kBouncingBallLyrics);
538  dc.SetBrush(*wxWHITE_BRUSH);
539  dc.DrawRectangle(0, 0, mWidth, mKaraokeHeight);
540 
541  this->HandlePaint_BouncingBall(dc);
542 }
void HandlePaint_BouncingBall(wxDC &dc)
Definition: Lyrics.cpp:544
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 544 of file Lyrics.cpp.

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

Referenced by HandlePaint().

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

Definition at line 258 of file Lyrics.cpp.

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

Referenced by DoPaint().

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

Definition at line 457 of file Lyrics.cpp.

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

458 {
459  AudacityProject *project = GetActiveProject();
460  project->GetCommandManager()->FilterKeyEvent(project, event, true);
461  event.Skip();
462 }
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:176
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:309
void LyricsPanel::OnPaint ( wxPaintEvent &  evt)

Definition at line 464 of file Lyrics.cpp.

References DoPaint().

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

Definition at line 499 of file Lyrics.cpp.

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

Referenced by SetLyricsStyle().

500 {
501  GetClientSize(&mWidth, &mHeight);
502 
504 
506  (int)((float)(this->GetDefaultFontSize() * mHeight) / (float)LYRICS_DEFAULT_HEIGHT);
507  // Usually don't get the size window we want, usually less than
508  // LYRICS_DEFAULT_HEIGHT, so bump it a little.
509  mKaraokeFontSize += 2;
510 
512  {
513  mMeasurementsDone = false;
514  wxClientDC dc(this);
515  this->DoPaint(dc);
516  }
517  else // (mLyricsStyle == kHighlightLyrics)
518  {
520  this->SetHighlightFont();
521  }
522 
523  this->Refresh(false);
524 }
int mHeight
Definition: Lyrics.h:132
void SetHighlightFont()
Definition: Lyrics.cpp:250
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:240
int mKaraokeHeight
Definition: Lyrics.h:134
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:470
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 245 of file Lyrics.cpp.

References mKaraokeFontSize.

Referenced by HandlePaint_BouncingBall(), and Measure().

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

Definition at line 250 of file Lyrics.cpp.

References mHighlightTextCtrl, and mKaraokeFontSize.

Referenced by OnSize().

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

Definition at line 227 of file Lyrics.cpp.

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

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

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

Definition at line 417 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().

418 {
419  if (t < 0.0)
420  {
421  // TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive().
422  // In that case, use the selection start time.
424  mT = pProj->GetSel0();
425  }
426  else
427  mT = t;
428 
430  {
431  wxRect karaokeRect(0, 0, mWidth, mKaraokeHeight);
432  this->Refresh(false, &karaokeRect);
433  }
434 
435  int i = FindSyllable(mT);
436  if (i == mCurrentSyllable)
437  return;
438 
439  mCurrentSyllable = i;
440 
442  {
443  mHighlightTextCtrl->SetSelection(mSyllables[i].char0, mSyllables[i].char1);
444 
445  //v No trail for now.
447  //if (i == I_FIRST_REAL_SYLLABLE)
448  // // Reset the trail to zero.
449  // mHighlightTextCtrl->SetStyle(0, mHighlightTextCtrl->GetLastPosition(), wxTextAttr(wxNullColour, *wxWHITE));
451  //mHighlightTextCtrl->SetStyle(mSyllables[i].char0, mSyllables[i].char1, wxTextAttr(wxNullColour, *wxLIGHT_GREY));
452 
453  //v Too much flicker: mHighlightTextCtrl->ShowPosition(mSyllables[i].char0);
454  }
455 }
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:205
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
int mKaraokeHeight
Definition: Lyrics.h:134
int mWidth
Definition: Lyrics.h:131
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:309
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: