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(":")),
95  *(int*)&mTempSettings.scaleType,
96  &mScaleChoices);
97 
98  mRangeChoice =
99  S.Id(ID_RANGE).TieChoice(_("Waveform dB &range") + wxString(wxT(":")),
100  *(int*)&mTempSettings.dBRange,
101  &mRangeChoices);
103  }
104  S.EndTwoColumn();
105  }
106  S.EndStatic();
107  }
108  // S.EndStatic();
109 
110  /*
111  S.StartStatic(_("Global settings"));
112  {
113  }
114  S.EndStatic();
115  */
116 
117  S.EndScroller();
118 
120 
121  mPopulating = false;
122 }
123 
125 {
126  // Do checking for whole numbers
127 
128  // ToDo: use wxIntegerValidator<unsigned> when available
129 
132 
133  // Delegate range checking to WaveformSettings class
135  const bool result = mTempSettings.Validate(false);
137  return result;
138 }
139 
141 {
142  const bool isOpenPage = this->IsShown();
143 
144  const auto partner =
145  mWt ?
146  // Assume linked track is wave or null
147  static_cast<WaveTrack*>(mWt->GetLink())
148  : nullptr;
149 
152 
155 
156  if (mWt) {
157  if (mDefaulted) {
159  if (partner)
160  partner->SetWaveformSettings({});
161  }
162  else {
163  WaveformSettings *pSettings =
165  *pSettings = mTempSettings;
166  if (partner) {
167  pSettings = &partner->GetIndependentWaveformSettings();
168  *pSettings = mTempSettings;
169  }
170  }
171  }
172 
173  if (!mWt || mDefaulted) {
174  WaveformSettings *const pSettings =
176  *pSettings = mTempSettings;
177  pSettings->SavePrefs();
178  }
179 
181 
182  if (mWt && isOpenPage) {
184  if (partner)
185  partner->SetDisplay(WaveTrack::Waveform);
186  }
187 
188  if (isOpenPage) {
190  tp->UpdateVRulers();
191  tp->Refresh(false);
192  }
193 
194  return true;
195 }
196 
198 {
199  return true;
200 }
201 
202 void WaveformPrefs::OnControl(wxCommandEvent&)
203 {
204  // Common routine for most controls
205  // If any per-track setting is changed, break the association with defaults
206  // Skip this, and View Settings... will be able to change defaults instead
207  // when the checkbox is on, as in the original design.
208 
209  if (mDefaultsCheckbox && !mPopulating) {
210  mDefaulted = false;
211  mDefaultsCheckbox->SetValue(false);
212  }
213 }
214 
215 void WaveformPrefs::OnScale(wxCommandEvent &e)
216 {
218 
219  // do the common part
220  OnControl(e);
221 }
222 
223 void WaveformPrefs::OnDefaults(wxCommandEvent &)
224 {
225  if (mDefaultsCheckbox->IsChecked()) {
228  mDefaulted = true;
231  }
232 }
233 
235 {
236  mRangeChoice->Enable
237  (mScaleChoice->GetSelection() == WaveformSettings::stLogarithmic);
238 }
239 
240 BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
241 
242 EVT_CHOICE(ID_SCALE, WaveformPrefs::OnScale)
243 EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl)
244 
245 EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults)
247 
249 : mWt(wt)
250 {
251 }
252 
253 PrefsPanel *WaveformPrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
254 {
255  wxASSERT(parent); // to justify safenew
256  return safenew WaveformPrefs(parent, winid, mWt);
257 }
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:366
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:742
WaveformSettings & GetIndependentWaveformSettings()
Definition: WaveTrack.cpp:758
static void GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes)
Definition: GUIPrefs.cpp:50
bool Validate(bool quiet)
static WaveformSettings & defaults()
void EndScroller()
Definition: ShuttleGui.cpp:770
void OnDefaults(wxCommandEvent &)
#define safenew
Definition: Audacity.h:223
WaveTrack *const mWt
Definition: WaveformPrefs.h:43
PrefsPanel * operator()(wxWindow *parent, wxWindowID winid) override
A PrefsPanel for spectrum settings.
Definition: WaveformPrefs.h:23
void PopulateOrExchange(ShuttleGui &S)
void SetSizeHints(int minX=-1, int minY=-1)
void OnScale(wxCommandEvent &)
void SetDisplay(WaveTrackDisplay display)
Definition: WaveTrack.h:589
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:733
void StartTwoColumn()
Definition: ShuttleGui.h:125
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:43
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
virtual ~WaveformPrefs()
wxCheckBox * TieCheckBox(const wxString &Prompt, WrappedType &WrappedRef)
void OnControl(wxCommandEvent &)
Track * GetLink() const
Definition: Track.cpp:267
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
wxCheckBox * mDefaultsCheckbox
Definition: WaveformPrefs.h:46
bool Validate() override
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:701
wxChoice * mScaleChoice
Definition: WaveformPrefs.h:47
WaveTrack *const mWt
Definition: WaveformPrefs.h:66
TrackPanel * GetTrackPanel()
Definition: Project.h:289
WaveformSettings mTempSettings
Definition: WaveformPrefs.h:54
END_EVENT_TABLE()
void UpdateVRulers()
void SetBorder(int Border)
Definition: ShuttleGui.h:251
void EndTwoColumn()
Definition: ShuttleGui.h:126
wxArrayString mScaleChoices
Definition: WaveformPrefs.h:50
void SetWaveformSettings(std::unique_ptr< WaveformSettings > &&pSettings)
Definition: WaveTrack.cpp:765
Waveform settings, either for one track or as defaults.