Audacity  2.2.2
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 #include "Audacity.h"
16 
17 #include <vector>
18 #include <wx/textctrl.h>
19 #include "widgets/wxPanelWrapper.h"
20 
21 class LabelTrack;
22 
23 
24 #define LYRICS_DEFAULT_WIDTH 608
25 #define LYRICS_DEFAULT_HEIGHT 280
26 
27 struct Syllable {
28  Syllable() = default;
29  Syllable( const Syllable& ) = default;
30  Syllable& operator= ( const Syllable& ) = default;
31  //Syllable( Syllable && ) = default;
32  //Syllable& operator= ( Syllable&& ) = default;
33 
34  double t;
35  wxString text;
36  wxString textWithSpace;
37  int char0; // index of first char of syllable in LyricsPanel::mText, used only for kHighlightLyrics
38  int char1; // index of last char of syllable in LyricsPanel::mText, used only for kHighlightLyrics
39  int width;
40  int leftX;
41  int x; // centerX, used only for kBouncingBallLyrics
42 };
43 
44 class LyricsPanel;
45 
46 // Override wxTextCtrl to handle selection events, which the parent ignores if the control is read-only.
47 class HighlightTextCtrl final : public wxTextCtrl
48 {
49 public:
51  wxWindowID id,
52  const wxString& value = wxT(""),
53  const wxPoint& pos = wxDefaultPosition,
54  const wxSize& size = wxDefaultSize);
55  virtual ~HighlightTextCtrl() {};
56 
57  void OnMouseEvent(wxMouseEvent &evt);
58 
59 private:
61 
62  DECLARE_EVENT_TABLE()
63 };
64 
65 
66 /**************************************************************/
71 class LyricsPanel final : public wxPanelWrapper
72 {
73  DECLARE_DYNAMIC_CLASS(LyricsPanel)
74 
75  enum LyricsStyle {
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  };
80 
81  public:
82  LyricsPanel(wxWindow* parent, wxWindowID id,
83  const wxPoint& pos = wxDefaultPosition,
84  const wxSize& size = wxDefaultSize);
85  virtual ~LyricsPanel();
86 
87  void Clear();
88  void AddLabels(const LabelTrack *pLT);
89  void Finish(double finalT);
90 
91  int FindSyllable(long startChar); // Find the syllable whose char0 <= startChar <= char1.
93  Syllable* GetSyllable(int nSyl) { return &(mSyllables[nSyl]); };
94  void SetCurrentSyllableIndex(int nSyl) { mCurrentSyllable = nSyl; };
95 
97  void SetLyricsStyle(const LyricsStyle newLyricsStyle);
98 
99  void Update(double t);
100 
101  //
102  // Event handlers
103  //
104  void OnKeyEvent(wxKeyEvent & event);
105  void DoPaint(wxDC &dc);
106  void OnPaint(wxPaintEvent &evt);
107  void OnSize(wxSizeEvent &evt);
108 
109  // Doesn't seem to be a way to capture a selection event in a read-only wxTextCtrl.
110  // Thus the HighlightTextCtrl class.
111  // void OnHighlightTextCtrl(wxCommandEvent & event);
112 
113  void HandlePaint(wxDC &dc);
114  void HandlePaint_BouncingBall(wxDC &dc);
115 
116  void HandleLayout();
117 
118 private:
119  void Add(double t, const wxString &syllable, wxString &highlightText);
120 
121  unsigned int GetDefaultFontSize() const; // Depends on mLyricsStyle. Call only after mLyricsStyle is set.
122 
123  void SetDrawnFont(wxDC *dc); // for kBouncingBallLyrics
124  void SetHighlightFont(); // for kHighlightLyrics
125 
126  void Measure(wxDC *dc);
127  int FindSyllable(double t);
128  void GetKaraokePosition(double t, int *outX, double *outY);
129 
130 private:
131  int mWidth; // client width
132  int mHeight; // client height
133 
134  int mKaraokeHeight; //v mHeight - mBrandingHeight (so just mHeight now that Branding is removed).
135  unsigned int mKaraokeFontSize;
136 
137  LyricsStyle mLyricsStyle; // default kHighlightLyrics
138  HighlightTextCtrl* mHighlightTextCtrl; // only for kHighlightLyrics
139 
140  double mT;
141 
143  std::vector<Syllable> mSyllables;
144  wxString mText;
145 
146  int mTextHeight; // only for drawn text
147  bool mMeasurementsDone; // only for drawn text
148 
149  DECLARE_EVENT_TABLE()
150 };
151 
152 #endif // __AUDACITY_LYRICS__
std::vector< Syllable > mSyllables
Definition: Lyrics.h:143
int char0
Definition: Lyrics.h:37
void SetLyricsStyle(const LyricsStyle newLyricsStyle)
Definition: Lyrics.cpp:227
int mCurrentSyllable
Definition: Lyrics.h:142
Syllable()=default
Syllable * GetSyllable(int nSyl)
Definition: Lyrics.h:93
void HandlePaint_BouncingBall(wxDC &dc)
Definition: Lyrics.cpp:544
void Add(double t, const wxString &syllable, wxString &highlightText)
Definition: Lyrics.cpp:143
void OnMouseEvent(wxMouseEvent &evt)
Definition: Lyrics.cpp:42
LyricsStyle GetLyricsStyle()
Definition: Lyrics.h:96
void OnPaint(wxPaintEvent &evt)
Definition: Lyrics.cpp:464
virtual ~LyricsPanel()
Definition: Lyrics.cpp:112
int char1
Definition: Lyrics.h:38
void HandlePaint(wxDC &dc)
Definition: Lyrics.cpp:535
int mHeight
Definition: Lyrics.h:132
LyricsPanel * mLyricsPanel
Definition: Lyrics.h:60
void SetCurrentSyllableIndex(int nSyl)
Definition: Lyrics.h:94
int GetCurrentSyllableIndex()
Definition: Lyrics.h:92
void SetHighlightFont()
Definition: Lyrics.cpp:250
double t
Definition: Lyrics.h:34
double mT
Definition: Lyrics.h:140
void Finish(double finalT)
Definition: Lyrics.cpp:187
int leftX
Definition: Lyrics.h:40
HighlightTextCtrl(LyricsPanel *parent, wxWindowID id, const wxString &value=wxT(""), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Lyrics.cpp:28
int FindSyllable(long startChar)
Definition: Lyrics.cpp:205
virtual ~HighlightTextCtrl()
Definition: Lyrics.h:55
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
int width
Definition: Lyrics.h:39
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:240
int mKaraokeHeight
Definition: Lyrics.h:134
void OnSize(wxSizeEvent &evt)
Definition: Lyrics.cpp:499
void SetDrawnFont(wxDC *dc)
Definition: Lyrics.cpp:245
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:470
int mTextHeight
Definition: Lyrics.h:146
void Measure(wxDC *dc)
Definition: Lyrics.cpp:258
wxString text
Definition: Lyrics.h:35
int x
Definition: Lyrics.h:41
int mWidth
Definition: Lyrics.h:131
LyricsPanel is a panel that paints the bouncing ball and the lyrics text.
Definition: Lyrics.h:71
LyricsPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Lyrics.cpp:80
void Update(double t)
Definition: Lyrics.cpp:417
bool mMeasurementsDone
Definition: Lyrics.h:147
wxString textWithSpace
Definition: Lyrics.h:36
unsigned int mKaraokeFontSize
Definition: Lyrics.h:135
wxString mText
Definition: Lyrics.h:144
void HandleLayout()
void OnKeyEvent(wxKeyEvent &event)
Definition: Lyrics.cpp:457
LyricsStyle mLyricsStyle
Definition: Lyrics.h:137
void Clear()
Definition: Lyrics.cpp:118
void GetKaraokePosition(double t, int *outX, double *outY)
Definition: Lyrics.cpp:342
void AddLabels(const LabelTrack *pLT)
Definition: Lyrics.cpp:132
Syllable & operator=(const Syllable &)=default
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:138