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 , mSnapTo( gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) )
59 , mCurrentBrushRadius ( 5 )
60{
61 bool multiToolActive = false;
62 gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
63
64 if (multiToolActive)
66 else
68
70}
71
73{
74 gPrefs->Read(wxT("/AudioFiles/ShowId3Dialog"), &mShowId3Dialog, true);
75 gPrefs->Read(wxT("/GUI/EmptyCanBeDirty"), &mEmptyCanBeDirty, true);
76 gPrefs->Read(wxT("/GUI/ShowSplashScreen"), &mShowSplashScreen, true);
78 // Update the old default to the NEW default.
79 if (mSoloPref == wxT("Standard"))
80 mSoloPref = wxT("Simple");
81 gPrefs->Read(wxT("/GUI/TracksFitVerticallyZoomed"),
83 // gPrefs->Read(wxT("/GUI/UpdateSpectrogram"),
84 // &mViewInfo.bUpdateSpectrogram, true);
85
86 // This code to change an empty projects rate is currently disabled, after
87 // discussion. The rule 'Default sample rate' only affects newly created
88 // projects was felt to be simpler and better.
89#if 0
90 // The DefaultProjectSample rate is the rate for new projects.
91 // Do not change this project's rate, unless there are no tracks.
92 if( TrackList::Get( *this ).size() == 0){
93 mRate = QualityDefaultSampleRate.Read();
94 // If necessary, we change this rate in the selection toolbar too.
95 auto bar = SelectionBar::Get( *this );
96 bar.SetRate( mRate );
97 }
98#endif
99}
100
102{
103 mSnapTo = snap;
104}
105
107{
108 return mSnapTo;
109}
110
112 if (auto oldValue = mCurrentTool; oldValue != tool) {
113 mCurrentTool = tool;
114 Notify( mProject, ChangedTool, oldValue );
115 }
116}
117
119[](const AudacityProject &project, XMLWriter &xmlFile){
120 auto &settings = ProjectSettings::Get(project);
121 xmlFile.WriteAttr(wxT("snapto"),
122 settings.GetSnapTo() ? wxT("on") : wxT("off"));
123}
124};
125
127// Just a pointer to function, but needing overload resolution as non-const:
129 // PRL: The following has persisted as a per-project setting for long.
130 // Maybe that should be abandoned. Enough to save changes in the user
131 // preference file.
132 { "snapto", [](auto &settings, auto value){
133 settings.SetSnapTo(value.ToWString() == wxT("on") ? true : false);
134 } },
135} };
wxT("CloseDown"))
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
FileConfig * gPrefs
Definition: Prefs.cpp:70
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
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
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
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)
int GetSnapTo() const
bool mTracksFitVerticallyZoomed
AudacityProject & mProject
void UpdatePrefs() override
void SetSnapTo(int snap)
static SelectionBar & Get(AudacityProject &project)
size_t size() const
Definition: Track.cpp:1015
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:487
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
void Notify(AudacityProject &project, ProjectSettings::EventCode code, long previousValue)
Typically statically constructed.