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#include "ShuttleGui.h"
22#include "wxPanelWrapper.h"
23#include <wx/spinctrl.h>
24#include "AudacityMessageBox.h"
25
27{
28}
29
30std::vector<UIHandlePtr> TimeTrackControls::HitTest
31(const TrackPanelMouseState & state,
32 const AudacityProject *pProject)
33{
34 return CommonTrackControls::HitTest(state, pProject);
35}
36
37enum
38{
43};
44
46{
47 static TimeTrackMenuTable instance;
48 return instance;
49}
50
52{
53 mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
54}
55
56void TimeTrackMenuTable::OnSetTimeTrackRange(wxCommandEvent & /*event*/)
57{
58 auto &track = static_cast<TimeTrack&>(mpData->track);
59 long lower = (long)(track.GetRangeLower() * 100.0 + 0.5);
60 long upper = (long)(track.GetRangeUpper() * 100.0 + 0.5);
61
62 // MB: these lower/upper limits match the maximum allowed range of the time track
63 // envelope, but this is not strictly required
64
65 wxDialogWrapper dlg(mpData->pParent, wxID_ANY, XO("Change Speed Limits"));
66 dlg.SetName();
68 wxSpinCtrl *scLower;
69 wxSpinCtrl *scUpper;
70
71 S.StartVerticalLay(true);
72 {
73 S.StartStatic(XO("Change speed limit (%) to:"),1);
74 {
75 S.StartMultiColumn(2, wxEXPAND);
76 {
77
78 S.SetStretchyCol(1);
79
80 S.AddPrompt(XXO("Lower Speed Limit"));
81 scLower = safenew wxSpinCtrl(S.GetParent(), wxID_ANY,
82 wxT(""),
83 wxDefaultPosition,
84 wxDefaultSize,
85 wxSP_ARROW_KEYS,
87 S
88 .Name(XO("Lower Speed Limit"))
89 .Position( wxALIGN_LEFT | wxALL )
90 .AddWindow(scLower);
91
92 S.AddPrompt(XXO("Upper Speed Limit"));
93 scUpper = safenew wxSpinCtrl(S.GetParent(), wxID_ANY,
94 wxT(""),
95 wxDefaultPosition,
96 wxDefaultSize,
97 wxSP_ARROW_KEYS,
99 S
100 .Name(XO("Upper Speed Limit"))
101 .Position( wxALIGN_LEFT | wxALL )
102 .AddWindow(scUpper);
103
104 }
105 S.EndMultiColumn();
106 }
107 S.EndStatic();
108 S.AddStandardButtons();
109 }
110 S.EndVerticalLay();
111
112 dlg.Layout();
113 dlg.Fit();
114 dlg.CenterOnParent();
115 if (dlg.ShowModal() == wxID_CANCEL)
116 return;
117
118 while(scLower->GetValue() >= scUpper->GetValue()) {
120 XO("Upper Speed Limit must be greater than the Lower Speed Limit"),
121 XO("Invalid Limits"),
122 wxOK | wxICON_ERROR,
123 mpData->pParent);
124
125 if (dlg.ShowModal() == wxID_CANCEL)
126 return;
127 }
128
129 lower = scLower->GetValue();
130 upper = scUpper->GetValue();
131
132 if (lower >= TimeTrackControls::kRangeMin &&
135 track.SetRangeLower((double)lower / 100.0);
136 track.SetRangeUpper((double)upper / 100.0);
138 .PushState(XO("Set range to '%ld' - '%ld'").Format( lower, upper ),
139 /* i18n-hint: (verb)*/
140 XO("Set Range"));
142 }
143}
144
145void TimeTrackMenuTable::OnTimeTrackLin(wxCommandEvent & /*event*/)
146{
147 auto &track = static_cast<TimeTrack&>(mpData->track);
148 track.SetDisplayLog(false);
151 .PushState(XO("Set time track display to linear"), XO("Set Display"));
152
153 using namespace RefreshCode;
155}
156
157void TimeTrackMenuTable::OnTimeTrackLog(wxCommandEvent & /*event*/)
158{
159 auto &track = static_cast<TimeTrack&>(mpData->track);
160 track.SetDisplayLog(true);
163 .PushState(XO("Set time track display to logarithmic"), XO("Set Display"));
164
165 using namespace RefreshCode;
167}
168
169void TimeTrackMenuTable::OnTimeTrackLogInt(wxCommandEvent & /*event*/)
170{
171 auto &track = static_cast<TimeTrack&>(mpData->track);
173 if (track.GetInterpolateLog()) {
174 track.SetInterpolateLog(false);
176 .PushState(XO("Set time track interpolation to linear"), XO("Set Interpolation"));
177 }
178 else {
179 track.SetInterpolateLog(true);
180 ProjectHistory::Get( *project ).
181 PushState(XO("Set time track interpolation to logarithmic"), XO("Set Interpolation"));
182 }
184}
185
187 static const auto findTrack =
189 return static_cast<TimeTrack&>(
190 static_cast<TimeTrackMenuTable&>(handler).mpData->track);
191 };
192
193 BeginSection( "Scales" );
194 AppendRadioItem( "Linear", OnTimeTrackLinID, XXO("&Linear scale"),
195 POPUP_MENU_FN( OnTimeTrackLin ),
196 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
197 menu.Check( id, !findTrack(handler).GetDisplayLog() );
198 } );
199 AppendRadioItem( "Log", OnTimeTrackLogID, XXO("L&ogarithmic scale"),
200 POPUP_MENU_FN( OnTimeTrackLog ),
201 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
202 menu.Check( id, findTrack(handler).GetDisplayLog() );
203 } );
205
206 BeginSection( "Other" );
207 AppendItem( "Range", OnSetTimeTrackRangeID, XXO("&Range..."),
208 POPUP_MENU_FN( OnSetTimeTrackRange ) );
210 XXO("Logarithmic &Interpolation"), POPUP_MENU_FN( OnTimeTrackLogInt),
211 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
212 menu.Check( id, findTrack(handler).GetInterpolateLog() );
213 } );
214 EndSection();
215
217
219{
221}
222
225 return [](TimeTrack &track) {
226 return std::make_shared<TimeTrackControls>( track.SharedPointer() );
227 };
228}
229
230#include "../../ui/ChannelView.h"
231
234 return [](TimeTrack &) {
235 return 100;
236 };
237}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
#define END_POPUP_MENU()
#define BEGIN_POPUP_MENU(HandlerClass)
#define POPUP_MENU_FN(memFn)
@ eIsCreating
Definition: ShuttleGui.h:37
const auto project
EndSection()
AppendCheckItem("LogInterp", OnTimeTrackLogIntID, XXO("Logarithmic &Interpolation"), POPUP_MENU_FN(OnTimeTrackLogInt), [](PopupMenuHandler &handler, wxMenu &menu, int id){ menu.Check(id, findTrack(handler).GetInterpolateLog());})
@ 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());})
BeginSection("Scales")
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(DoGetTimeTrackControls)
static const auto findTrack
AppendItem("Range", OnSetTimeTrackRangeID, XXO("&Range..."), POPUP_MENU_FN(OnSetTimeTrackRange))
#define S(N)
Definition: ToChars.cpp:64
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)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
static const int kRangeMin
static const int kRangeMax
~TimeTrackControls() override
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:24
void SetDisplayLog(bool displayLog)
Definition: TimeTrack.h:96
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:110
void SetName(const TranslatableString &title)
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
For defining overrides of the method.