Audacity  3.0.3
ProjectSettings.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 ProjectSettings.cpp
6 
7 Paul Licameli split from AudacityProject.cpp
8 
9 **********************************************************************/
10 
11 #include "ProjectSettings.h"
12 
13 
14 
15 #include "AudioIOBase.h"
16 #include "Project.h"
19 
20 wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent);
21 
22 namespace {
24  {
25  wxCommandEvent e{ EVT_PROJECT_SETTINGS_CHANGE };
26  e.SetInt( static_cast<int>( code ) );
27  project.ProcessEvent( e );
28  }
29 }
30 
33  []( AudacityProject &project ){
34  auto result = std::make_shared< ProjectSettings >( project );
35  return result;
36  }
37 };
38 
40 {
41  return project.AttachedObjects::Get< ProjectSettings >(
43 }
44 
46 {
47  return Get( const_cast< AudacityProject & >( project ) );
48 }
49 
51  : mProject{ project }
52  , mSelectionFormat{ NumericTextCtrl::LookupFormat(
54  gPrefs->Read(wxT("/SelectionFormat"), wxT("")))
55 }
56 , mAudioTimeFormat{ NumericTextCtrl::LookupFormat(
58  gPrefs->Read(wxT("/AudioTimeFormat"), wxT("hh:mm:ss")))
59 }
60 , mFrequencySelectionFormatName{ NumericTextCtrl::LookupFormat(
62  gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT("")) )
63 }
64 , mBandwidthSelectionFormatName{ NumericTextCtrl::LookupFormat(
66  gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) )
67 }
68 , mSnapTo( gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) )
69 {
70  if (!gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate,
72  // The default given above can vary with host/devices. So unless there is
73  // an entry for the default sample rate in audacity.cfg, Audacity can open
74  // with a rate which is different from the rate with which it closed.
75  // See bug 1879.
76  gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mRate);
77  gPrefs->Flush();
78  }
79  gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mIsSyncLocked, false);
80 
81  bool multiToolActive = false;
82  gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
83 
84  if (multiToolActive)
85  mCurrentTool = ToolCodes::multiTool;
86  else
87  mCurrentTool = ToolCodes::selectTool;
88 
89  UpdatePrefs();
90 }
91 
93 {
94  gPrefs->Read(wxT("/AudioFiles/ShowId3Dialog"), &mShowId3Dialog, true);
95  gPrefs->Read(wxT("/GUI/EmptyCanBeDirty"), &mEmptyCanBeDirty, true);
96  gPrefs->Read(wxT("/GUI/ShowSplashScreen"), &mShowSplashScreen, true);
98  // Update the old default to the NEW default.
99  if (mSoloPref == wxT("Standard"))
100  mSoloPref = wxT("Simple");
101  gPrefs->Read(wxT("/GUI/TracksFitVerticallyZoomed"),
103  // gPrefs->Read(wxT("/GUI/UpdateSpectrogram"),
104  // &mViewInfo.bUpdateSpectrogram, true);
105 
106  // This code to change an empty projects rate is currently disabled, after
107  // discussion. The rule 'Default sample rate' only affects newly created
108  // projects was felt to be simpler and better.
109 #if 0
110  // The DefaultProjectSample rate is the rate for new projects.
111  // Do not change this project's rate, unless there are no tracks.
112  if( TrackList::Get( *this ).size() == 0){
113  gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate,
115  // If necessary, we change this rate in the selection toolbar too.
116  auto bar = SelectionBar::Get( *this );
117  bar.SetRate( mRate );
118  }
119 #endif
120 }
121 
122 const NumericFormatSymbol &
124 {
126 }
127 
129  const NumericFormatSymbol & formatName)
130 {
131  mFrequencySelectionFormatName = formatName;
132 }
133 
134 const NumericFormatSymbol &
136 {
138 }
139 
141  const NumericFormatSymbol & formatName)
142 {
143  mBandwidthSelectionFormatName = formatName;
144 }
145 
147 {
149 }
150 
152 {
153  return mSelectionFormat;
154 }
155 
157 {
159 }
160 
162 {
163  return mAudioTimeFormat;
164 }
165 
167 {
168  return mRate;
169 }
170 
171 void ProjectSettings::SetRate(double rate)
172 {
173  auto &project = mProject;
174  if (rate != mRate) {
175  mRate = rate;
176  Notify( project, ChangedProjectRate );
177  }
178 }
179 
181 {
182  mSnapTo = snap;
183 }
184 
186 {
187  return mSnapTo;
188 }
189 
191 {
192 #ifdef EXPERIMENTAL_SYNC_LOCK
193  return mIsSyncLocked;
194 #else
195  return false;
196 #endif
197 }
198 
200 {
201  auto &project = mProject;
202  if (flag != mIsSyncLocked) {
204  Notify( project, ChangedSyncLock );
205  }
206 }
207 
SelectionBar::Get
static SelectionBar & Get(AudacityProject &project)
Definition: SelectionBar.cpp:137
ProjectSettings::mProject
AudacityProject & mProject
Definition: ProjectSettings.h:124
AudioIOBase.h
ProjectSettings::GetSnapTo
int GetSnapTo() const
Definition: ProjectSettings.cpp:185
ProjectSettings::SetRate
void SetRate(double rate)
Definition: ProjectSettings.cpp:171
TracksBehaviorsSolo
ChoiceSetting TracksBehaviorsSolo
Definition: TracksBehaviorsPrefs.cpp:64
ProjectSettings::mFrequencySelectionFormatName
NumericFormatSymbol mFrequencySelectionFormatName
Definition: ProjectSettings.h:127
ProjectSettings::mShowId3Dialog
bool mShowId3Dialog
Definition: ProjectSettings.h:144
ToolCodes::selectTool
@ selectTool
Definition: ProjectSettings.h:35
flag
static std::once_flag flag
Definition: WaveformView.cpp:1113
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:67
TrackInfo::UpdatePrefs
void UpdatePrefs(wxWindow *pParent)
Project.h
ProjectSettings::SetSyncLock
void SetSyncLock(bool flag)
Definition: ProjectSettings.cpp:199
sProjectSettingsKey
static const AudacityProject::AttachedObjects::RegisteredFactory sProjectSettingsKey
Definition: ProjectSettings.cpp:32
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:39
ProjectSettings::mAudioTimeFormat
NumericFormatSymbol mAudioTimeFormat
Definition: ProjectSettings.h:129
ProjectSettings::mSelectionFormat
NumericFormatSymbol mSelectionFormat
Definition: ProjectSettings.h:126
SNAP_OFF
@ SNAP_OFF
Definition: ProjectSettings.h:28
ProjectSettings.h
TracksBehaviorsPrefs.h
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
ProjectSettings::UpdatePrefs
void UpdatePrefs() override
Definition: ProjectSettings.cpp:92
NumericConverter::BANDWIDTH
@ BANDWIDTH
Definition: NumericTextCtrl.h:54
ProjectSettings::ProjectSettings
ProjectSettings(AudacityProject &project)
Definition: ProjectSettings.cpp:50
ProjectSettings::mBandwidthSelectionFormatName
NumericFormatSymbol mBandwidthSelectionFormatName
Definition: ProjectSettings.h:128
ProjectSettings::EventCode
EventCode
Definition: ProjectSettings.h:59
anonymous_namespace{ProjectSettings.cpp}::Notify
void Notify(AudacityProject &project, ProjectSettings::EventCode code)
Definition: ProjectSettings.cpp:23
ProjectSettings::IsSyncLocked
bool IsSyncLocked() const
Definition: ProjectSettings.cpp:190
ProjectSettings::ChangedSyncLock
@ ChangedSyncLock
Definition: ProjectSettings.h:60
NumericConverter::LookupFormat
static NumericFormatSymbol LookupFormat(Type type, const wxString &id)
Definition: NumericTextCtrl.cpp:702
wxDEFINE_EVENT
wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent)
ProjectSettings::mSnapTo
int mSnapTo
Definition: ProjectSettings.h:139
ToolCodes::multiTool
@ multiTool
Definition: ProjectSettings.h:40
ProjectSettings::mShowSplashScreen
bool mShowSplashScreen
Definition: ProjectSettings.h:147
AudioIOBase::GetOptimalSupportedSampleRate
static int GetOptimalSupportedSampleRate()
Get a supported sample rate which can be used a an optimal default.
Definition: AudioIOBase.cpp:693
ProjectSettings::GetBandwidthSelectionFormatName
const NumericFormatSymbol & GetBandwidthSelectionFormatName() const
Definition: ProjectSettings.cpp:135
ProjectSettings::GetFrequencySelectionFormatName
const NumericFormatSymbol & GetFrequencySelectionFormatName() const
Definition: ProjectSettings.cpp:123
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:51
format
int format
Definition: ExportPCM.cpp:54
ProjectSettings::GetSelectionFormat
const NumericFormatSymbol & GetSelectionFormat() const
Definition: ProjectSettings.cpp:151
NumericConverter::FREQUENCY
@ FREQUENCY
Definition: NumericTextCtrl.h:53
ProjectSettings::SetSelectionFormat
void SetSelectionFormat(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:146
ChoiceSetting::Read
wxString Read() const
Definition: Prefs.cpp:235
TrackList::size
size_t size() const
Definition: Track.cpp:988
ProjectSettings::SetFrequencySelectionFormatName
void SetFrequencySelectionFormatName(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:128
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:151
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:495
ProjectSettings::mRate
double mRate
Definition: ProjectSettings.h:133
ProjectSettings::mSoloPref
wxString mSoloPref
Definition: ProjectSettings.h:131
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
ProjectSettings::GetAudioTimeFormat
const NumericFormatSymbol & GetAudioTimeFormat() const
Definition: ProjectSettings.cpp:161
ProjectSettings::GetRate
double GetRate() const
Definition: ProjectSettings.cpp:166
ProjectSettings::SetAudioTimeFormat
void SetAudioTimeFormat(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:156
NumericTextCtrl.h
ProjectSettings::mTracksFitVerticallyZoomed
bool mTracksFitVerticallyZoomed
Definition: ProjectSettings.h:143
ProjectSettings::ChangedProjectRate
@ ChangedProjectRate
Definition: ProjectSettings.h:61
ProjectSettings::mEmptyCanBeDirty
bool mEmptyCanBeDirty
Definition: ProjectSettings.h:146
ProjectSettings::SetSnapTo
void SetSnapTo(int snap)
Definition: ProjectSettings.cpp:180
ProjectSettings::SetBandwidthSelectionFormatName
void SetBandwidthSelectionFormatName(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:140
ProjectSettings::mIsSyncLocked
bool mIsSyncLocked
Definition: ProjectSettings.h:145
ProjectSettings
Holds various per-project settings values, including the sample rate, and sends events to the project...
Definition: ProjectSettings.h:53