1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 00:29:41 +02:00

Redo TP_UpdateStatusMessage...

... Rename it as SetStatus; make it part of AudacityProject not
TrackPanelListener; and use a roundabout event signalling to cause the timer
restart.

Because SetStatus will be one of very few things left in AudacityProject, but
the timer handling will be part of another class decoupled from it.

And TrackPanelListener won't really be needed: TrackPanel will not need to
pretend it doesn't know what an AudacityProject is.
This commit is contained in:
Paul Licameli 2019-05-27 22:27:00 -04:00
parent ae18f2f220
commit 02afcbca8c
10 changed files with 47 additions and 27 deletions

View File

@ -2226,7 +2226,7 @@ void AdornedRulerPanel::ProcessUIHandleResult
void AdornedRulerPanel::UpdateStatusMessage( const wxString &message )
{
GetProject()->TP_DisplayStatusMessage(message);
GetProject()->SetStatus(message);
}
void AdornedRulerPanel::CreateOverlays()

View File

@ -4605,7 +4605,7 @@ void AudioIO::AILAProcess(double maxPeak) {
//we can't improve it more now
if (mAILATotalAnalysis != 0) {
mAILAActive = false;
proj->TP_DisplayStatusMessage(_("Automated Recording Level Adjustment stopped. It was not possible to optimize it more. Still too high."));
proj->SetStatus(_("Automated Recording Level Adjustment stopped. It was not possible to optimize it more. Still too high."));
}
wxPrintf("\talready min vol:%f\n", iv);
}
@ -4614,7 +4614,7 @@ void AudioIO::AILAProcess(double maxPeak) {
Px_SetInputVolume(mPortMixer, vol);
wxString msg;
msg.Printf(_("Automated Recording Level Adjustment decreased the volume to %f."), vol);
proj->TP_DisplayStatusMessage(msg);
proj->SetStatus(msg);
changetype = 1;
wxPrintf("\tnew vol:%f\n", vol);
float check = Px_GetInputVolume(mPortMixer);
@ -4628,7 +4628,7 @@ void AudioIO::AILAProcess(double maxPeak) {
//we can't improve it more
if (mAILATotalAnalysis != 0) {
mAILAActive = false;
proj->TP_DisplayStatusMessage(_("Automated Recording Level Adjustment stopped. It was not possible to optimize it more. Still too low."));
proj->SetStatus(_("Automated Recording Level Adjustment stopped. It was not possible to optimize it more. Still too low."));
}
wxPrintf("\talready max vol:%f\n", iv);
}
@ -4641,7 +4641,7 @@ void AudioIO::AILAProcess(double maxPeak) {
Px_SetInputVolume(mPortMixer, vol);
wxString msg;
msg.Printf(_("Automated Recording Level Adjustment increased the volume to %.2f."), vol);
proj->TP_DisplayStatusMessage(msg);
proj->SetStatus(msg);
changetype = 2;
wxPrintf("\tnew vol:%f\n", vol);
float check = Px_GetInputVolume(mPortMixer);
@ -4674,13 +4674,13 @@ void AudioIO::AILAProcess(double maxPeak) {
if (mAILAActive && mAILATotalAnalysis != 0 && mAILAAnalysisCounter >= mAILATotalAnalysis) {
mAILAActive = false;
if (mAILAMax > mAILAGoalPoint + mAILAGoalDelta)
proj->TP_DisplayStatusMessage(_("Automated Recording Level Adjustment stopped. The total number of analyses has been exceeded without finding an acceptable volume. Still too high."));
proj->SetStatus(_("Automated Recording Level Adjustment stopped. The total number of analyses has been exceeded without finding an acceptable volume. Still too high."));
else if (mAILAMax < mAILAGoalPoint - mAILAGoalDelta)
proj->TP_DisplayStatusMessage(_("Automated Recording Level Adjustment stopped. The total number of analyses has been exceeded without finding an acceptable volume. Still too low."));
proj->SetStatus(_("Automated Recording Level Adjustment stopped. The total number of analyses has been exceeded without finding an acceptable volume. Still too low."));
else {
wxString msg;
msg.Printf(_("Automated Recording Level Adjustment stopped. %.2f seems an acceptable volume."), Px_GetInputVolume(mPortMixer));
proj->TP_DisplayStatusMessage(msg);
proj->SetStatus(msg);
}
}
}

View File

@ -168,6 +168,8 @@ scroll information. It also has some status flags.
#include "widgets/WindowAccessible.h"
#endif
wxDEFINE_EVENT(EVT_PROJECT_STATUS_UPDATE, wxCommandEvent);
bool AllProjects::sbClosing = false;
bool AllProjects::sbWindowRectAlreadySaved = false;
@ -1323,6 +1325,9 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
wxTheApp->Bind(EVT_THEME_CHANGE, &AudacityProject::OnThemeChange, this);
project.Bind(EVT_PROJECT_STATUS_UPDATE,
&AudacityProject::OnStatusChange, this);
#ifdef EXPERIMENTAL_DA2
ClearBackground();// For wxGTK.
#endif
@ -4905,20 +4910,29 @@ void AudacityProject::OnTimer(wxTimerEvent& WXUNUSED(event))
}
// TrackPanel callback method
void AudacityProject::TP_DisplayStatusMessage(const wxString &msg)
void AudacityProject::SetStatus(const wxString &msg)
{
auto &window = *this;
auto &project = *this;
if ( msg != mLastMainStatusMessage ) {
mLastMainStatusMessage = msg;
window.GetStatusBar()->SetStatusText(msg, mainStatusBarField);
// When recording, let the NEW status message stay at least as long as
// the timer interval (if it is not replaced again by this function),
// before replacing it with the message about remaining disk capacity.
RestartTimer();
wxCommandEvent evt{ EVT_PROJECT_STATUS_UPDATE };
project.GetEventHandler()->ProcessEvent( evt );
}
}
void AudacityProject::OnStatusChange( wxCommandEvent & )
{
auto &project = *this;
auto &window = project;
const auto &msg = project.GetStatus();
window.GetStatusBar()->SetStatusText(msg, mainStatusBarField);
// When recording, let the NEW status message stay at least as long as
// the timer interval (if it is not replaced again by this function),
// before replacing it with the message about remaining disk capacity.
RestartTimer();
}
void AudacityProject::TP_DisplaySelection()
{
auto &project = *this;

View File

@ -41,6 +41,9 @@
const int AudacityProjectTimerID = 5200;
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
EVT_PROJECT_STATUS_UPDATE, wxCommandEvent);
class wxMemoryDC;
class wxArrayString;
class wxWindow;
@ -394,7 +397,6 @@ public:
// TrackPanel callback methods, overrides of TrackPanelListener
void TP_DisplaySelection() override;
void TP_DisplayStatusMessage(const wxString &msg) override;
void TP_RedrawScrollbars() override;
void TP_ScrollLeft() override;
@ -408,6 +410,11 @@ public:
MeterPanel *GetCaptureMeter();
void SetCaptureMeter(MeterPanel *capture);
const wxString &GetStatus() const { return mLastMainStatusMessage; }
void SetStatus(const wxString &msg);
void OnStatusChange( wxCommandEvent& );
private:
bool SnapSelection();

View File

@ -707,7 +707,7 @@ void TrackPanel::UpdateStatusMessage( const wxString &st )
if (HasEscape())
/* i18n-hint Esc is a key on the keyboard */
status += wxT(" "), status += _("(Esc to cancel)");
mListener->TP_DisplayStatusMessage(status);
GetProject()->SetStatus(status);
}
void TrackPanel::UpdateSelectionDisplay()
@ -765,7 +765,7 @@ void TrackPanel::UpdateViewIfNoTracks()
mListener->TP_RedrawScrollbars();
mListener->TP_HandleResize();
mListener->TP_DisplayStatusMessage(wxT("")); //STM: Clear message if all tracks are removed
GetProject()->SetStatus(wxT("")); //STM: Clear message if all tracks are removed
}
}

View File

@ -25,7 +25,6 @@ class AUDACITY_DLL_API TrackPanelListener /* not final */ {
virtual ~TrackPanelListener(){};
virtual void TP_DisplaySelection() = 0;
virtual void TP_DisplayStatusMessage(const wxString &msg) = 0;
virtual void TP_RedrawScrollbars() = 0;
virtual void TP_ScrollLeft() = 0;

View File

@ -1384,7 +1384,7 @@ void OnTrackClose(const CommandContext &context)
if (isAudioActive)
{
project.TP_DisplayStatusMessage(
project.SetStatus(
_("Can't delete track with active audio"));
wxBell();
return;

View File

@ -491,7 +491,7 @@ void AButton::OnMouseEvent(wxMouseEvent & event)
if (mCursorIsInWindow)
UpdateStatus();
else {
GetActiveProject()->TP_DisplayStatusMessage(wxT(""));
GetActiveProject()->SetStatus(wxT(""));
}
}
else
@ -508,7 +508,7 @@ void AButton::UpdateStatus()
wxString tipText = pTip->GetTip();
if (!mEnabled)
tipText += _(" (disabled)");
GetActiveProject()->TP_DisplayStatusMessage(tipText);
GetActiveProject()->SetStatus(tipText);
}
#endif
}

View File

@ -1091,7 +1091,7 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
{
// Display the tooltip in the status bar
wxString tip = GetTip(mCurrentValue);
GetActiveProject()->TP_DisplayStatusMessage(tip);
GetActiveProject()->SetStatus(tip);
Refresh();
}
else if (event.Leaving())
@ -1100,7 +1100,7 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
{
ShowTip(false);
}
GetActiveProject()->TP_DisplayStatusMessage(wxT(""));
GetActiveProject()->SetStatus(wxT(""));
Refresh();
}

View File

@ -755,14 +755,14 @@ void MeterPanel::OnMouse(wxMouseEvent &evt)
#if wxUSE_TOOLTIPS // Not available in wxX11
if (evt.Leaving()){
GetActiveProject()->TP_DisplayStatusMessage(wxT(""));
GetActiveProject()->SetStatus(wxT(""));
}
else if (evt.Entering()) {
// Display the tooltip in the status bar
wxToolTip * pTip = this->GetToolTip();
if( pTip ) {
wxString tipText = pTip->GetTip();
GetActiveProject()->TP_DisplayStatusMessage(tipText);
GetActiveProject()->SetStatus(tipText);
}
}
#endif