Audacity 3.2.0
ProjectSettings.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ProjectSettings.cpp
6
7Paul 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
23wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent);
24
25namespace {
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(
59 NumericConverter::TIME,
60 gPrefs->Read(wxT("/SelectionFormat"), wxT("")))
61}
62, mFrequencySelectionFormatName{ NumericTextCtrl::LookupFormat(
63 NumericConverter::FREQUENCY,
64 gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT("")) )
65}
66, mBandwidthSelectionFormatName{ NumericTextCtrl::LookupFormat(
67 NumericConverter::BANDWIDTH,
68 gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) )
69}
70, mAudioTimeFormat{ NumericTextCtrl::LookupFormat(
71 NumericConverter::TIME,
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)
84 else
86
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
121{
123}
124
126 const NumericFormatSymbol & formatName)
127{
129}
130
133{
135}
136
138 const NumericFormatSymbol & formatName)
139{
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
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} };
wxT("CloseDown"))
int format
Definition: ExportPCM.cpp:56
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
FileConfig * gPrefs
Definition: Prefs.cpp:71
static const AudacityProject::AttachedObjects::RegisteredFactory sProjectSettingsKey
static ProjectFileIORegistry::AttributeWriterEntry entry
wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent)
static ProjectFileIORegistry::AttributeReaderEntries entries
@ SNAP_OFF
static Settings & settings()
Definition: TrackInfo.cpp:87
ChoiceSetting TracksBehaviorsSolo
static std::once_flag flag
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
wxString Read() const
Definition: Prefs.cpp:354
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
static NumericFormatSymbol LookupFormat(Type type, const wxString &id)
Holds various per-project settings values, and sends events to the project when certain values change...
void SetTool(int tool)
static ProjectSettings & Get(AudacityProject &project)
ProjectSettings(AudacityProject &project)
NumericFormatSymbol mBandwidthSelectionFormatName
int GetSnapTo() const
const NumericFormatSymbol & GetBandwidthSelectionFormatName() const
bool mTracksFitVerticallyZoomed
void SetSyncLock(bool flag)
const NumericFormatSymbol & GetFrequencySelectionFormatName() const
AudacityProject & mProject
bool IsSyncLocked() const
const NumericFormatSymbol & GetSelectionFormat() const
void SetSelectionFormat(const NumericFormatSymbol &format)
NumericFormatSymbol mAudioTimeFormat
NumericFormatSymbol mSelectionFormat
void UpdatePrefs() override
void SetBandwidthSelectionFormatName(const NumericFormatSymbol &format)
void SetAudioTimeFormat(const NumericFormatSymbol &format)
void SetSnapTo(int snap)
const NumericFormatSymbol & GetAudioTimeFormat() const
void SetFrequencySelectionFormatName(const NumericFormatSymbol &format)
NumericFormatSymbol mFrequencySelectionFormatName
static SelectionBar & Get(AudacityProject &project)
size_t size() const
Definition: Track.cpp:1014
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
void Notify(AudacityProject &project, ProjectSettings::EventCode code, long previousValue)
Typically statically constructed.