Audacity  2.2.2
TimeTrackControls.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 TimeTrackControls.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../Audacity.h"
12 #include "TimeTrackControls.h"
13 #include "../../../HitTestResult.h"
14 #include "../../../Project.h"
15 #include "../../../RefreshCode.h"
16 #include "../../../TimeTrack.h"
17 #include "../../../widgets/PopupMenuTable.h"
18 #include <wx/numdlg.h>
19 
21 {
22 }
23 
24 std::vector<UIHandlePtr> TimeTrackControls::HitTest
25 (const TrackPanelMouseState & state,
26  const AudacityProject *pProject)
27 {
28  return TrackControls::HitTest(state, pProject);
29 }
30 
31 enum
32 {
37 };
38 
40 {
43 
44 public:
45  static TimeTrackMenuTable &Instance();
46 
47 private:
48  void InitMenu(Menu *pMenu, void *pUserData) override
49  {
50  mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
51  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
52 
53  pMenu->Check(OnTimeTrackLogIntID, pTrack->GetInterpolateLog());
54 
55  auto isLog = pTrack->GetDisplayLog();
56  pMenu->Check(OnTimeTrackLinID, !isLog);
57  pMenu->Check(OnTimeTrackLogID, isLog);
58  }
59 
60  void DestroyMenu() override
61  {
62  mpData = nullptr;
63  }
64 
66 
67  void OnSetTimeTrackRange(wxCommandEvent & /*event*/);
68  void OnTimeTrackLin(wxCommandEvent & /*event*/);
69  void OnTimeTrackLog(wxCommandEvent & /*event*/);
70  void OnTimeTrackLogInt(wxCommandEvent & /*event*/);
71 };
72 
74 {
75  static TimeTrackMenuTable instance;
76  return instance;
77 }
78 
79 void TimeTrackMenuTable::OnSetTimeTrackRange(wxCommandEvent & /*event*/)
80 {
81  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
82  if (pTrack) {
83  long lower = (long)(pTrack->GetRangeLower() * 100.0 + 0.5);
84  long upper = (long)(pTrack->GetRangeUpper() * 100.0 + 0.5);
85 
86  // MB: these lower/upper limits match the maximum allowed range of the time track
87  // envelope, but this is not strictly required
88  lower = wxGetNumberFromUser(_("Change lower speed limit (%) to:"),
89  _("Lower speed limit"),
90  _("Lower speed limit"),
91  lower,
92  10,
93  1000);
94 
95  upper = wxGetNumberFromUser(_("Change upper speed limit (%) to:"),
96  _("Upper speed limit"),
97  _("Upper speed limit"),
98  upper,
99  lower + 1,
100  1000);
101 
102  if (lower >= 10 && upper <= 1000 && lower < upper) {
103  AudacityProject *const project = ::GetActiveProject();
104  pTrack->SetRangeLower((double)lower / 100.0);
105  pTrack->SetRangeUpper((double)upper / 100.0);
106  project->PushState(wxString::Format(_("Set range to '%ld' - '%ld'"),
107  lower,
108  upper),
109  /* i18n-hint: (verb)*/
110  _("Set Range"));
112  }
113  }
114 }
115 
116 void TimeTrackMenuTable::OnTimeTrackLin(wxCommandEvent & /*event*/)
117 {
118  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
119  pTrack->SetDisplayLog(false);
120  AudacityProject *const project = ::GetActiveProject();
121  project->PushState(_("Set time track display to linear"), _("Set Display"));
122 
123  using namespace RefreshCode;
125 }
126 
127 void TimeTrackMenuTable::OnTimeTrackLog(wxCommandEvent & /*event*/)
128 {
129  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
130  pTrack->SetDisplayLog(true);
131  AudacityProject *const project = ::GetActiveProject();
132  project->PushState(_("Set time track display to logarithmic"), _("Set Display"));
133 
134  using namespace RefreshCode;
136 }
137 
138 void TimeTrackMenuTable::OnTimeTrackLogInt(wxCommandEvent & /*event*/)
139 {
140  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
141  AudacityProject *const project = ::GetActiveProject();
142  if (pTrack->GetInterpolateLog()) {
143  pTrack->SetInterpolateLog(false);
144  project->PushState(_("Set time track interpolation to linear"), _("Set Interpolation"));
145  }
146  else {
147  pTrack->SetInterpolateLog(true);
148  project->PushState(_("Set time track interpolation to logarithmic"), _("Set Interpolation"));
149  }
151 }
152 
156  POPUP_MENU_RADIO_ITEM(OnTimeTrackLogID, _("L&ogarithmic scale"), OnTimeTrackLog)
159  POPUP_MENU_CHECK_ITEM(OnTimeTrackLogIntID, _("Logarithmic &Interpolation"), OnTimeTrackLogInt)
161 
163 {
165 }
#define POPUP_MENU_SEPARATOR()
bool GetDisplayLog() const
Definition: TimeTrack.h:133
void SetRangeUpper(double upper)
Definition: TimeTrack.h:131
void OnTimeTrackLog(wxCommandEvent &)
#define POPUP_MENU_RADIO_ITEM(id, string, memFn)
void InitMenu(Menu *pMenu, void *pUserData) override
double GetRangeLower() const
Definition: TimeTrack.h:127
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
void SetDisplayLog(bool displayLog)
Definition: TimeTrack.h:134
#define POPUP_MENU_CHECK_ITEM(id, string, memFn)
static TimeTrackMenuTable & Instance()
#define END_POPUP_MENU()
void OnTimeTrackLogInt(wxCommandEvent &)
bool GetInterpolateLog() const
Definition: TimeTrack.cpp:145
DECLARE_POPUP_MENU(TimeTrackMenuTable)
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:29
double GetRangeUpper() const
Definition: TimeTrack.h:128
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
TrackControls::InitMenuData * mpData
void OnSetTimeTrackRange(wxCommandEvent &)
void DestroyMenu() override
_("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 &)
void SetInterpolateLog(bool interpolateLog)
Definition: TimeTrack.cpp:150
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4505
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
POPUP_MENU_ITEM(OnMoveUpID, _("Move Track &Up")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveUp"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveDownID
void SetRangeLower(double lower)
Definition: TimeTrack.h:130
void OnTimeTrackLin(wxCommandEvent &)
BEGIN_POPUP_MENU(SpectrumVRulerMenuTable)