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