Audacity 3.2.0
WaveformPrefs.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveformPrefs.cpp
6
7Paul Licameli
8
9*******************************************************************//*******************************************************************/
15
16
17#include "WaveformPrefs.h"
18
19#include "GUIPrefs.h"
20#include "Decibels.h"
21
22#include <wx/checkbox.h>
23#include <wx/choice.h>
24
25#include "Project.h"
26
27#include "../TrackPanel.h"
28#include "ShuttleGui.h"
29#include "WaveTrack.h"
30#include "../tracks/playabletrack/wavetrack/ui/WaveTrackView.h"
31#include "../tracks/playabletrack/wavetrack/ui/WaveTrackViewConstants.h"
32
33WaveformPrefs::WaveformPrefs(wxWindow * parent, wxWindowID winid,
34 AudacityProject *pProject, WaveTrack *wt)
35/* i18n-hint: A waveform is a visual representation of vibration */
36: PrefsPanel(parent, winid, XO("Waveforms"))
37, mProject{ pProject }
38, mWt(wt)
39, mPopulating(false)
40{
41 if (mWt) {
45 }
46 else {
48 mDefaulted = false;
49 }
50
52 Populate();
53}
54
56{
57}
58
60{
62}
63
65{
66 return XO("Preferences for Waveforms");
67}
68
70{
71 return "Waveform_Preferences";
72}
73
74enum {
75 ID_DEFAULTS = 10001,
76
79};
80
82{
83 // Reuse the same choices and codes as for Interface prefs
85
86 //------------------------- Main section --------------------
87 // Now construct the GUI itself.
90 // ----------------------- End of main section --------------
91}
92
94{
95 mPopulating = true;
96
97 S.SetBorder(2);
98 S.StartScroller();
99
100 // S.StartStatic(XO("Track Settings"));
101 {
103 if (mWt) {
104 /* i18n-hint: use is a verb */
105 mDefaultsCheckbox = S.Id(ID_DEFAULTS).TieCheckBox(XXO("&Use Preferences"), mDefaulted);
106 }
107
108 S.StartStatic(XO("Display"));
109 {
110 S.StartTwoColumn();
111 {
113 S.Id(ID_SCALE).TieChoice(XXO("S&cale:"),
116
118 S.Id(ID_RANGE).TieChoice(XXO("Waveform dB &range:"),
121 }
122 S.EndTwoColumn();
123 }
124 S.EndStatic();
125 }
126 // S.EndStatic();
127
128 /*
129 S.StartStatic(XO("Global settings"));
130 {
131 }
132 S.EndStatic();
133 */
134
135 S.EndScroller();
136
138
139 mPopulating = false;
140}
141
143{
144 // Do checking for whole numbers
145
146 // ToDo: use wxIntegerValidator<unsigned> when available
147
150
151 // Delegate range checking to WaveformSettings class
153 const bool result = mTempSettings.Validate(false);
155 return result;
156}
157
159{
160 const bool isOpenPage = this->IsShown();
161
164
167
168 if (mWt) {
169 for (auto channel : TrackList::Channels(mWt)) {
170 if (mDefaulted)
171 WaveformSettings::Set(*channel, {});
172 else {
173 auto &settings = WaveformSettings::Get(*channel);
175 }
176 }
177 }
178
179 WaveformSettings *const pSettings = &WaveformSettings::defaults();
180 if (!mWt || mDefaulted) {
181 *pSettings = mTempSettings;
182 pSettings->SavePrefs();
183 }
184 pSettings->LoadPrefs(); // always; in case Globals changed
185
187
188 if (mWt && isOpenPage) {
189 for (auto channel : TrackList::Channels(mWt))
190 WaveTrackView::Get( *channel )
192 }
193
194 if (isOpenPage) {
195 if ( mProject ) {
196 auto &tp = TrackPanel::Get( *mProject );
197 tp.UpdateVRulers();
198 tp.Refresh(false);
199 }
200 }
201
202 return true;
203}
204
206{
207 return true;
208}
209
210void WaveformPrefs::OnControl(wxCommandEvent&)
211{
212 // Common routine for most controls
213 // If any per-track setting is changed, break the association with defaults
214 // Skip this, and View Settings... will be able to change defaults instead
215 // when the checkbox is on, as in the original design.
216
218 mDefaulted = false;
219 mDefaultsCheckbox->SetValue(false);
220 }
221}
222
223void WaveformPrefs::OnScale(wxCommandEvent &e)
224{
226
227 // do the common part
228 OnControl(e);
229}
230
231void WaveformPrefs::OnDefaults(wxCommandEvent &)
232{
233 if (mDefaultsCheckbox->IsChecked()) {
236 mDefaulted = true;
239 }
240}
241
243{
244 mRangeChoice->Enable(
246}
247
248BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
249
252
255
256PrefsPanel::Factory
258{
259 return [=](wxWindow *parent, wxWindowID winid, AudacityProject *pProject)
260 {
261 wxASSERT(parent); // to justify safenew
262 return safenew WaveformPrefs(parent, winid, pProject, wt);
263 };
264}
265#if 0
266namespace{
268 WaveformPrefsFactory( nullptr ),
269 false,
270 // Register with an explicit ordering hint because this one is
271 // only conditionally compiled; and place it at a lower tree level
272 { "Tracks", { Registry::OrderingHint::Before, "Spectrum" } }
273};
274}
275#endif
END_EVENT_TABLE()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
@ eIsSettingToDialog
Definition: ShuttleGui.h:39
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:46
@ eIsGettingFromDialog
Definition: ShuttleGui.h:38
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:87
PrefsPanel::Factory WaveformPrefsFactory(WaveTrack *wt)
@ ID_SCALE
@ ID_DEFAULTS
@ ID_RANGE
#define WAVEFORM_PREFS_PLUGIN_SYMBOL
Definition: WaveformPrefs.h:23
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
Definition: GUIPrefs.cpp:65
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1544
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
void SetDisplay(Display display, bool exclusive=true)
static WaveTrackView & Get(WaveTrack &track)
A PrefsPanel for spectrum settings.
Definition: WaveformPrefs.h:26
virtual ~WaveformPrefs()
bool ShowsPreviewButton() override
TranslatableStrings mRangeChoices
Definition: WaveformPrefs.h:60
void OnControl(wxCommandEvent &)
TranslatableString GetDescription() const override
void OnDefaults(wxCommandEvent &)
WaveformSettings mTempSettings
Definition: WaveformPrefs.h:62
ComponentInterfaceSymbol GetSymbol() const override
void EnableDisableRange()
AudacityProject * mProject
Definition: WaveformPrefs.h:50
void OnScale(wxCommandEvent &)
wxChoice * mRangeChoice
Definition: WaveformPrefs.h:57
bool Commit() override
WaveTrack *const mWt
Definition: WaveformPrefs.h:52
WaveformPrefs(wxWindow *parent, wxWindowID winid, AudacityProject *pProject, WaveTrack *wt)
wxChoice * mScaleChoice
Definition: WaveformPrefs.h:56
wxCheckBox * mDefaultsCheckbox
Definition: WaveformPrefs.h:55
void PopulateOrExchange(ShuttleGui &S) override
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
bool Validate() override
wxArrayStringEx mRangeCodes
Definition: WaveformPrefs.h:59
Waveform settings, either for one track or as defaults.
static const EnumValueSymbols & GetScaleNames()
static void Set(WaveTrack &track, std::unique_ptr< WaveformSettings > pSettings)
Guarantee independence of settings, then assign.
bool Validate(bool quiet)
static WaveformSettings & defaults()
static WaveformSettings & Get(const WaveTrack &track)