Audacity 3.2.0
Lyrics.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Lyrics.h
6
7 Dominic Mazzoni
8 Vaughan Johnson
9
10**********************************************************************/
11
12#ifndef __AUDACITY_LYRICS__
13#define __AUDACITY_LYRICS__
14
15
16
17#include <vector>
18#include <wx/textctrl.h> // to inherit
20#include "wxPanelWrapper.h" // to inherit
21#include "Observer.h"
22
23class AudacityProject;
24struct AudioIOEvent;
25class LabelTrack;
26
27#define LYRICS_DEFAULT_WIDTH 608
28#define LYRICS_DEFAULT_HEIGHT 280
29
32struct Syllable {
33 Syllable() = default;
34 Syllable( const Syllable& ) = default;
35 Syllable& operator= ( const Syllable& ) = default;
36 //Syllable( Syllable && ) = default;
37 //Syllable& operator= ( Syllable&& ) = default;
38
39 double t;
40 wxString text;
41 wxString textWithSpace;
42 int char0; // index of first char of syllable in LyricsPanel::mText, used only for kHighlightLyrics
43 int char1; // index of last char of syllable in LyricsPanel::mText, used only for kHighlightLyrics
44 int width;
45 int leftX;
46 int x; // centerX, used only for kBouncingBallLyrics
47};
48
49class LyricsPanel;
50
51// Override wxTextCtrl to handle selection events, which the parent ignores if the control is read-only.
52class HighlightTextCtrl final : public wxTextCtrl
53{
54public:
56 wxWindowID id,
57 const wxString& value = {},
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize);
60 virtual ~HighlightTextCtrl() {};
61
62 void OnMouseEvent(wxMouseEvent &evt);
63
64private:
66
67 DECLARE_EVENT_TABLE()
68};
69
70
71/**************************************************************/
76class LyricsPanel final
77 : public wxPanelWrapper
79{
80 DECLARE_DYNAMIC_CLASS(LyricsPanel)
81
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 };
87
88 public:
89 LyricsPanel(wxWindow* parent, wxWindowID id,
91 const wxPoint& pos = wxDefaultPosition,
92 const wxSize& size = wxDefaultSize);
93 virtual ~LyricsPanel();
94
95 int FindSyllable(long startChar); // Find the syllable whose char0 <= startChar <= char1.
97 Syllable* GetSyllable(int nSyl) { return &(mSyllables[nSyl]); };
98 void SetCurrentSyllableIndex(int nSyl) { mCurrentSyllable = nSyl; };
99
101 void SetLyricsStyle(const LyricsStyle newLyricsStyle);
102
103 void Update(double t);
104 void UpdateLyrics(struct UndoRedoMessage);
105 void DoUpdateLyrics();
106 void OnShow(wxShowEvent& e);
108
109 //
110 // Event handlers
111 //
112 void OnKeyEvent(wxKeyEvent & event);
113 void DoPaint(wxDC &dc);
114 void OnPaint(wxPaintEvent &evt);
115 void OnSize(wxSizeEvent &evt);
116
117 // Doesn't seem to be a way to capture a selection event in a read-only wxTextCtrl.
118 // Thus the HighlightTextCtrl class.
119 // void OnHighlightTextCtrl(wxCommandEvent & event);
120
121 void HandlePaint(wxDC &dc);
122 void HandlePaint_BouncingBall(wxDC &dc);
123
125
126private:
127 void Clear();
128 void AddLabels(const LabelTrack *pLT);
129 void Finish(double finalT);
130
131 void Add(double t, const wxString &syllable, wxString &highlightText);
132
133 unsigned int GetDefaultFontSize() const; // Depends on mLyricsStyle. Call only after mLyricsStyle is set.
134
135 void SetDrawnFont(wxDC *dc); // for kBouncingBallLyrics
136 void SetHighlightFont(); // for kHighlightLyrics
137
138 void Measure(wxDC *dc);
139 int FindSyllable(double t);
140 void GetKaraokePosition(double t, int *outX, double *outY);
141
142private:
145 ;
146
147 int mWidth; // client width
148 int mHeight; // client height
149
150 int mKaraokeHeight; //v mHeight - mBrandingHeight (so just mHeight now that Branding is removed).
151 unsigned int mKaraokeFontSize;
152
153 LyricsStyle mLyricsStyle; // default kHighlightLyrics
154 HighlightTextCtrl* mHighlightTextCtrl; // only for kHighlightLyrics
155
156 double mT;
157
159 std::vector<Syllable> mSyllables;
160 wxString mText;
161
162 int mTextHeight; // only for drawn text
163 bool mMeasurementsDone; // only for drawn text
164
165 wxWeakRef<AudacityProject> mProject;
166 bool mDelayedUpdate{ false };
167
168 DECLARE_EVENT_TABLE()
169};
170
171#endif // __AUDACITY_LYRICS__
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
void OnMouseEvent(wxMouseEvent &evt)
Definition: Lyrics.cpp:49
LyricsPanel * mLyricsPanel
Definition: Lyrics.h:65
virtual ~HighlightTextCtrl()
Definition: Lyrics.h:60
HighlightTextCtrl(LyricsPanel *parent, wxWindowID id, const wxString &value={}, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Lyrics.cpp:35
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
LyricsPanel is a panel that paints the bouncing ball and the lyrics text.
Definition: Lyrics.h:79
void OnStartStop(AudioIOEvent)
Definition: Lyrics.cpp:526
void SetLyricsStyle(const LyricsStyle newLyricsStyle)
Definition: Lyrics.cpp:247
LyricsPanel(wxWindow *parent, wxWindowID id, AudacityProject *project, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Lyrics.cpp:89
virtual ~LyricsPanel()
Definition: Lyrics.cpp:132
int FindSyllable(long startChar)
Definition: Lyrics.cpp:225
void HandlePaint(wxDC &dc)
Definition: Lyrics.cpp:621
void Update(double t)
Definition: Lyrics.cpp:437
LyricsStyle mLyricsStyle
Definition: Lyrics.h:153
wxString mText
Definition: Lyrics.h:160
void SetHighlightFont()
Definition: Lyrics.cpp:270
double mT
Definition: Lyrics.h:156
void OnKeyEvent(wxKeyEvent &event)
Definition: Lyrics.cpp:543
LyricsStyle GetLyricsStyle()
Definition: Lyrics.h:100
int GetCurrentSyllableIndex()
Definition: Lyrics.h:96
@ kBouncingBallLyrics
Definition: Lyrics.h:83
@ kHighlightLyrics
Definition: Lyrics.h:85
void GetKaraokePosition(double t, int *outX, double *outY)
Definition: Lyrics.cpp:362
int mKaraokeHeight
Definition: Lyrics.h:150
int mCurrentSyllable
Definition: Lyrics.h:158
void Measure(wxDC *dc)
Definition: Lyrics.cpp:278
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:556
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
Syllable * GetSyllable(int nSyl)
Definition: Lyrics.h:97
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:260
bool mDelayedUpdate
Definition: Lyrics.h:166
void Add(double t, const wxString &syllable, wxString &highlightText)
Definition: Lyrics.cpp:163
void HandleLayout()
void AddLabels(const LabelTrack *pLT)
Definition: Lyrics.cpp:152
void OnSize(wxSizeEvent &evt)
Definition: Lyrics.cpp:585
void HandlePaint_BouncingBall(wxDC &dc)
Definition: Lyrics.cpp:630
void DoUpdateLyrics()
Definition: Lyrics.cpp:492
Observer::Subscription mAudioIOSubscription
Definition: Lyrics.h:144
void SetCurrentSyllableIndex(int nSyl)
Definition: Lyrics.h:98
void OnPaint(wxPaintEvent &evt)
Definition: Lyrics.cpp:550
std::vector< Syllable > mSyllables
Definition: Lyrics.h:159
void UpdateLyrics(struct UndoRedoMessage)
Definition: Lyrics.cpp:478
int mTextHeight
Definition: Lyrics.h:162
bool mMeasurementsDone
Definition: Lyrics.h:163
void SetDrawnFont(wxDC *dc)
Definition: Lyrics.cpp:265
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
used in LyricsPanel, a Syllable gives positional information to be used with the bouncing ball effect...
Definition: Lyrics.h:32
int x
Definition: Lyrics.h:46
int leftX
Definition: Lyrics.h:45
int width
Definition: Lyrics.h:44
wxString text
Definition: Lyrics.h:40
Syllable()=default
wxString textWithSpace
Definition: Lyrics.h:41
double t
Definition: Lyrics.h:39
Syllable & operator=(const Syllable &)=default
int char1
Definition: Lyrics.h:43
int char0
Definition: Lyrics.h:42
Syllable(const Syllable &)=default
Type of message published by UndoManager.
Definition: UndoManager.h:55