Audacity  3.2.0
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"
17 #include "QualitySettings.h"
20 #include "XMLWriter.h"
21 #include "XMLTagHandler.h"
22 
23 wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent);
24 
25 namespace {
26  void Notify(
28  long previousValue )
29  {
30  wxCommandEvent e{ EVT_PROJECT_SETTINGS_CHANGE };
31  e.SetInt( static_cast<int>( code ) );
32  e.SetExtraLong( previousValue );
33  project.ProcessEvent( e );
34  }
35 }
36 
39  []( AudacityProject &project ){
40  auto result = std::make_shared< ProjectSettings >( project );
41  return result;
42  }
43 };
44 
46 {
47  return project.AttachedObjects::Get< ProjectSettings >(
49 }
50 
52 {
53  return Get( const_cast< AudacityProject & >( project ) );
54 }
55 
57  : mProject{ project }
58  , mSelectionFormat{ NumericTextCtrl::LookupFormat(
60  gPrefs->Read(wxT("/SelectionFormat"), wxT("")))
61 }
62 , mFrequencySelectionFormatName{ NumericTextCtrl::LookupFormat(
64  gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT("")) )
65 }
66 , mBandwidthSelectionFormatName{ NumericTextCtrl::LookupFormat(
68  gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) )
69 }
70 , mAudioTimeFormat{ NumericTextCtrl::LookupFormat(
72  gPrefs->Read(wxT("/AudioTimeFormat"), wxT("hh:mm:ss")))
73 }
74 , mSnapTo( gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) )
75 , mCurrentBrushRadius ( 5 )
76 {
77  gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mIsSyncLocked, false);
78 
79  bool multiToolActive = false;
80  gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
81 
82  if (multiToolActive)
83  mCurrentTool = ToolCodes::multiTool;
84  else
85  mCurrentTool = ToolCodes::selectTool;
86 
87  UpdatePrefs();
88 }
89 
91 {
92  gPrefs->Read(wxT("/AudioFiles/ShowId3Dialog"), &mShowId3Dialog, true);
93  gPrefs->Read(wxT("/GUI/EmptyCanBeDirty"), &mEmptyCanBeDirty, true);
94  gPrefs->Read(wxT("/GUI/ShowSplashScreen"), &mShowSplashScreen, true);
96  // Update the old default to the NEW default.
97  if (mSoloPref == wxT("Standard"))
98  mSoloPref = wxT("Simple");
99  gPrefs->Read(wxT("/GUI/TracksFitVerticallyZoomed"),
101  // gPrefs->Read(wxT("/GUI/UpdateSpectrogram"),
102  // &mViewInfo.bUpdateSpectrogram, true);
103 
104  // This code to change an empty projects rate is currently disabled, after
105  // discussion. The rule 'Default sample rate' only affects newly created
106  // projects was felt to be simpler and better.
107 #if 0
108  // The DefaultProjectSample rate is the rate for new projects.
109  // Do not change this project's rate, unless there are no tracks.
110  if( TrackList::Get( *this ).size() == 0){
111  mRate = QualityDefaultSampleRate.Read();
112  // If necessary, we change this rate in the selection toolbar too.
113  auto bar = SelectionBar::Get( *this );
114  bar.SetRate( mRate );
115  }
116 #endif
117 }
118 
119 const NumericFormatSymbol &
121 {
123 }
124 
126  const NumericFormatSymbol & formatName)
127 {
128  mFrequencySelectionFormatName = formatName;
129 }
130 
131 const NumericFormatSymbol &
133 {
135 }
136 
138  const NumericFormatSymbol & formatName)
139 {
140  mBandwidthSelectionFormatName = formatName;
141 }
142 
144 {
146 }
147 
149 {
150  return mSelectionFormat;
151 }
152 
154 {
156 }
157 
159 {
160  return mAudioTimeFormat;
161 }
162 
164 {
165  mSnapTo = snap;
166 }
167 
169 {
170  return mSnapTo;
171 }
172 
173 void ProjectSettings::SetTool(int tool) {
174  if (auto oldValue = mCurrentTool; oldValue != tool) {
175  mCurrentTool = tool;
176  Notify( mProject, ChangedTool, oldValue );
177  }
178 }
179 
181 {
182 #ifdef EXPERIMENTAL_SYNC_LOCK
183  return mIsSyncLocked;
184 #else
185  return false;
186 #endif
187 }
188 
190 {
191  auto &project = mProject;
192  if (auto oldValue = mIsSyncLocked; flag != oldValue) {
194  Notify( project, ChangedSyncLock, oldValue );
195  }
196 }
197 
199 [](const AudacityProject &project, XMLWriter &xmlFile){
200  auto &settings = ProjectSettings::Get(project);
201  xmlFile.WriteAttr(wxT("snapto"), settings.GetSnapTo() ? wxT("on") : wxT("off"));
202  xmlFile.WriteAttr(wxT("selectionformat"),
203  settings.GetSelectionFormat().Internal());
204  xmlFile.WriteAttr(wxT("frequencyformat"),
205  settings.GetFrequencySelectionFormatName().Internal());
206  xmlFile.WriteAttr(wxT("bandwidthformat"),
207  settings.GetBandwidthSelectionFormatName().Internal());
208 }
209 };
210 
212 // Just a pointer to function, but needing overload resolution as non-const:
214  // PRL: The following have persisted as per-project settings for long.
215  // Maybe that should be abandoned. Enough to save changes in the user
216  // preference file.
217  { "snapto", [](auto &settings, auto value){
218  settings.SetSnapTo(value.ToWString() == wxT("on") ? true : false);
219  } },
220  { "selectionformat", [](auto &settings, auto value){
221  settings.SetSelectionFormat(NumericConverter::LookupFormat(
222  NumericConverter::TIME, value.ToWString()));
223  } },
224  { "frequencyformat", [](auto &settings, auto value){
225  settings.SetFrequencySelectionFormatName(
227  NumericConverter::FREQUENCY, value.ToWString()));
228  } },
229  { "bandwidthformat", [](auto &settings, auto value){
230  settings.SetBandwidthSelectionFormatName(
232  NumericConverter::BANDWIDTH, value.ToWString()));
233  } },
234 } };
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
SelectionBar::Get
static SelectionBar & Get(AudacityProject &project)
Definition: SelectionBar.cpp:138
ProjectSettings::mProject
AudacityProject & mProject
Definition: ProjectSettings.h:130
AudioIOBase.h
ProjectSettings::GetSnapTo
int GetSnapTo() const
Definition: ProjectSettings.cpp:168
TracksBehaviorsSolo
ChoiceSetting TracksBehaviorsSolo
Definition: TracksBehaviorsPrefs.cpp:59
SNAP_OFF
@ SNAP_OFF
Definition: ProjectSettings.h:31
ProjectSettings::mFrequencySelectionFormatName
NumericFormatSymbol mFrequencySelectionFormatName
Definition: ProjectSettings.h:133
XMLWriter.h
ProjectSettings::mShowId3Dialog
bool mShowId3Dialog
Definition: ProjectSettings.h:148
ToolCodes::selectTool
@ selectTool
Definition: ProjectSettings.h:40
entries
static ProjectFileIORegistry::AttributeReaderEntries entries
Definition: ProjectSettings.cpp:211
flag
static std::once_flag flag
Definition: WaveformView.cpp:1133
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:71
Project.h
ProjectSettings::SetSyncLock
void SetSyncLock(bool flag)
Definition: ProjectSettings.cpp:189
entry
static ProjectFileIORegistry::AttributeWriterEntry entry
Definition: ProjectSettings.cpp:198
ProjectSettings::mCurrentTool
int mCurrentTool
Definition: ProjectSettings.h:141
sProjectSettingsKey
static const AudacityProject::AttachedObjects::RegisteredFactory sProjectSettingsKey
Definition: ProjectSettings.cpp:38
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:45
ProjectSettings::mAudioTimeFormat
NumericFormatSymbol mAudioTimeFormat
Definition: ProjectSettings.h:135
ProjectSettings::mSelectionFormat
NumericFormatSymbol mSelectionFormat
Definition: ProjectSettings.h:132
TrackInfo::UpdatePrefs
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
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: ComponentInterfaceSymbol.h:27
ProjectSettings::UpdatePrefs
void UpdatePrefs() override
Definition: ProjectSettings.cpp:90
NumericConverter::BANDWIDTH
@ BANDWIDTH
Definition: NumericTextCtrl.h:55
ProjectSettings::ProjectSettings
ProjectSettings(AudacityProject &project)
Definition: ProjectSettings.cpp:56
ProjectSettings::SetTool
void SetTool(int tool)
Definition: ProjectSettings.cpp:173
ProjectSettings::mBandwidthSelectionFormatName
NumericFormatSymbol mBandwidthSelectionFormatName
Definition: ProjectSettings.h:134
ProjectSettings::EventCode
EventCode
Definition: ProjectSettings.h:66
ProjectSettings::IsSyncLocked
bool IsSyncLocked() const
Definition: ProjectSettings.cpp:180
ProjectSettings::ChangedSyncLock
@ ChangedSyncLock
Definition: ProjectSettings.h:67
NumericConverter::LookupFormat
static NumericFormatSymbol LookupFormat(Type type, const wxString &id)
Definition: NumericTextCtrl.cpp:704
wxDEFINE_EVENT
wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent)
ProjectSettings::mSnapTo
int mSnapTo
Definition: ProjectSettings.h:139
XMLTagHandler.h
ToolCodes::multiTool
@ multiTool
Definition: ProjectSettings.h:44
ProjectSettings::mShowSplashScreen
bool mShowSplashScreen
Definition: ProjectSettings.h:151
ProjectSettings::GetBandwidthSelectionFormatName
const NumericFormatSymbol & GetBandwidthSelectionFormatName() const
Definition: ProjectSettings.cpp:132
ProjectSettings::GetFrequencySelectionFormatName
const NumericFormatSymbol & GetFrequencySelectionFormatName() const
Definition: ProjectSettings.cpp:120
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:52
format
int format
Definition: ExportPCM.cpp:56
XMLMethodRegistry::AttributeWriterEntry
Typically statically constructed.
Definition: XMLMethodRegistry.h:158
ProjectSettings::GetSelectionFormat
const NumericFormatSymbol & GetSelectionFormat() const
Definition: ProjectSettings.cpp:148
anonymous_namespace{ProjectSettings.cpp}::Notify
void Notify(AudacityProject &project, ProjectSettings::EventCode code, long previousValue)
Definition: ProjectSettings.cpp:26
NumericConverter::FREQUENCY
@ FREQUENCY
Definition: NumericTextCtrl.h:54
ProjectSettings::SetSelectionFormat
void SetSelectionFormat(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:143
ChoiceSetting::Read
wxString Read() const
Definition: Prefs.cpp:277
TrackList::size
size_t size() const
Definition: Track.cpp:859
ProjectSettings::SetFrequencySelectionFormatName
void SetFrequencySelectionFormatName(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:125
ProjectSettings::ChangedTool
@ ChangedTool
Definition: ProjectSettings.h:68
QualitySettings.h
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:377
ProjectSettings::mSoloPref
wxString mSoloPref
Definition: ProjectSettings.h:137
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
ProjectSettings::GetAudioTimeFormat
const NumericFormatSymbol & GetAudioTimeFormat() const
Definition: ProjectSettings.cpp:158
ProjectSettings::SetAudioTimeFormat
void SetAudioTimeFormat(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:153
NumericTextCtrl.h
ProjectSettings::mTracksFitVerticallyZoomed
bool mTracksFitVerticallyZoomed
Definition: ProjectSettings.h:147
ProjectSettings::mEmptyCanBeDirty
bool mEmptyCanBeDirty
Definition: ProjectSettings.h:150
ProjectSettings::SetSnapTo
void SetSnapTo(int snap)
Definition: ProjectSettings.cpp:163
settings
static Settings & settings()
Definition: TrackInfo.cpp:87
XMLMethodRegistry::AttributeReaderEntries
Definition: XMLMethodRegistry.h:124
ProjectSettings::SetBandwidthSelectionFormatName
void SetBandwidthSelectionFormatName(const NumericFormatSymbol &format)
Definition: ProjectSettings.cpp:137
ProjectSettings::mIsSyncLocked
bool mIsSyncLocked
Definition: ProjectSettings.h:149
ProjectSettings
Holds various per-project settings values, and sends events to the project when certain values change...
Definition: ProjectSettings.h:60