Audacity  2.2.2
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 #include "../Audacity.h"
17 #include "WaveformPrefs.h"
18 #include "GUIPrefs.h"
19 #include "GUISettings.h"
20 
21 #include <wx/checkbox.h>
22 
23 #include "../Project.h"
24 
25 #include "../TrackPanel.h"
26 #include "../ShuttleGui.h"
27 #include "../WaveTrack.h"
28 
29 WaveformPrefs::WaveformPrefs(wxWindow * parent, wxWindowID winid, WaveTrack *wt)
30 /* i18n-hint: A waveform is a visual representation of vibration */
31 : PrefsPanel(parent, winid, _("Waveforms"))
32 , mWt(wt)
33 , mPopulating(false)
34 {
35  if (mWt) {
36  WaveformSettings &settings = wt->GetWaveformSettings();
37  mDefaulted = (&WaveformSettings::defaults() == &settings);
38  mTempSettings = settings;
39  }
40  else {
42  mDefaulted = false;
43  }
44 
46  Populate();
47 }
48 
50 {
51 }
52 
53 enum {
54  ID_DEFAULTS = 10001,
55 
58 };
59 
61 {
63 
64  // Reuse the same choices and codes as for Interface prefs
66 
67  //------------------------- Main section --------------------
68  // Now construct the GUI itself.
71  // ----------------------- End of main section --------------
72 }
73 
75 {
76  mPopulating = true;
77 
78  S.SetBorder(2);
79  S.StartScroller();
80 
81  // S.StartStatic(_("Track Settings"));
82  {
84  if (mWt) {
85  /* i18n-hint: use is a verb */
86  mDefaultsCheckbox = S.Id(ID_DEFAULTS).TieCheckBox(_("&Use Preferences"), mDefaulted);
87  }
88 
89  S.StartStatic(_("Display"));
90  {
91  S.StartTwoColumn();
92  {
93  mScaleChoice =
94  S.Id(ID_SCALE).TieChoice(_("S&cale") + wxString(wxT(":")),
96  &mScaleChoices);
97 
98  mRangeChoice =
99  S.Id(ID_RANGE).TieChoice(_("Waveform dB &range") + wxString(wxT(":")),
101  &mRangeChoices);
102  }
103  S.EndTwoColumn();
104  }
105  S.EndStatic();
106  }
107  // S.EndStatic();
108 
109  /*
110  S.StartStatic(_("Global settings"));
111  {
112  }
113  S.EndStatic();
114  */
115 
116  S.EndScroller();
117 
119 
120  mPopulating = false;
121 }
122 
124 {
125  // Do checking for whole numbers
126 
127  // ToDo: use wxIntegerValidator<unsigned> when available
128 
131 
132  // Delegate range checking to WaveformSettings class
134  const bool result = mTempSettings.Validate(false);
136  return result;
137 }
138 
140 {
141  const bool isOpenPage = this->IsShown();
142 
143  const auto partner =
144  mWt ?
145  // Assume linked track is wave or null
146  static_cast<WaveTrack*>(mWt->GetLink())
147  : nullptr;
148 
151 
154 
155  if (mWt) {
156  if (mDefaulted) {
158  if (partner)
159  partner->SetWaveformSettings({});
160  }
161  else {
162  WaveformSettings *pSettings =
164  *pSettings = mTempSettings;
165  if (partner) {
166  pSettings = &partner->GetIndependentWaveformSettings();
167  *pSettings = mTempSettings;
168  }
169  }
170  }
171 
172  if (!mWt || mDefaulted) {
173  WaveformSettings *const pSettings =
175  *pSettings = mTempSettings;
176  pSettings->SavePrefs();
177  }
178 
180 
181  if (mWt && isOpenPage) {
183  if (partner)
184  partner->SetDisplay(WaveTrack::Waveform);
185  }
186 
187  if (isOpenPage) {
189  tp->UpdateVRulers();
190  tp->Refresh(false);
191  }
192 
193  return true;
194 }
195 
197 {
198  return true;
199 }
200 
201 void WaveformPrefs::OnControl(wxCommandEvent&)
202 {
203  // Common routine for most controls
204  // If any per-track setting is changed, break the association with defaults
205  // Skip this, and View Settings... will be able to change defaults instead
206  // when the checkbox is on, as in the original design.
207 
208  if (mDefaultsCheckbox && !mPopulating) {
209  mDefaulted = false;
210  mDefaultsCheckbox->SetValue(false);
211  }
212 }
213 
214 void WaveformPrefs::OnScale(wxCommandEvent &e)
215 {
217 
218  // do the common part
219  OnControl(e);
220 }
221 
222 void WaveformPrefs::OnDefaults(wxCommandEvent &)
223 {
224  if (mDefaultsCheckbox->IsChecked()) {
227  mDefaulted = true;
230  }
231 }
232 
234 {
235  mRangeChoice->Enable
236  (mScaleChoice->GetSelection() == WaveformSettings::stLogarithmic);
237 }
238 
239 BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
240 
241 EVT_CHOICE(ID_SCALE, WaveformPrefs::OnScale)
242 EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl)
243 
244 EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults)
246 
248 : mWt(wt)
249 {
250 }
251 
252 PrefsPanel *WaveformPrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
253 {
254  wxASSERT(parent); // to justify safenew
255  return safenew WaveformPrefs(parent, winid, mWt);
256 }
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
wxArrayString mRangeChoices
Definition: WaveformPrefs.h:52
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:738
WaveformSettings & GetIndependentWaveformSettings()
Definition: WaveTrack.cpp:754
static void GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes)
Definition: GUIPrefs.cpp:50
bool Validate(bool quiet)
void PopulateOrExchange(ShuttleGui &S) override
static WaveformSettings & defaults()
void EndScroller()
Definition: ShuttleGui.cpp:828
void OnDefaults(wxCommandEvent &)
#define safenew
Definition: Audacity.h:230
WaveTrack *const mWt
Definition: WaveformPrefs.h:43
PrefsPanel * operator()(wxWindow *parent, wxWindowID winid) override
A PrefsPanel for spectrum settings.
Definition: WaveformPrefs.h:23
void OnScale(wxCommandEvent &)
void SetDisplay(WaveTrackDisplay display)
Definition: WaveTrack.h:594
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:795
void StartTwoColumn()
Definition: ShuttleGui.h:136
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:245
bool ShowsPreviewButton() override
bool Commit() override
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
ShuttleGui & Id(int id)
WaveformPrefs(wxWindow *parent, wxWindowID winid, WaveTrack *wt)
void EnableDisableRange()
void Refresh(bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
static const wxArrayString & GetScaleNames()
wxChoice * mRangeChoice
Definition: WaveformPrefs.h:48
wxArrayString mRangeCodes
Definition: WaveformPrefs.h:51
Used within the PrefsDialog, classes derived from this class include AudioIOPrefs, BatchPrefs, DirectoriesPrefs, FileFormatPrefs, GUIPrefs, KeyConfigPrefs, MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
Definition: PrefsPanel.h:45
virtual ~WaveformPrefs()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxCheckBox * TieCheckBox(const wxString &Prompt, WrappedType &WrappedRef)
void OnControl(wxCommandEvent &)
Track * GetLink() const
Definition: Track.cpp:269
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
wxCheckBox * mDefaultsCheckbox
Definition: WaveformPrefs.h:46
bool Validate() override
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
wxChoice * mScaleChoice
Definition: WaveformPrefs.h:47
WaveTrack *const mWt
Definition: WaveformPrefs.h:66
TrackPanel * GetTrackPanel()
Definition: Project.h:307
WaveformSettings mTempSettings
Definition: WaveformPrefs.h:54
END_EVENT_TABLE()
void UpdateVRulers()
void SetBorder(int Border)
Definition: ShuttleGui.h:286
void EndTwoColumn()
Definition: ShuttleGui.h:137
wxArrayString mScaleChoices
Definition: WaveformPrefs.h:50
void SetWaveformSettings(std::unique_ptr< WaveformSettings > &&pSettings)
Definition: WaveTrack.cpp:761
Waveform settings, either for one track or as defaults.