Audacity  3.0.3
WaveformPrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 WaveformPrefs.cpp
6 
7 Paul 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 
33 WaveformPrefs::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) {
42  WaveformSettings &settings = wt->GetWaveformSettings();
43  mDefaulted = (&WaveformSettings::defaults() == &settings);
44  mTempSettings = settings;
45  }
46  else {
47  mTempSettings = WaveformSettings::defaults();
48  mDefaulted = false;
49  }
50 
51  mTempSettings.ConvertToEnumeratedDBRange();
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 
74 enum {
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  {
102  mDefaultsCheckbox = 0;
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  {
112  mScaleChoice =
113  S.Id(ID_SCALE).TieChoice(XXO("S&cale:"),
116 
117  mRangeChoice =
118  S.Id(ID_RANGE).TieChoice(XXO("Waveform dB &range:"),
120  mRangeChoices);
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 
211 void 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 
218  if (mDefaultsCheckbox && !mPopulating) {
219  mDefaulted = false;
220  mDefaultsCheckbox->SetValue(false);
221  }
222 }
223 
224 void WaveformPrefs::OnScale(wxCommandEvent &e)
225 {
227 
228  // do the common part
229  OnControl(e);
230 }
231 
232 void WaveformPrefs::OnDefaults(wxCommandEvent &)
233 {
234  if (mDefaultsCheckbox->IsChecked()) {
237  mDefaulted = true;
240  }
241 }
242 
244 {
245  mRangeChoice->Enable
246  (mScaleChoice->GetSelection() == WaveformSettings::stLogarithmic);
247 }
248 
249 BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
250 
251 EVT_CHOICE(ID_SCALE, WaveformPrefs::OnScale)
253 
256 
257 PrefsPanel::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
267 namespace{
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
WaveformSettings::scaleType
ScaleType scaleType
Definition: WaveformSettings.h:67
WaveformPrefs::mDefaulted
bool mDefaulted
Definition: WaveformPrefs.h:53
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
WaveformPrefs::mWt
WaveTrack *const mWt
Definition: WaveformPrefs.h:52
WaveformPrefs::~WaveformPrefs
virtual ~WaveformPrefs()
Definition: WaveformPrefs.cpp:55
WaveformPrefs::mScaleChoice
wxChoice * mScaleChoice
Definition: WaveformPrefs.h:56
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
eIsGettingFromDialog
@ eIsGettingFromDialog
Definition: ShuttleGui.h:39
WaveformSettings::Validate
bool Validate(bool quiet)
Definition: WaveformSettings.cpp:75
WaveformSettings::Globals::Get
static Globals & Get()
Definition: WaveformSettings.cpp:43
WaveformPrefs::OnScale
void OnScale(wxCommandEvent &)
Definition: WaveformPrefs.cpp:224
WaveformPrefs::mDefaultsCheckbox
wxCheckBox * mDefaultsCheckbox
Definition: WaveformPrefs.h:55
WaveformPrefs::Validate
bool Validate() override
Definition: WaveformPrefs.cpp:142
WAVEFORM_PREFS_PLUGIN_SYMBOL
#define WAVEFORM_PREFS_PLUGIN_SYMBOL
Definition: WaveformPrefs.h:23
Project.h
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1629
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
WaveformPrefs::mTempSettings
WaveformSettings mTempSettings
Definition: WaveformPrefs.h:62
ID_RANGE
@ ID_RANGE
Definition: WaveformPrefs.cpp:78
WaveformPrefs::Populate
void Populate()
Definition: WaveformPrefs.cpp:81
PrefsPanel::Registration
Definition: PrefsPanel.h:84
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
XO
#define XO(s)
Definition: Internat.h:31
ID_DEFAULTS
@ ID_DEFAULTS
Definition: WaveformPrefs.cpp:75
WaveformPrefs::mProject
AudacityProject * mProject
Definition: WaveformPrefs.h:50
eIsSettingToDialog
@ eIsSettingToDialog
Definition: ShuttleGui.h:40
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
WaveformPrefs::WaveformPrefs
WaveformPrefs(wxWindow *parent, wxWindowID winid, AudacityProject *pProject, WaveTrack *wt)
Definition: WaveformPrefs.cpp:33
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
WaveformPrefs::GetDescription
TranslatableString GetDescription() override
Definition: WaveformPrefs.cpp:64
WaveformSettings::stLogarithmic
@ stLogarithmic
Definition: WaveformSettings.h:60
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:971
WaveformPrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: WaveformPrefs.cpp:59
WaveformPrefs
A PrefsPanel for spectrum settings.
Definition: WaveformPrefs.h:26
ID_SCALE
@ ID_SCALE
Definition: WaveformPrefs.cpp:77
WaveformSettings::LoadPrefs
void LoadPrefs()
Definition: WaveformSettings.cpp:87
WaveformPrefs::OnControl
void OnControl(wxCommandEvent &)
Definition: WaveformPrefs.cpp:211
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:938
WaveformSettings::GetScaleNames
static const EnumValueSymbols & GetScaleNames()
Definition: WaveformSettings.cpp:162
WaveformSettings::ConvertToActualDBRange
void ConvertToActualDBRange()
Definition: WaveformSettings.cpp:137
WaveformPrefs::mRangeChoices
TranslatableStrings mRangeChoices
Definition: WaveformPrefs.h:60
anonymous_namespace{Contrast.cpp}::sAttachment
AttachedItem sAttachment
Definition: Contrast.cpp:697
GUIPrefs::GetRangeChoices
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
Definition: GUIPrefs.cpp:64
WaveformSettings::Globals::SavePrefs
void SavePrefs()
Definition: WaveformSettings.cpp:34
Decibels.h
ShuttleGuiBase::StartTwoColumn
void StartTwoColumn()
Definition: ShuttleGui.h:366
Registry::OrderingHint::Before
@ Before
Definition: Registry.h:29
WaveformPrefsFactory
PrefsPanel::Factory WaveformPrefsFactory(WaveTrack *wt)
Definition: WaveformPrefs.cpp:258
WaveformPrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: WaveformPrefs.cpp:93
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
Definition: ShuttleGui.cpp:2522
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
WaveformSettings::defaults
static WaveformSettings & defaults()
Definition: WaveformSettings.cpp:69
WaveformPrefs::OnDefaults
void OnDefaults(wxCommandEvent &)
Definition: WaveformPrefs.cpp:232
WaveformPrefs::HelpPageName
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
Definition: WaveformPrefs.cpp:69
WaveformPrefs::mPopulating
bool mPopulating
Definition: WaveformPrefs.h:64
TaggedIdentifier< ManualPageIDTag >
WaveformSettings::ConvertToEnumeratedDBRange
void ConvertToEnumeratedDBRange()
Definition: WaveformSettings.cpp:122
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
GUIPrefs.h
WaveformPrefs::Commit
bool Commit() override
Definition: WaveformPrefs.cpp:158
WaveTrackView::Get
static WaveTrackView & Get(WaveTrack &track)
Definition: WaveTrackView.cpp:851
WaveformPrefs.h
WaveformSettings::dBRange
int dBRange
Definition: WaveformSettings.h:68
WaveformSettings
Waveform settings, either for one track or as defaults.
Definition: WaveformSettings.h:19
WaveformPrefs::ShowsPreviewButton
bool ShowsPreviewButton() override
Definition: WaveformPrefs.cpp:206
WaveformPrefs::mRangeCodes
wxArrayStringEx mRangeCodes
Definition: WaveformPrefs.h:59
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
WaveformSettings::SavePrefs
void SavePrefs()
Definition: WaveformSettings.cpp:99
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
ShuttleGuiBase::EndTwoColumn
void EndTwoColumn()
Definition: ShuttleGui.h:367
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:47
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
safenew
#define safenew
Definition: MemoryX.h:10
settings
static Settings & settings()
Definition: TrackInfo.cpp:86
WaveTrackView::SetDisplay
void SetDisplay(Display display, bool exclusive=true)
Definition: WaveTrackView.cpp:963
WaveformPrefs::EnableDisableRange
void EnableDisableRange()
Definition: WaveformPrefs.cpp:243
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1727
WaveformPrefs::mRangeChoice
wxChoice * mRangeChoice
Definition: WaveformPrefs.h:57
WaveTrackViewConstants::Waveform
@ Waveform
Definition: WaveTrackViewConstants.h:24
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631