Audacity  2.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 #include "Audacity.h"
16 
17 #include <wx/dynarray.h>
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  double t;
29  wxString text;
30  wxString textWithSpace;
31  int char0; // index of first char of syllable in Lyrics::mText, used only for kHighlightLyrics
32  int char1; // index of last char of syllable in Lyrics::mText, used only for kHighlightLyrics
33  int width;
34  int leftX;
35  int x; // centerX, used only for kBouncingBallLyrics
36 };
37 
38 WX_DECLARE_OBJARRAY(Syllable, SyllableArray);
39 
40 class Lyrics;
41 
42 // Override wxTextCtrl to handle selection events, which the parent ignores if the control is read-only.
43 class HighlightTextCtrl final : public wxTextCtrl
44 {
45 public:
46  HighlightTextCtrl(Lyrics* parent,
47  wxWindowID id,
48  const wxString& value = wxT(""),
49  const wxPoint& pos = wxDefaultPosition,
50  const wxSize& size = wxDefaultSize);
51  virtual ~HighlightTextCtrl() {};
52 
53  void OnMouseEvent(wxMouseEvent &evt);
54 
55 private:
57 
58  DECLARE_EVENT_TABLE()
59 };
60 
61 class Lyrics final : public wxPanelWrapper
62 {
63  DECLARE_DYNAMIC_CLASS(Lyrics)
64 
65  enum LyricsStyle {
66  kBouncingBallLyrics, // Lyrics move from right to left with bouncing ball.
67  // kGuitarTab, //v <<future>> Guitar Tablature moves from right to left.
68  kHighlightLyrics, // Lyrics show in scrolling page and syllables highlight successively.
69  };
70 
71  public:
72  Lyrics(wxWindow* parent, wxWindowID id,
73  const wxPoint& pos = wxDefaultPosition,
74  const wxSize& size = wxDefaultSize);
75  virtual ~Lyrics();
76 
77  void Clear();
78  void AddLabels(const LabelTrack *pLT);
79  void Finish(double finalT);
80 
81  int FindSyllable(long startChar); // Find the syllable whose char0 <= startChar <= char1.
83  Syllable* GetSyllable(int nSyl) { return &(mSyllables[nSyl]); };
84  void SetCurrentSyllableIndex(int nSyl) { mCurrentSyllable = nSyl; };
85 
87  void SetLyricsStyle(const LyricsStyle newLyricsStyle);
88 
89  void Update(double t);
90 
91  //
92  // Event handlers
93  //
94  void OnKeyEvent(wxKeyEvent & event);
95  void DoPaint(wxDC &dc);
96  void OnPaint(wxPaintEvent &evt);
97  void OnSize(wxSizeEvent &evt);
98 
99  // Doesn't seem to be a way to capture a selection event in a read-only wxTextCtrl.
100  // Thus the HighlightTextCtrl class.
101  // void OnHighlightTextCtrl(wxCommandEvent & event);
102 
103  void HandlePaint(wxDC &dc);
104  void HandlePaint_BouncingBall(wxDC &dc);
105 
106  void HandleLayout();
107 
108 private:
109  void Add(double t, const wxString &syllable, wxString &highlightText);
110 
111  unsigned int GetDefaultFontSize() const; // Depends on mLyricsStyle. Call only after mLyricsStyle is set.
112 
113  void SetDrawnFont(wxDC *dc); // for kBouncingBallLyrics
114  void SetHighlightFont(); // for kHighlightLyrics
115 
116  void Measure(wxDC *dc);
117  int FindSyllable(double t);
118  void GetKaraokePosition(double t, int *outX, double *outY);
119 
120 private:
121  int mWidth; // client width
122  int mHeight; // client height
123 
124  int mKaraokeHeight; //v mHeight - mBrandingHeight (so just mHeight now that Branding is removed).
125  unsigned int mKaraokeFontSize;
126 
127  LyricsStyle mLyricsStyle; // default kHighlightLyrics
128  HighlightTextCtrl* mHighlightTextCtrl; // only for kHighlightLyrics
129 
130  double mT;
131 
133  SyllableArray mSyllables;
134  wxString mText;
135 
136  int mTextHeight; // only for drawn text
137  bool mMeasurementsDone; // only for drawn text
138 
139  DECLARE_EVENT_TABLE()
140 };
141 
142 #endif // __AUDACITY_LYRICS__
int char0
Definition: Lyrics.h:31
void Update(double t)
Definition: Lyrics.cpp:420
unsigned int mKaraokeFontSize
Definition: Lyrics.h:125
void Finish(double finalT)
Definition: Lyrics.cpp:190
void HandleLayout()
void GetKaraokePosition(double t, int *outX, double *outY)
Definition: Lyrics.cpp:345
void OnMouseEvent(wxMouseEvent &evt)
Definition: Lyrics.cpp:45
LyricsStyle
Definition: Lyrics.h:65
int mWidth
Definition: Lyrics.h:121
Definition: Lyrics.h:43
int char1
Definition: Lyrics.h:32
Lyrics(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Lyrics.cpp:83
int mHeight
Definition: Lyrics.h:122
void SetHighlightFont()
Definition: Lyrics.cpp:253
double t
Definition: Lyrics.h:28
LyricsStyle mLyricsStyle
Definition: Lyrics.h:127
Definition: wxPanelWrapper.h:19
int GetCurrentSyllableIndex()
Definition: Lyrics.h:82
Definition: Lyrics.h:66
void HandlePaint(wxDC &dc)
Definition: Lyrics.cpp:538
int leftX
Definition: Lyrics.h:34
int mCurrentSyllable
Definition: Lyrics.h:132
virtual ~HighlightTextCtrl()
Definition: Lyrics.h:51
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:114
void Measure(wxDC *dc)
Definition: Lyrics.cpp:261
int width
Definition: Lyrics.h:33
void SetCurrentSyllableIndex(int nSyl)
Definition: Lyrics.h:84
void OnKeyEvent(wxKeyEvent &event)
Definition: Lyrics.cpp:460
void SetDrawnFont(wxDC *dc)
Definition: Lyrics.cpp:248
void AddLabels(const LabelTrack *pLT)
Definition: Lyrics.cpp:135
HighlightTextCtrl * mHighlightTextCtrl
Definition: Lyrics.h:128
void SetLyricsStyle(const LyricsStyle newLyricsStyle)
Definition: Lyrics.cpp:230
int mTextHeight
Definition: Lyrics.h:136
void OnSize(wxSizeEvent &evt)
Definition: Lyrics.cpp:502
WX_DECLARE_OBJARRAY(Syllable, SyllableArray)
int FindSyllable(long startChar)
Definition: Lyrics.cpp:208
wxString text
Definition: Lyrics.h:29
int x
Definition: Lyrics.h:35
void HandlePaint_BouncingBall(wxDC &dc)
Definition: Lyrics.cpp:547
Syllable * GetSyllable(int nSyl)
Definition: Lyrics.h:83
Definition: Lyrics.h:61
HighlightTextCtrl(Lyrics *parent, wxWindowID id, const wxString &value=wxT(""), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Lyrics.cpp:31
bool mMeasurementsDone
Definition: Lyrics.h:137
wxString mText
Definition: Lyrics.h:134
void DoPaint(wxDC &dc)
Definition: Lyrics.cpp:473
unsigned int GetDefaultFontSize() const
Definition: Lyrics.cpp:243
int mKaraokeHeight
Definition: Lyrics.h:124
wxString textWithSpace
Definition: Lyrics.h:30
SyllableArray mSyllables
Definition: Lyrics.h:133
Definition: Lyrics.h:27
void OnPaint(wxPaintEvent &evt)
Definition: Lyrics.cpp:467
void Clear()
Definition: Lyrics.cpp:121
Definition: Lyrics.h:68
void Add(double t, const wxString &syllable, wxString &highlightText)
Definition: Lyrics.cpp:146
LyricsStyle GetLyricsStyle()
Definition: Lyrics.h:86
virtual ~Lyrics()
Definition: Lyrics.cpp:115
Lyrics * mLyrics
Definition: Lyrics.h:56
double mT
Definition: Lyrics.h:130