forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLyrics.h
165 lines (121 loc) · 4.89 KB
/
Lyrics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**********************************************************************
Sneedacity: A Digital Audio Editor
Lyrics.h
Dominic Mazzoni
Vaughan Johnson
**********************************************************************/
#ifndef __SNEEDACITY_LYRICS__
#define __SNEEDACITY_LYRICS__
#include <vector>
#include <wx/textctrl.h> // to inherit
#include "commands/CommandManagerWindowClasses.h"
#include "widgets/wxPanelWrapper.h" // to inherit
class SneedacityProject;
class LabelTrack;
#define LYRICS_DEFAULT_WIDTH 608
#define LYRICS_DEFAULT_HEIGHT 280
/// \brief used in LyricsPanel, a Syllable gives positional information to
/// be used with the bouncing ball effect.
struct Syllable {
Syllable() = default;
Syllable( const Syllable& ) = default;
Syllable& operator= ( const Syllable& ) = default;
//Syllable( Syllable && ) = default;
//Syllable& operator= ( Syllable&& ) = default;
double t;
wxString text;
wxString textWithSpace;
int char0; // index of first char of syllable in LyricsPanel::mText, used only for kHighlightLyrics
int char1; // index of last char of syllable in LyricsPanel::mText, used only for kHighlightLyrics
int width;
int leftX;
int x; // centerX, used only for kBouncingBallLyrics
};
class LyricsPanel;
// Override wxTextCtrl to handle selection events, which the parent ignores if the control is read-only.
class HighlightTextCtrl final : public wxTextCtrl
{
public:
HighlightTextCtrl(LyricsPanel* parent,
wxWindowID id,
const wxString& value = {},
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);
virtual ~HighlightTextCtrl() {};
void OnMouseEvent(wxMouseEvent &evt);
private:
LyricsPanel* mLyricsPanel;
DECLARE_EVENT_TABLE()
};
/**************************************************************//**
\brief LyricsPanel is a panel that paints the bouncing
ball and the lyrics text.
*******************************************************************/
class LyricsPanel final
: public wxPanelWrapper
, public NonKeystrokeInterceptingWindow
{
DECLARE_DYNAMIC_CLASS(LyricsPanel)
enum LyricsStyle {
kBouncingBallLyrics, // Lyrics move from right to left with bouncing ball.
// kGuitarTab, //v <<future>> Guitar Tablature moves from right to left.
kHighlightLyrics, // Lyrics show in scrolling page and syllables highlight successively.
};
public:
LyricsPanel(wxWindow* parent, wxWindowID id,
SneedacityProject *project,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);
virtual ~LyricsPanel();
int FindSyllable(long startChar); // Find the syllable whose char0 <= startChar <= char1.
int GetCurrentSyllableIndex() { return mCurrentSyllable; };
Syllable* GetSyllable(int nSyl) { return &(mSyllables[nSyl]); };
void SetCurrentSyllableIndex(int nSyl) { mCurrentSyllable = nSyl; };
LyricsStyle GetLyricsStyle() { return mLyricsStyle; };
void SetLyricsStyle(const LyricsStyle newLyricsStyle);
void Update(double t);
void UpdateLyrics(wxEvent &e);
void OnShow(wxShowEvent& e);
void OnStartStop(wxCommandEvent &e);
//
// Event handlers
//
void OnKeyEvent(wxKeyEvent & event);
void DoPaint(wxDC &dc);
void OnPaint(wxPaintEvent &evt);
void OnSize(wxSizeEvent &evt);
// Doesn't seem to be a way to capture a selection event in a read-only wxTextCtrl.
// Thus the HighlightTextCtrl class.
// void OnHighlightTextCtrl(wxCommandEvent & event);
void HandlePaint(wxDC &dc);
void HandlePaint_BouncingBall(wxDC &dc);
void HandleLayout();
private:
void Clear();
void AddLabels(const LabelTrack *pLT);
void Finish(double finalT);
void Add(double t, const wxString &syllable, wxString &highlightText);
unsigned int GetDefaultFontSize() const; // Depends on mLyricsStyle. Call only after mLyricsStyle is set.
void SetDrawnFont(wxDC *dc); // for kBouncingBallLyrics
void SetHighlightFont(); // for kHighlightLyrics
void Measure(wxDC *dc);
int FindSyllable(double t);
void GetKaraokePosition(double t, int *outX, double *outY);
private:
int mWidth; // client width
int mHeight; // client height
int mKaraokeHeight; //v mHeight - mBrandingHeight (so just mHeight now that Branding is removed).
unsigned int mKaraokeFontSize;
LyricsStyle mLyricsStyle; // default kHighlightLyrics
HighlightTextCtrl* mHighlightTextCtrl; // only for kHighlightLyrics
double mT;
int mCurrentSyllable;
std::vector<Syllable> mSyllables;
wxString mText;
int mTextHeight; // only for drawn text
bool mMeasurementsDone; // only for drawn text
wxWeakRef<SneedacityProject> mProject;
bool mDelayedUpdate{ false };
DECLARE_EVENT_TABLE()
};
#endif // __SNEEDACITY_LYRICS__