Audacity 3.2.0
LyricsWindow.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LyricsWindow.cpp
6
7 Vaughan Johnson
8 Dominic Mazzoni
9
10**********************************************************************/
11
12#include "LyricsWindow.h"
13#include "Lyrics.h"
14#include "AudioIO.h"
15#include "CommonCommandFlags.h"
16#include "LabelTrack.h"
17#include "prefs/GUISettings.h" // for RTL_WORKAROUND
18#include "Project.h"
19#include "ProjectAudioIO.h"
20#include "ProjectFileIO.h"
21#include "ProjectWindow.h"
22#include "ProjectWindows.h"
23#include "ViewInfo.h"
24
25#include <wx/app.h>
26#include <wx/toolbar.h>
27#include <wx/settings.h>
28
29#ifdef __WXMSW__
30 #include "../images/AudacityLogo.xpm"
31#else
32 #include "../images/AudacityLogo48x48.xpm"
33#endif
34
35#ifdef __WXMAC__
36 #include <Carbon/Carbon.h>
37#endif
38
39#define AudacityKaraokeTitle XO("Audacity Karaoke%s")
40
41enum {
44};
45
46BEGIN_EVENT_TABLE(LyricsWindow, wxFrame)
51
53
55 : wxFrame( &GetProjectFrame( *parent ), -1, wxString{},
56 wxPoint(100, 300), gSize,
57 //v Bug in wxFRAME_FLOAT_ON_PARENT:
58 // If both the project frame and LyricsWindow are minimized and you restore LyricsWindow,
59 // you can't restore project frame until you close LyricsWindow, but then project frame and
60 // LyricsWindow are restored but LyricsWindow is unresponsive because it thinks it's not shown.
61 // wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT)
62 wxDEFAULT_FRAME_STYLE)
63{
64 //vvv Still necessary? It's commented out in ToolManager and Meter, so I did so here.
65 // #ifdef __WXMAC__
66 // // WXMAC doesn't support wxFRAME_FLOAT_ON_PARENT, so we do
67 // SetWindowClass((WindowRef) MacGetWindowRef(), kFloatingWindowClass);
68 // #endif
69 auto pProject = parent->shared_from_this();
70 mProject = pProject;
71
72 SetWindowTitle();
73 mTitleChangeSubscription = ProjectFileIO::Get(*parent)
74 .Subscribe([this](ProjectFileIOMessage message){
76 SetWindowTitle();
77 });
78
79 // loads either the XPM or the windows resource, depending on the platform
80#if !defined(__WXMAC__) && !defined(__WXX11__)
81 {
82#ifdef __WXMSW__
83 wxIcon ic{ wxICON(AudacityLogo) };
84#else
85 wxIcon ic{wxICON(AudacityLogo48x48)};
86#endif
87 SetIcon(ic);
88 }
89 #endif
90
91 wxPoint panelPos(0, 0);
92 wxSize panelSize = gSize;
93
94 //vvv not yet working right in ported version, so choice is disabled.
95 // It seems when you select highlight style, the TrackPanel timer stops working, but
96 // going back to bouncing ball style starts it up again (!!!), per breakpoints in TrackPanel::OnTimer().
97 //
98 //wxToolBar* pToolBar = this->CreateToolBar();
99 //const int kHorizMargin = 8;
100 //wxASSERT(pToolBar); // To justify safenew
101 //wxRadioButton* pRadioButton_BouncingBall =
102 // safenew wxRadioButton(pToolBar, kID_RadioButton_BouncingBall, _("Bouncing Ball"), wxPoint(kHorizMargin, 4),
103 // wxDefaultSize, wxRB_GROUP);
105 //wxSize tbSize = pToolBar->GetSize();
106 //wxSize btnSize = pRadioButton_BouncingBall->GetSize();
107 //int top = (tbSize.GetHeight() - btnSize.GetHeight()) / 2;
108 //pRadioButton_BouncingBall->Move(kHorizMargin, top);
109 //pToolBar->AddControl(pRadioButton_BouncingBall);
110 //
111 //int left = kHorizMargin + btnSize.GetWidth() + kHorizMargin; //vvv Doesn't actually work. Probably need sizers.
112 //wxRadioButton* pRadioButton_Highlight =
113 // safenew wxRadioButton(pToolBar, kID_RadioButton_Highlight, _("Highlight"), wxPoint(left, top));
114 //pToolBar->AddControl(pRadioButton_Highlight);
115 //
116 //panelPos.x += tbSize.GetHeight();
117 //panelSize.y -= tbSize.GetHeight();
118 //
119 //#if defined(__WXMAC__)
120 // wxColour face = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
121 // pRadioButton_BouncingBall->SetBackgroundColour(face);
122 // pRadioButton_Highlight->SetBackgroundColour(face);
123 //#endif
124 //
125 //pToolBar->Realize();
126
127 mLyricsPanel = safenew LyricsPanel(this, -1, parent, panelPos, panelSize);
128 RTL_WORKAROUND(mLyricsPanel);
129
130 //vvv Highlight style is broken in ported version.
131 //switch (mLyricsPanel->GetLyricsStyle())
132 //{
133 // case LyricsPanel::kBouncingBallLyrics:
134 // pRadioButton_BouncingBall->SetValue(true); break;
135 // case LyricsPanel::kHighlightLyrics:
136 // default:
137 // pRadioButton_Highlight->SetValue(true); break;
138 //}
139
140 // Events from the project don't propagate directly to this other frame, so...
141 if (pProject)
142 mTimerSubscription = ProjectWindow::Get( *pProject ).GetPlaybackScroller()
144 Center();
145}
146
147void LyricsWindow::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
148{
149 this->Hide();
150}
151
152void LyricsWindow::OnStyle_BouncingBall(wxCommandEvent & WXUNUSED(event))
153{
155}
156
157void LyricsWindow::OnStyle_Highlight(wxCommandEvent & WXUNUSED(event))
158{
160}
161
163{
164 if (auto pProject = mProject.lock()) {
165 if (ProjectAudioIO::Get( *pProject ).IsAudioActive())
166 {
167 auto gAudioIO = AudioIO::Get();
168 GetLyricsPanel()->Update(gAudioIO->GetStreamTime());
169 }
170 else
171 {
172 // Reset lyrics display.
173 const auto &selectedRegion = ViewInfo::Get( *pProject ).selectedRegion;
174 GetLyricsPanel()->Update(selectedRegion.t0());
175 }
176 }
177}
178
180{
181 wxString name;
182 if (auto pProject = mProject.lock()) {
183 name = pProject->GetProjectName();
184 if (!name.empty())
185 name.Prepend(wxT(" - "));
186 }
187
188 SetTitle(AudacityKaraokeTitle.Format(name).Translation());
189}
190
192{
194}
195
196// Remaining code hooks this add-on into the application
197#include "CommandContext.h"
198#include "MenuRegistry.h"
199
200namespace {
201
202// Lyrics window attached to each project is built on demand by:
203AttachedWindows::RegisteredFactory sLyricsWindowKey{
204 []( AudacityProject &parent ) -> wxWeakRef< wxWindow > {
205 return safenew LyricsWindow( &parent );
206 }
207};
208
209// Define our extra menu item that invokes that factory
210void OnKaraoke(const CommandContext &context)
211{
212 auto &project = context.project;
213
214 auto lyricsWindow = &GetAttachedWindows(project).Get(sLyricsWindowKey);
215 lyricsWindow->Show();
216 lyricsWindow->Raise();
217}
218
219// Register that menu item
220
221using namespace MenuRegistry;
223 Command( wxT("Karaoke"), XXO("&Karaoke"), OnKaraoke,
225 wxT("View/Windows")
226};
227
228}
wxT("CloseDown"))
END_EVENT_TABLE()
const ReservedCommandFlag & LabelTracksExistFlag()
const TranslatableString name
Definition: Distortion.cpp:76
XXO("&Cut/Copy/Paste Toolbar")
#define RTL_WORKAROUND(pWnd)
Definition: GUISettings.h:20
#define LYRICS_DEFAULT_HEIGHT
Definition: Lyrics.h:28
#define LYRICS_DEFAULT_WIDTH
Definition: Lyrics.h:27
#define AudacityKaraokeTitle
const wxSize gSize
@ kID_RadioButton_BouncingBall
@ kID_RadioButton_Highlight
#define safenew
Definition: MemoryX.h:10
ProjectFileIOMessage
Subscribe to ProjectFileIO to receive messages; always in idle time.
Definition: ProjectFileIO.h:50
@ ProjectTitleChange
A normal occurrence.
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
accessors for certain important windows associated with each project
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
static AudioIO * Get()
Definition: AudioIO.cpp:126
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:317
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
LyricsPanel is a panel that paints the bouncing ball and the lyrics text.
Definition: Lyrics.h:79
void SetLyricsStyle(const LyricsStyle newLyricsStyle)
Definition: Lyrics.cpp:247
void Update(double t)
Definition: Lyrics.cpp:437
@ kBouncingBallLyrics
Definition: Lyrics.h:83
@ kHighlightLyrics
Definition: Lyrics.h:85
void UpdatePrefs() override
void OnStyle_BouncingBall(wxCommandEvent &evt)
void OnStyle_Highlight(wxCommandEvent &evt)
void OnCloseWindow(wxCloseEvent &WXUNUSED(event))
LyricsPanel * GetLyricsPanel()
Definition: LyricsWindow.h:31
void SetWindowTitle()
std::weak_ptr< AudacityProject > mProject
Definition: LyricsWindow.h:45
LyricsPanel * mLyricsPanel
Definition: LyricsWindow.h:46
void OnTimer(Observer::Message)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
static ProjectFileIO & Get(AudacityProject &project)
PlaybackScroller & GetPlaybackScroller()
static ProjectWindow & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
constexpr auto Command
Definition: MenuRegistry.h:456
void OnKaraoke(const CommandContext &context)
AttachedWindows::RegisteredFactory sLyricsWindowKey
Default message type for Publisher.
Definition: Observer.h:26