16#include <wx/dcclient.h>
18#include <wx/dcmemory.h>
20#include <wx/mimetype.h>
37 const wxString& value ,
40: wxTextCtrl(parent,
id,
44 wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_RICH2 | wxTE_AUTO_URL | wxTE_NOHIDESEL),
54 this->GetSelection(&from, &to);
58 if (nNewSyl != nCurSyl)
63 selectedRegion.
setT0( pCurSyl->
t );
68 selectedRegion.setT1( pCurSyl->
t );
92 const wxSize&
size ) :
97 mKaraokeHeight = mHeight;
98 mLyricsStyle = kBouncingBallLyrics;
99 mKaraokeFontSize = this->GetDefaultFontSize();
101 this->SetBackgroundColour(*wxWHITE);
108 this->SetHighlightFont();
109 mHighlightTextCtrl->Show(mLyricsStyle == kHighlightLyrics);
118 wxSizeEvent dummyEvent;
128 mAudioIOSubscription =
136#define I_FIRST_REAL_SYLLABLE 2
155 wxString highlightText;
156 for (
size_t ii = 0; ii < numLabels; ++ii) {
170 if (prevSyllable.
t == t) {
174 prevSyllable.
text += syllable;
176 prevSyllable.
char1 += syllable.length();
184 thisSyllable.
text = syllable;
202 highlightText += (thisSyllable.
textWithSpace.Left(nTextLen - 1) +
wxT(
"\n"));
232 int pmid = (i1+i2)/2;
267 dc->SetFont(wxFont(
mKaraokeFontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
272 wxFont newFont(
mKaraokeFontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
275 wxTextAttr(wxNullColour, wxNullColour, newFont));
281 int width = 0, height = 0;
283 const int kIndent = 4;
291 dc->GetTextExtent(
wxT(
"DUMMY"), &width, &height);
295 dc->GetTextExtent(
mSyllables[i].textWithSpace, &width, &height);
309 ratio = deltaThis / deltaPrev;
314 extraWidth = 15 + (int)(15.0 * ratio);
340 int pmid = (i1+i2)/2;
363 int *outX,
double *outY)
373 double t0, t1, t2, t3;
401 double linear_vel0 = (x1 - x0) / (t1 - t0);
402 double linear_vel1 = (x2 - x1) / (t2 - t1);
403 double linear_vel2 = (x3 - x2) / (t3 - t2);
406 double v1 = (linear_vel0 + linear_vel1) / 2;
407 double v2 = (linear_vel1 + linear_vel2) / 2;
412 double delta_t = t2 - t1;
413 double delta_x = x2 - x1;
416 double a = v1 + v2 - 2*delta_x;
417 double b = 3*delta_x - 2*v1 - v2;
421 t = (t - t1) / (t2 - t1);
422 double xx = a*t*t*t + b*t*t + c*t + d;
433 double height = t2 - t1 > 4.0? 1.0: sqrt((t2-t1)/4.0);
434 *outY = height * sin(
M_PI * t);
445 mT = selectedRegion.t0();
453 this->Refresh(
false, &karaokeRect);
480 switch (message.
type) {
496 if (gAudioIO->IsStreamActive()) {
516 auto parent =
dynamic_cast<wxFrame*
>(GetParent());
517 if( !(parent && parent->IsVisible()) )
521 Finish(pLabelTrack->GetEndTime());
523 Update(selectedRegion.t0());
547 commandManager.FilterKeyEvent(project, event,
true);
559 if (!this->GetParent()->IsShown())
574 memDC.SelectObject(bitmap);
610 this->Refresh(
false);
625 dc.SetBrush(*wxWHITE_BRUSH);
638 dc.SetTextForeground(wxColour(238, 0, 102));
639 bool changedColor =
false;
651 dc.SetTextForeground(*wxBLACK);
656 if (text.length() > 0 && text.Right(1) ==
wxT(
"_")) {
657 text = text.Left(text.length() - 1);
666 int bounceTop = ballRadius * 2;
667 int bounceHeight = yTextTop - bounceTop;
668 int yi = (int)(yTextTop - 4 - (y * bounceHeight));
671 wxRect ball(ctr - ballRadius, yi - ballRadius, 2 * ballRadius, 2 * ballRadius);
672 dc.SetBrush(wxBrush(wxColour(238, 0, 102), wxBRUSHSTYLE_SOLID));
673 dc.DrawEllipse(ball);
#define I_FIRST_REAL_SYLLABLE
#define LYRICS_DEFAULT_HEIGHT
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
static void OnSize(wxSizeEvent &evt)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
static AudioIOBase * Get()
static CommandManager & Get(AudacityProject &project)
void OnMouseEvent(wxMouseEvent &evt)
LyricsPanel * mLyricsPanel
A LabelStruct holds information for ONE label in a LabelTrack.
A LabelTrack is a Track that holds labels (LabelStruct).
const LabelStruct * GetLabel(int index) const
LyricsPanel is a panel that paints the bouncing ball and the lyrics text.
void OnStartStop(AudioIOEvent)
void SetLyricsStyle(const LyricsStyle newLyricsStyle)
int FindSyllable(long startChar)
void HandlePaint(wxDC &dc)
void OnKeyEvent(wxKeyEvent &event)
int GetCurrentSyllableIndex()
void GetKaraokePosition(double t, int *outX, double *outY)
void Finish(double finalT)
HighlightTextCtrl * mHighlightTextCtrl
wxWeakRef< AudacityProject > mProject
unsigned int mKaraokeFontSize
void OnShow(wxShowEvent &e)
Syllable * GetSyllable(int nSyl)
unsigned int GetDefaultFontSize() const
void Add(double t, const wxString &syllable, wxString &highlightText)
void AddLabels(const LabelTrack *pLT)
void OnSize(wxSizeEvent &evt)
void HandlePaint_BouncingBall(wxDC &dc)
void OnPaint(wxPaintEvent &evt)
std::vector< Syllable > mSyllables
void UpdateLyrics(struct UndoRedoMessage)
void SetDrawnFont(wxDC *dc)
bool setT0(double t, bool maySwap=true)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
auto Any() -> TrackIterRange< TrackType >
static TrackList & Get(AudacityProject &project)
static UndoManager & Get(AudacityProject &project)
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
enum AudioIOEvent::Type type
used in LyricsPanel, a Syllable gives positional information to be used with the bouncing ball effect...
Type of message published by UndoManager.
enum UndoRedoMessage::Type type