Audacity 3.2.0
TimeTrackControls.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TimeTrackControls.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12#include "TimeTrackControls.h"
13
14#include "../../../HitTestResult.h"
15#include "Project.h"
16#include "ProjectHistory.h"
17#include "../../../RefreshCode.h"
18#include "TimeTrack.h"
19#include "../../../widgets/PopupMenuTable.h"
20#include <wx/numdlg.h>
21
23{
24}
25
26std::vector<UIHandlePtr> TimeTrackControls::HitTest
27(const TrackPanelMouseState & state,
28 const AudacityProject *pProject)
29{
30 return CommonTrackControls::HitTest(state, pProject);
31}
32
33enum
34{
39};
40
42{
43 static TimeTrackMenuTable instance;
44 return instance;
45}
46
48{
49 mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
50}
51
52void TimeTrackMenuTable::OnSetTimeTrackRange(wxCommandEvent & /*event*/)
53{
54 TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
55 if (pTrack) {
56 long lower = (long)(pTrack->GetRangeLower() * 100.0 + 0.5);
57 long upper = (long)(pTrack->GetRangeUpper() * 100.0 + 0.5);
58
59 // MB: these lower/upper limits match the maximum allowed range of the time track
60 // envelope, but this is not strictly required
61 lower = wxGetNumberFromUser(_("Change lower speed limit (%) to:"),
62 _("Lower speed limit"),
63 _("Lower speed limit"),
64 lower,
67
68 upper = wxGetNumberFromUser(_("Change upper speed limit (%) to:"),
69 _("Upper speed limit"),
70 _("Upper speed limit"),
71 upper,
72 lower + 1,
74
75 if (lower >= TimeTrackControls::kRangeMin &&
77 lower < upper) {
79 pTrack->SetRangeLower((double)lower / 100.0);
80 pTrack->SetRangeUpper((double)upper / 100.0);
82 .PushState(XO("Set range to '%ld' - '%ld'").Format( lower, upper ),
83 /* i18n-hint: (verb)*/
84 XO("Set Range"));
86 }
87 }
88}
89
90void TimeTrackMenuTable::OnTimeTrackLin(wxCommandEvent & /*event*/)
91{
92 TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
93 pTrack->SetDisplayLog(false);
96 .PushState(XO("Set time track display to linear"), XO("Set Display"));
97
98 using namespace RefreshCode;
100}
101
102void TimeTrackMenuTable::OnTimeTrackLog(wxCommandEvent & /*event*/)
103{
104 TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
105 pTrack->SetDisplayLog(true);
108 .PushState(XO("Set time track display to logarithmic"), XO("Set Display"));
109
110 using namespace RefreshCode;
112}
113
114void TimeTrackMenuTable::OnTimeTrackLogInt(wxCommandEvent & /*event*/)
115{
116 TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
118 if (pTrack->GetInterpolateLog()) {
119 pTrack->SetInterpolateLog(false);
121 .PushState(XO("Set time track interpolation to linear"), XO("Set Interpolation"));
122 }
123 else {
124 pTrack->SetInterpolateLog(true);
125 ProjectHistory::Get( *project ).
126 PushState(XO("Set time track interpolation to logarithmic"), XO("Set Interpolation"));
127 }
129}
130
132 static const auto findTrack = []( PopupMenuHandler &handler ){
133 return static_cast<TimeTrack*>(
134 static_cast<TimeTrackMenuTable&>( handler ).mpData->pTrack );
135 };
136
137 BeginSection( "Scales" );
138 AppendRadioItem( "Linear", OnTimeTrackLinID, XXO("&Linear scale"),
139 POPUP_MENU_FN( OnTimeTrackLin ),
140 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
141 menu.Check( id, !findTrack(handler)->GetDisplayLog() );
142 } );
143 AppendRadioItem( "Log", OnTimeTrackLogID, XXO("L&ogarithmic scale"),
144 POPUP_MENU_FN( OnTimeTrackLog ),
145 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
146 menu.Check( id, findTrack(handler)->GetDisplayLog() );
147 } );
149
150 BeginSection( "Other" );
151 AppendItem( "Range", OnSetTimeTrackRangeID, XXO("&Range..."),
152 POPUP_MENU_FN( OnSetTimeTrackRange ) );
154 XXO("Logarithmic &Interpolation"), POPUP_MENU_FN( OnTimeTrackLogInt),
155 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
156 menu.Check( id, findTrack(handler)->GetInterpolateLog() );
157 } );
158 EndSection();
159
161
163{
165}
166
169 return [](TimeTrack &track) {
170 return std::make_shared<TimeTrackControls>( track.SharedPointer() );
171 };
172}
173
174#include "../../ui/ChannelView.h"
175
178 return [](TimeTrack &) {
179 return 100;
180 };
181}
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define _(s)
Definition: Internat.h:73
#define END_POPUP_MENU()
#define BEGIN_POPUP_MENU(HandlerClass)
#define POPUP_MENU_FN(memFn)
const auto project
EndSection()
@ OnTimeTrackLogIntID
@ OnTimeTrackLinID
@ OnTimeTrackLogID
@ OnSetTimeTrackRangeID
AppendRadioItem("Linear", OnTimeTrackLinID, XXO("&Linear scale"), POPUP_MENU_FN(OnTimeTrackLin), [](PopupMenuHandler &handler, wxMenu &menu, int id){ menu.Check(id, !findTrack(handler) ->GetDisplayLog());})
AppendCheckItem("LogInterp", OnTimeTrackLogIntID, XXO("Logarithmic &Interpolation"), POPUP_MENU_FN(OnTimeTrackLogInt), [](PopupMenuHandler &handler, wxMenu &menu, int id){ menu.Check(id, findTrack(handler) ->GetInterpolateLog());})
BeginSection("Scales")
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(DoGetTimeTrackControls)
static const auto findTrack
AppendItem("Range", OnSetTimeTrackRangeID, XXO("&Range..."), POPUP_MENU_FN(OnSetTimeTrackRange))
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
Abstract base class used in importing a file.
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
static const int kRangeMin
static const int kRangeMax
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:24
void SetInterpolateLog(bool interpolateLog)
Definition: TimeTrack.cpp:250
void SetDisplayLog(bool displayLog)
Definition: TimeTrack.h:95
bool GetInterpolateLog() const
Definition: TimeTrack.cpp:245
void SetRangeLower(double lower)
Definition: TimeTrack.cpp:122
double GetRangeLower() const
Definition: TimeTrack.cpp:112
double GetRangeUpper() const
Definition: TimeTrack.cpp:117
void SetRangeUpper(double upper)
Definition: TimeTrack.cpp:127
void OnTimeTrackLog(wxCommandEvent &)
static TimeTrackMenuTable & Instance()
void OnTimeTrackLin(wxCommandEvent &)
void OnSetTimeTrackRange(wxCommandEvent &)
void InitUserData(void *pUserData) override
Called before the menu items are appended.
void OnTimeTrackLogInt(wxCommandEvent &)
CommonTrackControls::InitMenuData * mpData
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
For defining overrides of the method.