forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectSettings.cpp
209 lines (175 loc) · 5.58 KB
/
ProjectSettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**********************************************************************
Sneedacity: A Digital Audio Editor
ProjectSettings.cpp
Paul Licameli split from SneedacityProject.cpp
**********************************************************************/
#include "ProjectSettings.h"
#include "AudioIOBase.h"
#include "Project.h"
#include "prefs/QualitySettings.h"
#include "widgets/NumericTextCtrl.h"
#include "prefs/TracksBehaviorsPrefs.h"
wxDEFINE_EVENT(EVT_PROJECT_SETTINGS_CHANGE, wxCommandEvent);
namespace {
void Notify( SneedacityProject &project, ProjectSettings::EventCode code )
{
wxCommandEvent e{ EVT_PROJECT_SETTINGS_CHANGE };
e.SetInt( static_cast<int>( code ) );
project.ProcessEvent( e );
}
}
static const SneedacityProject::AttachedObjects::RegisteredFactory
sProjectSettingsKey{
[]( SneedacityProject &project ){
auto result = std::make_shared< ProjectSettings >( project );
return result;
}
};
ProjectSettings &ProjectSettings::Get( SneedacityProject &project )
{
return project.AttachedObjects::Get< ProjectSettings >(
sProjectSettingsKey );
}
const ProjectSettings &ProjectSettings::Get( const SneedacityProject &project )
{
return Get( const_cast< SneedacityProject & >( project ) );
}
ProjectSettings::ProjectSettings(SneedacityProject &project)
: mProject{ project }
, mSelectionFormat{ NumericTextCtrl::LookupFormat(
NumericConverter::TIME,
gPrefs->Read(wxT("/SelectionFormat"), wxT("")))
}
, mAudioTimeFormat{ NumericTextCtrl::LookupFormat(
NumericConverter::TIME,
gPrefs->Read(wxT("/AudioTimeFormat"), wxT("hh:mm:ss")))
}
, mFrequencySelectionFormatName{ NumericTextCtrl::LookupFormat(
NumericConverter::FREQUENCY,
gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT("")) )
}
, mBandwidthSelectionFormatName{ NumericTextCtrl::LookupFormat(
NumericConverter::BANDWIDTH,
gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) )
}
, mSnapTo( gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) )
{
int intRate = 0;
bool wasDefined = QualitySettings::DefaultSampleRate.Read( &intRate );
mRate = intRate;
if ( !wasDefined ) {
// The default given above can vary with host/devices. So unless there is
// an entry for the default sample rate in sneedacity.cfg, Sneedacity can open
// with a rate which is different from the rate with which it closed.
// See bug 1879.
QualitySettings::DefaultSampleRate.Write( mRate );
gPrefs->Flush();
}
gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mIsSyncLocked, false);
bool multiToolActive = false;
gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
if (multiToolActive)
mCurrentTool = ToolCodes::multiTool;
else
mCurrentTool = ToolCodes::selectTool;
UpdatePrefs();
}
void ProjectSettings::UpdatePrefs()
{
gPrefs->Read(wxT("/AudioFiles/ShowId3Dialog"), &mShowId3Dialog, true);
gPrefs->Read(wxT("/GUI/EmptyCanBeDirty"), &mEmptyCanBeDirty, true);
gPrefs->Read(wxT("/GUI/ShowSplashScreen"), &mShowSplashScreen, true);
mSoloPref = TracksBehaviorsSolo.Read();
// Update the old default to the NEW default.
if (mSoloPref == wxT("Standard"))
mSoloPref = wxT("Simple");
gPrefs->Read(wxT("/GUI/TracksFitVerticallyZoomed"),
&mTracksFitVerticallyZoomed, false);
// gPrefs->Read(wxT("/GUI/UpdateSpectrogram"),
// &mViewInfo.bUpdateSpectrogram, true);
// This code to change an empty projects rate is currently disabled, after
// discussion. The rule 'Default sample rate' only affects newly created
// projects was felt to be simpler and better.
#if 0
// The DefaultProjectSample rate is the rate for new projects.
// Do not change this project's rate, unless there are no tracks.
if( TrackList::Get( *this ).size() == 0){
mRate = QualityDefaultSampleRate.Read();
// If necessary, we change this rate in the selection toolbar too.
auto bar = SelectionBar::Get( *this );
bar.SetRate( mRate );
}
#endif
}
const NumericFormatSymbol &
ProjectSettings::GetFrequencySelectionFormatName() const
{
return mFrequencySelectionFormatName;
}
void ProjectSettings::SetFrequencySelectionFormatName(
const NumericFormatSymbol & formatName)
{
mFrequencySelectionFormatName = formatName;
}
const NumericFormatSymbol &
ProjectSettings::GetBandwidthSelectionFormatName() const
{
return mBandwidthSelectionFormatName;
}
void ProjectSettings::SetBandwidthSelectionFormatName(
const NumericFormatSymbol & formatName)
{
mBandwidthSelectionFormatName = formatName;
}
void ProjectSettings::SetSelectionFormat(const NumericFormatSymbol & format)
{
mSelectionFormat = format;
}
const NumericFormatSymbol & ProjectSettings::GetSelectionFormat() const
{
return mSelectionFormat;
}
void ProjectSettings::SetAudioTimeFormat(const NumericFormatSymbol & format)
{
mAudioTimeFormat = format;
}
const NumericFormatSymbol & ProjectSettings::GetAudioTimeFormat() const
{
return mAudioTimeFormat;
}
double ProjectSettings::GetRate() const
{
return mRate;
}
void ProjectSettings::SetRate(double rate)
{
auto &project = mProject;
if (rate != mRate) {
mRate = rate;
Notify( project, ChangedProjectRate );
}
}
void ProjectSettings::SetSnapTo(int snap)
{
mSnapTo = snap;
}
int ProjectSettings::GetSnapTo() const
{
return mSnapTo;
}
bool ProjectSettings::IsSyncLocked() const
{
#ifdef EXPERIMENTAL_SYNC_LOCK
return mIsSyncLocked;
#else
return false;
#endif
}
void ProjectSettings::SetSyncLock(bool flag)
{
auto &project = mProject;
if (flag != mIsSyncLocked) {
mIsSyncLocked = flag;
Notify( project, ChangedSyncLock );
}
}