Use an event so that ProjectSettings.cpp does not need TrackPanel.h
This commit is contained in:
parent
05efeeb5bd
commit
6dc5162614
|
@ -13,9 +13,19 @@ Paul Licameli split from AudacityProject.cpp
|
|||
#include "AudioIO.h"
|
||||
#include "Project.h"
|
||||
#include "Snap.h"
|
||||
#include "TrackPanel.h"
|
||||
#include "prefs/QualityPrefs.h"
|
||||
|
||||
wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent);
|
||||
|
||||
namespace {
|
||||
void Notify( AudacityProject &project, ProjectSettings::EventCode code )
|
||||
{
|
||||
wxCommandEvent e{ EVT_PROJECT_SETTINGS_CHANGE };
|
||||
e.SetInt( static_cast<int>( code ) );
|
||||
project.GetEventHandler()->ProcessEvent( e );
|
||||
}
|
||||
}
|
||||
|
||||
static const AudacityProject::AttachedObjects::RegisteredFactory
|
||||
sProjectSettingsKey{
|
||||
[]( AudacityProject &project ){
|
||||
|
@ -157,7 +167,7 @@ void ProjectSettings::SetSyncLock(bool flag)
|
|||
auto &project = mProject;
|
||||
if (flag != mIsSyncLocked) {
|
||||
mIsSyncLocked = flag;
|
||||
TrackPanel::Get( project ).Refresh(false);
|
||||
Notify( project, ChangedSyncLock );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,17 @@ Paul Licameli split from AudacityProject.h
|
|||
#ifndef __AUDACITY_PROJECT_SETTINGS__
|
||||
#define __AUDACITY_PROJECT_SETTINGS__
|
||||
|
||||
#include <wx/event.h> // to declare custom event type
|
||||
|
||||
#include "ClientData.h" // to inherit
|
||||
#include "Prefs.h" // to inherit
|
||||
|
||||
class AudacityProject;
|
||||
|
||||
// Sent to the project when certain settings change
|
||||
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
|
||||
EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent);
|
||||
|
||||
///\brief Holds various per-project settings values, including the sample rate,
|
||||
/// and sends events to the project when certain values change
|
||||
class ProjectSettings final
|
||||
|
@ -26,6 +32,11 @@ public:
|
|||
static ProjectSettings &Get( AudacityProject &project );
|
||||
static const ProjectSettings &Get( const AudacityProject &project );
|
||||
|
||||
// Values retrievable from GetInt() of the event for settings change
|
||||
enum EventCode : int {
|
||||
ChangedSyncLock,
|
||||
};
|
||||
|
||||
ProjectSettings( AudacityProject &project );
|
||||
|
||||
sampleFormat GetDefaultFormat() const { return mDefaultFormat; }
|
||||
|
|
|
@ -70,6 +70,7 @@ is time to refresh some aspect of the screen.
|
|||
#include "AdornedRulerPanel.h"
|
||||
#include "KeyboardCapture.h"
|
||||
#include "Project.h"
|
||||
#include "ProjectSettings.h"
|
||||
#include "TrackPanelMouseEvent.h"
|
||||
#include "TrackPanelResizeHandle.h"
|
||||
//#define DEBUG_DRAW_TIMING 1
|
||||
|
@ -316,8 +317,11 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
|
|||
&TrackPanel::OnPlayback,
|
||||
this);
|
||||
|
||||
GetProject()->Bind(EVT_ODTASK_UPDATE, &TrackPanel::OnODTask, this);
|
||||
GetProject()->Bind(EVT_ODTASK_COMPLETE, &TrackPanel::OnODTask, this);
|
||||
auto theProject = GetProject();
|
||||
theProject->Bind(EVT_ODTASK_UPDATE, &TrackPanel::OnODTask, this);
|
||||
theProject->Bind(EVT_ODTASK_COMPLETE, &TrackPanel::OnODTask, this);
|
||||
theProject->Bind(
|
||||
EVT_PROJECT_SETTINGS_CHANGE, &TrackPanel::OnProjectSettingsChange, this);
|
||||
|
||||
UpdatePrefs();
|
||||
}
|
||||
|
@ -530,6 +534,18 @@ void TrackPanel::OnODTask(wxCommandEvent & WXUNUSED(event))
|
|||
Refresh(false);
|
||||
}
|
||||
|
||||
void TrackPanel::OnProjectSettingsChange( wxCommandEvent &event )
|
||||
{
|
||||
event.Skip();
|
||||
switch ( static_cast<ProjectSettings::EventCode>( event.GetInt() ) ) {
|
||||
case ProjectSettings::ChangedSyncLock:
|
||||
Refresh(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double TrackPanel::GetScreenEndTime() const
|
||||
{
|
||||
int width;
|
||||
|
|
|
@ -289,6 +289,7 @@ class AUDACITY_DLL_API TrackPanel final
|
|||
void OnIdle(wxIdleEvent & event);
|
||||
void OnTimer(wxTimerEvent& event);
|
||||
void OnODTask(wxCommandEvent &event);
|
||||
void OnProjectSettingsChange(wxCommandEvent &event);
|
||||
|
||||
int GetLeftOffset() const { return GetLabelWidth() + 1;}
|
||||
|
||||
|
|
Loading…
Reference in New Issue