Audacity 3.2.0
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:
[legend]
Collaboration diagram for LyricsPanel:
[legend]

Public Member Functions

 LyricsPanel (wxWindow *parent, wxWindowID id, AudacityProject *project, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
virtual ~LyricsPanel ()
 
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 UpdateLyrics (struct UndoRedoMessage)
 
void DoUpdateLyrics ()
 
void OnShow (wxShowEvent &e)
 
void OnStartStop (AudioIOEvent)
 
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 TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 
- Public Member Functions inherited from NonKeystrokeInterceptingWindow
virtual ~NonKeystrokeInterceptingWindow ()
 

Private Types

enum  LyricsStyle { kBouncingBallLyrics , kHighlightLyrics }
 

Private Member Functions

void Clear ()
 
void AddLabels (const LabelTrack *pLT)
 
void Finish (double finalT)
 
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

Observer::Subscription mAudioIOSubscription
 
Observer::Subscription mUndoSubscription
 
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
 
wxWeakRef< AudacityProjectmProject
 
bool mDelayedUpdate { false }
 

Detailed Description

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

Definition at line 76 of file Lyrics.h.

Member Enumeration Documentation

◆ LyricsStyle

Enumerator
kBouncingBallLyrics 
kHighlightLyrics 

Definition at line 82 of file Lyrics.h.

82 {
83 kBouncingBallLyrics, // Lyrics move from right to left with bouncing ball.
84 // kGuitarTab, //v <<future>> Guitar Tablature moves from right to left.
85 kHighlightLyrics, // Lyrics show in scrolling page and syllables highlight successively.
86 };
@ kBouncingBallLyrics
Definition: Lyrics.h:83
@ kHighlightLyrics
Definition: Lyrics.h:85

Constructor & Destructor Documentation

◆ LyricsPanel()

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

Definition at line 89 of file Lyrics.cpp.

92 :
93 wxPanelWrapper(parent, id, pos, size, wxWANTS_CHARS),
94 mWidth(size.x), mHeight(size.y)
96{
99 mKaraokeFontSize = this->GetDefaultFontSize(); // Call only after mLyricsPanelStyle is set.
100
101 this->SetBackgroundColour(*wxWHITE);
102
104 safenew HighlightTextCtrl(this, -1, // wxWindow* parent, wxWindowID id,
105 wxT(""), // const wxString& value = {},
106 wxPoint(0, 0), // const wxPoint& pos = wxDefaultPosition,
107 size); // const wxSize& size = wxDefaultSize
108 this->SetHighlightFont();
109 mHighlightTextCtrl->Show(mLyricsStyle == kHighlightLyrics); // test, in case we conditionalize the default, above
110
111
112 mT = 0.0;
113
114 Clear();
115 Finish(0.0);
116
117 #ifdef __WXMAC__
118 wxSizeEvent dummyEvent;
119 OnSize(dummyEvent);
120 #endif
121
122 parent->Bind(wxEVT_SHOW, &LyricsPanel::OnShow, this);
123
124 if (project)
127
130}
wxT("CloseDown"))
#define safenew
Definition: MemoryX.h:10
const auto project
static AudioIO * Get()
Definition: AudioIO.cpp:126
void OnStartStop(AudioIOEvent)
Definition: Lyrics.cpp:526
LyricsStyle mLyricsStyle
Definition: Lyrics.h:153
void SetHighlightFont()
Definition: Lyrics.cpp:270
double mT
Definition: Lyrics.h:156
int mKaraokeHeight
Definition: Lyrics.h:150
int mHeight
Definition: Lyrics.h:148
void Finish(double finalT)
Definition: Lyrics.cpp:207
int mWidth
Definition: Lyrics.h:147
void Clear()
Definition: Lyrics.cpp:138
Observer::Subscription mUndoSubscription
Definition: Lyrics.h:145
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:154
wxWeakRef< AudacityProject > mProject
Definition: Lyrics.h:165
unsigned int mKaraokeFontSize
Definition: Lyrics.h:151
void OnShow(wxShowEvent &e)
Definition: Lyrics.cpp:536
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:260
void OnSize(wxSizeEvent &evt)
Definition: Lyrics.cpp:585
Observer::Subscription mAudioIOSubscription
Definition: Lyrics.h:144
void UpdateLyrics(struct UndoRedoMessage)
Definition: Lyrics.cpp:478
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71

References AudioIO::Get(), UndoManager::Get(), OnShow(), OnSize(), OnStartStop(), project, safenew, size, Observer::Publisher< Message, NotifyAll >::Subscribe(), UpdateLyrics(), and wxT().

Here is the call graph for this function:

◆ ~LyricsPanel()

LyricsPanel::~LyricsPanel ( )
virtual

Definition at line 132 of file Lyrics.cpp.

133{
134}

Member Function Documentation

◆ Add()

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

Definition at line 163 of file Lyrics.cpp.

164{
165 int i = mSyllables.size();
166
167 {
168 Syllable &prevSyllable = mSyllables[i - 1];
169
170 if (prevSyllable.t == t) {
171 // We can't have two syllables with the same time, so append
172 // this to the end of the previous one if they're at the
173 // same time.
174 prevSyllable.text += syllable;
175 prevSyllable.textWithSpace += syllable;
176 prevSyllable.char1 += syllable.length();
177 return;
178 }
179 }
180
181 mSyllables.push_back(Syllable());
182 Syllable &thisSyllable = mSyllables[i];
183 thisSyllable.t = t;
184 thisSyllable.text = syllable;
185
186 thisSyllable.char0 = mText.length();
187
188 // Put a space between syllables unless the previous one
189 // ended in a hyphen
190 if (i > 0 &&
191 // mSyllables[i-1].text.length() > 0 &&
192 mSyllables[i - 1].text.Right(1) != wxT("-"))
193 thisSyllable.textWithSpace = wxT(" ") + syllable;
194 else
195 thisSyllable.textWithSpace = syllable;
196
197 mText += thisSyllable.textWithSpace;
198 thisSyllable.char1 = mText.length();
199
200 int nTextLen = thisSyllable.textWithSpace.length();
201 if ((nTextLen > 0) && (thisSyllable.textWithSpace.Right(1) == wxT("_")))
202 highlightText += (thisSyllable.textWithSpace.Left(nTextLen - 1) + wxT("\n"));
203 else
204 highlightText += thisSyllable.textWithSpace;
205}
wxString mText
Definition: Lyrics.h:160
std::vector< Syllable > mSyllables
Definition: Lyrics.h:159
used in LyricsPanel, a Syllable gives positional information to be used with the bouncing ball effect...
Definition: Lyrics.h:32
wxString text
Definition: Lyrics.h:40
wxString textWithSpace
Definition: Lyrics.h:41
double t
Definition: Lyrics.h:39
int char1
Definition: Lyrics.h:43
int char0
Definition: Lyrics.h:42

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

Referenced by AddLabels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddLabels()

void LyricsPanel::AddLabels ( const LabelTrack pLT)
private

Definition at line 152 of file Lyrics.cpp.

153{
154 const size_t numLabels = pLT->GetNumLabels();
155 wxString highlightText;
156 for (size_t ii = 0; ii < numLabels; ++ii) {
157 const LabelStruct *const pLabel = pLT->GetLabel(ii);
158 Add(pLabel->getT0(), pLabel->title, highlightText);
159 }
160 mHighlightTextCtrl->AppendText(highlightText);
161}
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:29
double getT0() const
Definition: LabelTrack.h:39
wxString title
Definition: LabelTrack.h:70
int GetNumLabels() const
Definition: LabelTrack.cpp:961
const LabelStruct * GetLabel(int index) const
Definition: LabelTrack.cpp:966
void Add(double t, const wxString &syllable, wxString &highlightText)
Definition: Lyrics.cpp:163

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

Referenced by DoUpdateLyrics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void LyricsPanel::Clear ( )
private

Definition at line 138 of file Lyrics.cpp.

139{
140 mSyllables.clear();
141 mText = wxT("");
142
143 // Add two dummy syllables at the beginning
144 mSyllables.push_back(Syllable());
145 mSyllables[0].t = -2.0;
146 mSyllables.push_back(Syllable());
147 mSyllables[1].t = -1.0;
148
149 mHighlightTextCtrl->Clear();
150}

References mHighlightTextCtrl, mSyllables, mText, and wxT().

Referenced by DoUpdateLyrics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoPaint()

void LyricsPanel::DoPaint ( wxDC &  dc)

Definition at line 556 of file Lyrics.cpp.

557{
558 if (!this->GetParent()->IsShown())
559 return;
560
562 {
564 Measure(&dc);
565
566 #ifdef __WXMAC__
567 // Mac OS X automatically double-buffers the screen for you,
568 // so our bitmap is unnecessary
569 HandlePaint(dc);
570 #else
571 wxBitmap bitmap(mWidth, mKaraokeHeight);
572 wxMemoryDC memDC;
573 memDC.SelectObject(bitmap);
574 HandlePaint(memDC);
575 dc.Blit(0, 0, mWidth, mKaraokeHeight, &memDC, 0, 0, wxCOPY, FALSE);
576 #endif
577 }
578 else // (mLyricsStyle == kHighlightLyrics)
579 {
580 //v causes flicker in ported version
581 // this->SetHighlightFont();
582 }
583}
void HandlePaint(wxDC &dc)
Definition: Lyrics.cpp:621
void Measure(wxDC *dc)
Definition: Lyrics.cpp:278
bool mMeasurementsDone
Definition: Lyrics.h:163

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

Referenced by OnPaint(), and OnSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoUpdateLyrics()

void LyricsPanel::DoUpdateLyrics ( )

Definition at line 492 of file Lyrics.cpp.

493{
494 // It's crucial to not do that repopulating during playback.
495 auto gAudioIO = AudioIOBase::Get();
496 if (gAudioIO->IsStreamActive()) {
497 mDelayedUpdate = true;
498 return;
499 }
500
501 Clear();
502
503 if (!mProject)
504 return;
505
506 // Lyrics come from only the first label track.
507 auto pLabelTrack =
508 *TrackList::Get(*mProject).Any<const LabelTrack>().begin();
509 if (!pLabelTrack)
510 return;
511
512 // The code that updates the lyrics is rather expensive when there
513 // are a lot of labels.
514 // So - bail out early if the lyrics window is not visible.
515 // We will later force an update when the lyrics window is made visible.
516 auto parent = dynamic_cast<wxFrame*>(GetParent());
517 if( !(parent && parent->IsVisible()) )
518 return;
519
520 AddLabels(pLabelTrack);
521 Finish(pLabelTrack->GetEndTime());
522 const auto &selectedRegion = ViewInfo::Get( *mProject ).selectedRegion;
523 Update(selectedRegion.t0());
524}
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:93
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
void Update(double t)
Definition: Lyrics.cpp:437
bool mDelayedUpdate
Definition: Lyrics.h:166
void AddLabels(const LabelTrack *pLT)
Definition: Lyrics.cpp:152
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1079
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References AddLabels(), TrackList::Any(), Clear(), Finish(), AudioIOBase::Get(), ViewInfo::Get(), TrackList::Get(), mDelayedUpdate, mProject, ViewInfo::selectedRegion, and Update().

Referenced by OnShow(), OnStartStop(), and UpdateLyrics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindSyllable() [1/2]

int LyricsPanel::FindSyllable ( double  t)
private

Definition at line 333 of file Lyrics.cpp.

334{
335 int i1, i2;
336
337 i1 = 0;
338 i2 = mSyllables.size();
339 while (i2 > i1+1) {
340 int pmid = (i1+i2)/2;
341 if (mSyllables[pmid].t > t)
342 i2 = pmid;
343 else
344 i1 = pmid;
345 }
346
347 if (i1 < 2)
348 i1 = 2;
349 if (i1 > (int)(mSyllables.size()) - 3)
350 i1 = mSyllables.size() - 3;
351
352 return i1;
353}

References mSyllables.

◆ FindSyllable() [2/2]

int LyricsPanel::FindSyllable ( long  startChar)

Definition at line 225 of file Lyrics.cpp.

226{
227 int i1, i2;
228
229 i1 = 0;
230 i2 = mSyllables.size();
231 while (i2 > i1+1) {
232 int pmid = (i1+i2)/2;
233 if (mSyllables[pmid].char0 > startChar)
234 i2 = pmid;
235 else
236 i1 = pmid;
237 }
238
239 if (i1 < 2)
240 i1 = 2;
241 if (i1 > (int)(mSyllables.size()) - 3)
242 i1 = mSyllables.size() - 3;
243
244 return i1;
245}

References mSyllables.

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

Here is the caller graph for this function:

◆ Finish()

void LyricsPanel::Finish ( double  finalT)
private

Definition at line 207 of file Lyrics.cpp.

208{
209 // Add 3 dummy syllables at the end
210 int i = mSyllables.size();
211 mSyllables.push_back(Syllable());
212 mSyllables[i].t = finalT + 1.0;
213 mSyllables.push_back(Syllable());
214 mSyllables[i+1].t = finalT + 2.0;
215 mSyllables.push_back(Syllable());
216 mSyllables[i+2].t = finalT + 3.0;
217
218 // Mark measurements as invalid
219 mMeasurementsDone = false; // only for drawn text
221 mHighlightTextCtrl->ShowPosition(0);
222}
int mCurrentSyllable
Definition: Lyrics.h:158

References mCurrentSyllable, mHighlightTextCtrl, mMeasurementsDone, and mSyllables.

Referenced by DoUpdateLyrics().

Here is the caller graph for this function:

◆ GetCurrentSyllableIndex()

int LyricsPanel::GetCurrentSyllableIndex ( )
inline

Definition at line 96 of file Lyrics.h.

96{ return mCurrentSyllable; };

References mCurrentSyllable.

Referenced by HighlightTextCtrl::OnMouseEvent().

Here is the caller graph for this function:

◆ GetDefaultFontSize()

unsigned int LyricsPanel::GetDefaultFontSize ( ) const
private

Definition at line 260 of file Lyrics.cpp.

261{
262 return (mLyricsStyle == kBouncingBallLyrics) ? 48 : 10;
263}

References kBouncingBallLyrics, and mLyricsStyle.

Referenced by OnSize().

Here is the caller graph for this function:

◆ GetKaraokePosition()

void LyricsPanel::GetKaraokePosition ( double  t,
int *  outX,
double *  outY 
)
private

Definition at line 362 of file Lyrics.cpp.

364{
365 *outX = 0;
366 *outY = 0;
367
368 if (t < mSyllables[I_FIRST_REAL_SYLLABLE].t || t > mSyllables[mSyllables.size() - 3].t)
369 return;
370
371 int i0, i1, i2, i3;
372 int x0, x1, x2, x3;
373 double t0, t1, t2, t3;
374 i1 = FindSyllable(t);
375 i2 = i1 + 1;
376
377 // Because we've padded the syllables with two dummies at the beginning
378 // and end, we know that i0...i3 will always exist. Also, we've made
379 // sure that we don't ever have two of the same time, so t2>t1 strictly.
380 //
381 // t
382 // \/
383 // time: t0 t1 t2 t3
384 // pos: x0 x1 x2 x3
385 // index: i0 i1 i2 i3
386 // vel: vel1 vel2
387
388 i0 = i1 - 1;
389 i3 = i2 + 1;
390
391 x0 = mSyllables[i0].x;
392 x1 = mSyllables[i1].x;
393 x2 = mSyllables[i2].x;
394 x3 = mSyllables[i3].x;
395
396 t0 = mSyllables[i0].t;
397 t1 = mSyllables[i1].t;
398 t2 = mSyllables[i2].t;
399 t3 = mSyllables[i3].t;
400
401 double linear_vel0 = (x1 - x0) / (t1 - t0);
402 double linear_vel1 = (x2 - x1) / (t2 - t1);
403 double linear_vel2 = (x3 - x2) / (t3 - t2);
404
405 // average velocities
406 double v1 = (linear_vel0 + linear_vel1) / 2;
407 double v2 = (linear_vel1 + linear_vel2) / 2;
408
409 // Solve a cubic equation f(t) = at^3 + bt^2 + ct + d
410 // which gives the position x as a function of
411 // (t - t1), by constraining f(0), f'(0), f(t2-t1), f'(t2-t1)
412 double delta_t = t2 - t1;
413 double delta_x = x2 - x1;
414 v1 *= delta_t;
415 v2 *= delta_t;
416 double a = v1 + v2 - 2*delta_x;
417 double b = 3*delta_x - 2*v1 - v2;
418 double c = v1;
419 double d = x1;
420
421 t = (t - t1) / (t2 - t1);
422 double xx = a*t*t*t + b*t*t + c*t + d;
423
424 // Unfortunately sometimes our cubic goes backwards. This is a quick
425 // hack to stop that from happening.
426 if (xx < x1)
427 xx = x1;
428
429 *outX = (int)xx;
430
431 // The y position is a simple cosine curve; the max height is a
432 // function of the time.
433 double height = t2 - t1 > 4.0? 1.0: sqrt((t2-t1)/4.0);
434 *outY = height * sin(M_PI * t);
435}
#define M_PI
Definition: Distortion.cpp:30
#define I_FIRST_REAL_SYLLABLE
Definition: Lyrics.cpp:136
int FindSyllable(long startChar)
Definition: Lyrics.cpp:225
__finl float_x4 __vecc sqrt(const float_x4 &a)

References FindSyllable(), I_FIRST_REAL_SYLLABLE, M_PI, mSyllables, and staffpad::audio::simd::sqrt().

Referenced by HandlePaint_BouncingBall().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLyricsStyle()

LyricsStyle LyricsPanel::GetLyricsStyle ( )
inline

Definition at line 100 of file Lyrics.h.

100{ return mLyricsStyle; };

References mLyricsStyle.

◆ GetSyllable()

Syllable * LyricsPanel::GetSyllable ( int  nSyl)
inline

Definition at line 97 of file Lyrics.h.

97{ return &(mSyllables[nSyl]); };

References mSyllables.

Referenced by HighlightTextCtrl::OnMouseEvent().

Here is the caller graph for this function:

◆ HandleLayout()

void LyricsPanel::HandleLayout ( )

◆ HandlePaint()

void LyricsPanel::HandlePaint ( wxDC &  dc)

Definition at line 621 of file Lyrics.cpp.

622{
624 dc.SetBrush(*wxWHITE_BRUSH);
625 dc.DrawRectangle(0, 0, mWidth, mKaraokeHeight);
626
627 this->HandlePaint_BouncingBall(dc);
628}
void HandlePaint_BouncingBall(wxDC &dc)
Definition: Lyrics.cpp:630

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

Referenced by DoPaint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandlePaint_BouncingBall()

void LyricsPanel::HandlePaint_BouncingBall ( wxDC &  dc)

Definition at line 630 of file Lyrics.cpp.

631{
632 int ctr = mWidth / 2;
633 int x;
634 double y;
635 GetKaraokePosition(mT, &x, &y);
636
637 dc.SetTextForeground(wxColour(238, 0, 102));
638 bool changedColor = false;
639
640 SetDrawnFont(&dc);
641 unsigned int i;
642 wxCoord yTextTop = mKaraokeHeight - mTextHeight - 4;
643 for(i = 0; i < mSyllables.size(); i++) {
644 if (mSyllables[i].x + mSyllables[i].width < (x - ctr))
645 continue;
646 if (mSyllables[i].x > x + ctr)
647 continue;
648
649 if (!changedColor && mSyllables[i].x >= x) {
650 dc.SetTextForeground(*wxBLACK);
651 changedColor = true;
652 }
653
654 wxString text = mSyllables[i].text;
655 if (text.length() > 0 && text.Right(1) == wxT("_")) {
656 text = text.Left(text.length() - 1);
657 }
658
659 dc.DrawText(text,
660 mSyllables[i].leftX + ctr - x,
661 yTextTop);
662 }
663
664 int ballRadius = (int)(mTextHeight / 8.0);
665 int bounceTop = ballRadius * 2;
666 int bounceHeight = yTextTop - bounceTop;
667 int yi = (int)(yTextTop - 4 - (y * bounceHeight));
668
669 if (mT >= 0.0) {
670 wxRect ball(ctr - ballRadius, yi - ballRadius, 2 * ballRadius, 2 * ballRadius);
671 dc.SetBrush(wxBrush(wxColour(238, 0, 102), wxBRUSHSTYLE_SOLID));
672 dc.DrawEllipse(ball);
673 }
674}
void GetKaraokePosition(double t, int *outX, double *outY)
Definition: Lyrics.cpp:362
int mTextHeight
Definition: Lyrics.h:162
void SetDrawnFont(wxDC *dc)
Definition: Lyrics.cpp:265

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

Referenced by HandlePaint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Measure()

void LyricsPanel::Measure ( wxDC *  dc)
private

Definition at line 278 of file Lyrics.cpp.

279{
280 this->SetDrawnFont(dc);
281 int width = 0, height = 0;
282
283 const int kIndent = 4;
284 int x = 2*kIndent;
285
286 unsigned int i;
287 for(i = 0; i < mSyllables.size(); i++) {
288 if ((i < I_FIRST_REAL_SYLLABLE) || // Clear() starts the list with I_FIRST_REAL_SYLLABLE dummies.
289 (i >= mSyllables.size() - 3)) // Finish() ends with 3 dummies.
290 {
291 dc->GetTextExtent(wxT("DUMMY"), &width, &height); // Get the correct height even if we're at i=0.
292 width = 0;
293 }
294 else {
295 dc->GetTextExtent(mSyllables[i].textWithSpace, &width, &height);
296 }
297
298 // Add some space between words; the space is normally small but
299 // when there's a long pause relative to the previous word, insert
300 // extra space.
301 int extraWidth;
302 if (i >= I_FIRST_REAL_SYLLABLE && i < mSyllables.size() - 2)
303 {
304 double deltaThis = mSyllables[i+1].t - mSyllables[i].t;
305 double deltaPrev = mSyllables[i].t - mSyllables[i-1].t;
306
307 double ratio;
308 if (deltaPrev > 0.0)
309 ratio = deltaThis / deltaPrev;
310 else
311 ratio = deltaThis;
312
313 if (ratio > 2.0)
314 extraWidth = 15 + (int)(15.0 * ratio);
315 else
316 extraWidth = 15;
317 }
318 else
319 extraWidth = 20;
320
321 mSyllables[i].width = width + extraWidth;
322 mSyllables[i].leftX = x;
323 mSyllables[i].x = x + width/2;
324 x += mSyllables[i].width;
325 }
326
327 mTextHeight = height;
328
329 mMeasurementsDone = true;
330}

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

Referenced by DoPaint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnKeyEvent()

void LyricsPanel::OnKeyEvent ( wxKeyEvent &  event)

Definition at line 543 of file Lyrics.cpp.

544{
545 if (auto project = FindProjectFromWindow(this))
547 event.Skip();
548}
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
static bool FilterKeyEvent(AudacityProject &project, const wxKeyEvent &evt, bool permit=false)

References MenuCreator::FilterKeyEvent(), FindProjectFromWindow(), and project.

Here is the call graph for this function:

◆ OnPaint()

void LyricsPanel::OnPaint ( wxPaintEvent &  evt)

Definition at line 550 of file Lyrics.cpp.

551{
552 wxPaintDC dc(this);
553 DoPaint(dc);
554}
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:556

References DoPaint().

Here is the call graph for this function:

◆ OnShow()

void LyricsPanel::OnShow ( wxShowEvent &  e)

Definition at line 536 of file Lyrics.cpp.

537{
538 e.Skip();
539 if (e.IsShown())
541}
void DoUpdateLyrics()
Definition: Lyrics.cpp:492

References DoUpdateLyrics().

Referenced by LyricsPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSize()

void LyricsPanel::OnSize ( wxSizeEvent &  evt)

Definition at line 585 of file Lyrics.cpp.

586{
587 GetClientSize(&mWidth, &mHeight);
588
590
592 (int)((float)(this->GetDefaultFontSize() * mHeight) / (float)LYRICS_DEFAULT_HEIGHT);
593 // Usually don't get the size window we want, usually less than
594 // LYRICS_DEFAULT_HEIGHT, so bump it a little.
595 mKaraokeFontSize += 2;
596
598 {
599 mMeasurementsDone = false;
600 wxClientDC dc(this);
601 this->DoPaint(dc);
602 }
603 else // (mLyricsStyle == kHighlightLyrics)
604 {
606 this->SetHighlightFont();
607 }
608
609 this->Refresh(false);
610}
#define LYRICS_DEFAULT_HEIGHT
Definition: Lyrics.h:28

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

Referenced by SetLyricsStyle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnStartStop()

void LyricsPanel::OnStartStop ( AudioIOEvent  e)

Definition at line 526 of file Lyrics.cpp.

527{
529 return;
530 if ( !e.on && mDelayedUpdate ) {
531 mDelayedUpdate = false;
533 }
534}
bool on
Definition: AudioIO.h:66
enum AudioIOEvent::Type type

References DoUpdateLyrics(), mDelayedUpdate, AudioIOEvent::MONITOR, AudioIOEvent::on, and AudioIOEvent::type.

Referenced by LyricsPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCurrentSyllableIndex()

void LyricsPanel::SetCurrentSyllableIndex ( int  nSyl)
inline

Definition at line 98 of file Lyrics.h.

98{ mCurrentSyllable = nSyl; };

References mCurrentSyllable.

◆ SetDrawnFont()

void LyricsPanel::SetDrawnFont ( wxDC *  dc)
private

Definition at line 265 of file Lyrics.cpp.

266{
267 dc->SetFont(wxFont(mKaraokeFontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
268}

References mKaraokeFontSize.

Referenced by HandlePaint_BouncingBall(), and Measure().

Here is the caller graph for this function:

◆ SetHighlightFont()

void LyricsPanel::SetHighlightFont ( )
private

Definition at line 270 of file Lyrics.cpp.

271{
272 wxFont newFont(mKaraokeFontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
273 mHighlightTextCtrl->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, newFont));
274 mHighlightTextCtrl->SetStyle(0, mHighlightTextCtrl->GetLastPosition(),
275 wxTextAttr(wxNullColour, wxNullColour, newFont));
276}

References mHighlightTextCtrl, and mKaraokeFontSize.

Referenced by OnSize().

Here is the caller graph for this function:

◆ SetLyricsStyle()

void LyricsPanel::SetLyricsStyle ( const LyricsStyle  newLyricsStyle)

Definition at line 247 of file Lyrics.cpp.

248{
249 if (mLyricsStyle == newLyricsStyle)
250 return;
251
252 mLyricsStyle = newLyricsStyle;
254
255 wxSizeEvent ignore;
256 this->OnSize(ignore);
257}

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update()

void LyricsPanel::Update ( double  t)

Definition at line 437 of file Lyrics.cpp.

438{
439 if (t < 0.0)
440 {
441 // TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive().
442 // In that case, use the selection start time.
443 auto pProj = FindProjectFromWindow( this );
444 const auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
445 mT = selectedRegion.t0();
446 }
447 else
448 mT = t;
449
451 {
452 wxRect karaokeRect(0, 0, mWidth, mKaraokeHeight);
453 this->Refresh(false, &karaokeRect);
454 }
455
456 int i = FindSyllable(mT);
457 if (i == mCurrentSyllable)
458 return;
459
461
463 {
464 mHighlightTextCtrl->SetSelection(mSyllables[i].char0, mSyllables[i].char1);
465
466 //v No trail for now.
468 //if (i == I_FIRST_REAL_SYLLABLE)
469 // // Reset the trail to zero.
470 // mHighlightTextCtrl->SetStyle(0, mHighlightTextCtrl->GetLastPosition(), wxTextAttr(wxNullColour, *wxWHITE));
472 //mHighlightTextCtrl->SetStyle(mSyllables[i].char0, mSyllables[i].char1, wxTextAttr(wxNullColour, *wxLIGHT_GREY));
473
474 //v Too much flicker: mHighlightTextCtrl->ShowPosition(mSyllables[i].char0);
475 }
476}

References FindProjectFromWindow(), FindSyllable(), ViewInfo::Get(), kBouncingBallLyrics, kHighlightLyrics, mCurrentSyllable, mHighlightTextCtrl, mKaraokeHeight, mLyricsStyle, mSyllables, mT, mWidth, and ViewInfo::selectedRegion.

Referenced by DoUpdateLyrics(), and LyricsWindow::OnTimer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateLyrics()

void LyricsPanel::UpdateLyrics ( struct UndoRedoMessage  message)

Definition at line 478 of file Lyrics.cpp.

479{
480 switch (message.type) {
485 break;
486 default:
487 return;
488 }
490}
enum UndoRedoMessage::Type type

References DoUpdateLyrics(), UndoRedoMessage::Modified, UndoRedoMessage::Pushed, UndoRedoMessage::Reset, UndoRedoMessage::type, and UndoRedoMessage::UndoOrRedo.

Referenced by LyricsPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAudioIOSubscription

Observer::Subscription LyricsPanel::mAudioIOSubscription
private

Definition at line 143 of file Lyrics.h.

◆ mCurrentSyllable

int LyricsPanel::mCurrentSyllable
private

Definition at line 158 of file Lyrics.h.

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

◆ mDelayedUpdate

bool LyricsPanel::mDelayedUpdate { false }
private

Definition at line 166 of file Lyrics.h.

Referenced by DoUpdateLyrics(), and OnStartStop().

◆ mHeight

int LyricsPanel::mHeight
private

Definition at line 148 of file Lyrics.h.

Referenced by OnSize().

◆ mHighlightTextCtrl

HighlightTextCtrl* LyricsPanel::mHighlightTextCtrl
private

Definition at line 154 of file Lyrics.h.

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

◆ mKaraokeFontSize

unsigned int LyricsPanel::mKaraokeFontSize
private

Definition at line 151 of file Lyrics.h.

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

◆ mKaraokeHeight

int LyricsPanel::mKaraokeHeight
private

Definition at line 150 of file Lyrics.h.

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

◆ mLyricsStyle

LyricsStyle LyricsPanel::mLyricsStyle
private

◆ mMeasurementsDone

bool LyricsPanel::mMeasurementsDone
private

Definition at line 163 of file Lyrics.h.

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

◆ mProject

wxWeakRef<AudacityProject> LyricsPanel::mProject
private

Definition at line 165 of file Lyrics.h.

Referenced by DoUpdateLyrics().

◆ mSyllables

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

◆ mT

double LyricsPanel::mT
private

Definition at line 156 of file Lyrics.h.

Referenced by HandlePaint_BouncingBall(), and Update().

◆ mText

wxString LyricsPanel::mText
private

Definition at line 160 of file Lyrics.h.

Referenced by Add(), and Clear().

◆ mTextHeight

int LyricsPanel::mTextHeight
private

Definition at line 162 of file Lyrics.h.

Referenced by HandlePaint_BouncingBall(), and Measure().

◆ mUndoSubscription

Observer::Subscription LyricsPanel::mUndoSubscription
private

Definition at line 144 of file Lyrics.h.

◆ mWidth

int LyricsPanel::mWidth
private

Definition at line 147 of file Lyrics.h.

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


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