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 channel->SetWaveformSettings({});
172 else {
174 channel->GetWaveformSettings();
176 }
177 }
178 }
179
180 WaveformSettings *const pSettings = &WaveformSettings::defaults();
181 if (!mWt || mDefaulted) {
182 *pSettings = mTempSettings;
183 pSettings->SavePrefs();
184 }
185 pSettings->LoadPrefs(); // always; in case Globals changed
186
188
189 if (mWt && isOpenPage) {
190 for (auto channel : TrackList::Channels(mWt))
191 WaveTrackView::Get( *channel )
193 }
194
195 if (isOpenPage) {
196 if ( mProject ) {
197 auto &tp = TrackPanel::Get( *mProject );
198 tp.UpdateVRulers();
199 tp.Refresh(false);
200 }
201 }
202
203 return true;
204}
205
207{
208 return true;
209}
210
211void WaveformPrefs::OnControl(wxCommandEvent&)
212{
213 // Common routine for most controls
214 // If any per-track setting is changed, break the association with defaults
215 // Skip this, and View Settings... will be able to change defaults instead
216 // when the checkbox is on, as in the original design.
217
219 mDefaulted = false;
220 mDefaultsCheckbox->SetValue(false);
221 }
222}
223
224void WaveformPrefs::OnScale(wxCommandEvent &e)
225{
227
228 // do the common part
229 OnControl(e);
230}
231
232void WaveformPrefs::OnDefaults(wxCommandEvent &)
233{
234 if (mDefaultsCheckbox->IsChecked()) {
237 mDefaulted = true;
240 }
241}
242
244{
245 mRangeChoice->Enable
247}
248
249BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
250
253
256
257PrefsPanel::Factory
259{
260 return [=](wxWindow *parent, wxWindowID winid, AudacityProject *pProject)
261 {
262 wxASSERT(parent); // to justify safenew
263 return safenew WaveformPrefs(parent, winid, pProject, wt);
264 };
265}
266#if 0
267namespace{
269 WaveformPrefsFactory( nullptr ),
270 false,
271 // Register with an explicit ordering hint because this one is
272 // only conditionally compiled; and place it at a lower tree level
273 { "Tracks", { Registry::OrderingHint::Before, "Spectrum" } }
274};
275}
276#endif
END_EVENT_TABLE()
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#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:41
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:48
@ eIsGettingFromDialog
Definition: ShuttleGui.h:40
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:87
@ ID_SCALE
@ ID_DEFAULTS
@ ID_RANGE
PrefsPanel::Factory WaveformPrefsFactory(WaveTrack *wt)
#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:89
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
Definition: GUIPrefs.cpp:63
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:631
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1533
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:229
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:847
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()
bool Validate(bool quiet)
static WaveformSettings & defaults()