1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

All things with an UpdatePrefs() message listen for an event...

... Still to do, improve the handling of updates of only subsets of the prefs
This commit is contained in:
Paul Licameli
2018-02-17 17:42:14 -05:00
parent cc635e0498
commit 62899a32f4
37 changed files with 198 additions and 136 deletions

View File

@@ -253,9 +253,6 @@ bool MeterUpdateQueue::Get(MeterUpdateMsg &msg)
// How many pixels between items?
const static int gap = 2;
// Event used to notify all meters of preference changes
wxDEFINE_EVENT(EVT_METER_PREFERENCES_CHANGED, wxCommandEvent);
const static wxChar *PrefStyles[] =
{
wxT("AutomaticStereo"),
@@ -348,11 +345,6 @@ MeterPanel::MeterPanel(AudacityProject *project,
mPeakPeakPen = wxPen(theTheme.Colour( clrMeterPeak), 1, wxPENSTYLE_SOLID);
mDisabledPen = wxPen(theTheme.Colour( clrMeterDisabledPen), 1, wxPENSTYLE_SOLID);
// Register for our preference update event
wxTheApp->Bind(EVT_METER_PREFERENCES_CHANGED,
&MeterPanel::OnMeterPrefsUpdated,
this);
if (mIsInput) {
wxTheApp->Bind(EVT_AUDIOIO_MONITOR,
&MeterPanel::OnAudioIOStatus,
@@ -457,6 +449,20 @@ void MeterPanel::UpdatePrefs()
Reset(mRate, false);
mLayoutValid = false;
Refresh(false);
}
static int MeterPrefsID()
{
static int value = wxNewId();
return value;
}
void MeterPanel::UpdateSelectedPrefs(int id)
{
if (id == MeterPrefsID())
UpdatePrefs();
}
void MeterPanel::OnErase(wxEraseEvent & WXUNUSED(event))
@@ -1964,15 +1970,6 @@ void MeterPanel::OnMonitor(wxCommandEvent & WXUNUSED(event))
StartMonitoring();
}
void MeterPanel::OnMeterPrefsUpdated(wxCommandEvent & evt)
{
evt.Skip();
UpdatePrefs();
Refresh(false);
}
void MeterPanel::OnPreferences(wxCommandEvent & WXUNUSED(event))
{
wxTextCtrl *rate;
@@ -2099,9 +2096,8 @@ void MeterPanel::OnPreferences(wxCommandEvent & WXUNUSED(event))
// Currently, there are 2 playback meters and 2 record meters and any number of
// mixerboard meters, so we have to send out an preferences updated message to
// ensure they all update themselves.
wxCommandEvent e(EVT_METER_PREFERENCES_CHANGED);
e.SetEventObject(this);
GetParent()->GetEventHandler()->ProcessEvent(e);
wxTheApp->AddPendingEvent(wxCommandEvent{
EVT_PREFS_UPDATE, MeterPrefsID() });
}
}

View File

@@ -22,14 +22,11 @@
#include <wx/timer.h> // member variable
#include "../SampleFormat.h"
#include "../Prefs.h"
#include "Ruler.h" // member variable
class AudacityProject;
// Event used to notify all meters of preference changes
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
EVT_METER_PREFERENCES_CHANGED, wxCommandEvent);
// Increase this when we add support for multichannel meters
// (most of the code is already there)
const int kMaxMeterBars = 2;
@@ -94,7 +91,7 @@ class MeterAx;
\brief MeterPanel is a panel that paints the meter used for monitoring
or playback.
************************************************************************/
class MeterPanel final : public wxPanelWrapper
class MeterPanel final : public wxPanelWrapper, private PrefsListener
{
DECLARE_DYNAMIC_CLASS(MeterPanel)
@@ -124,7 +121,6 @@ class MeterPanel final : public wxPanelWrapper
void SetFocusFromKbd() override;
void UpdatePrefs();
void Clear();
Style GetStyle() const { return mStyle; }
@@ -192,6 +188,9 @@ class MeterPanel final : public wxPanelWrapper
int GetDBRange() const { return mDB ? mDBRange : -1; }
private:
void UpdatePrefs() override;
void UpdateSelectedPrefs( int ) override;
static bool s_AcceptsFocus;
struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
using TempAllowFocus = std::unique_ptr<bool, Resetter>;
@@ -232,7 +231,6 @@ class MeterPanel final : public wxPanelWrapper
void ShowMenu(const wxPoint & pos);
void OnMonitor(wxCommandEvent &evt);
void OnPreferences(wxCommandEvent &evt);
void OnMeterPrefsUpdated(wxCommandEvent &evt);
wxString Key(const wxString & key) const;