Audacity  3.0.3
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 
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 
26 std::vector<UIHandlePtr> TimeTrackControls::HitTest
27 (const TrackPanelMouseState & state,
28  const AudacityProject *pProject)
29 {
30  return CommonTrackControls::HitTest(state, pProject);
31 }
32 
33 enum
34 {
39 };
40 
42 {
43  static TimeTrackMenuTable instance;
44  return instance;
45 }
46 
47 void TimeTrackMenuTable::InitUserData(void *pUserData)
48 {
49  mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
50 }
51 
52 void 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) {
78  AudacityProject *const project = &mpData->project;
79  pTrack->SetRangeLower((double)lower / 100.0);
80  pTrack->SetRangeUpper((double)upper / 100.0);
81  ProjectHistory::Get( *project )
82  .PushState(XO("Set range to '%ld' - '%ld'").Format( lower, upper ),
83  /* i18n-hint: (verb)*/
84  XO("Set Range"));
86  }
87  }
88 }
89 
90 void TimeTrackMenuTable::OnTimeTrackLin(wxCommandEvent & /*event*/)
91 {
92  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
93  pTrack->SetDisplayLog(false);
94  AudacityProject *const project = &mpData->project;
95  ProjectHistory::Get( *project )
96  .PushState(XO("Set time track display to linear"), XO("Set Display"));
97 
98  using namespace RefreshCode;
100 }
101 
102 void TimeTrackMenuTable::OnTimeTrackLog(wxCommandEvent & /*event*/)
103 {
104  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
105  pTrack->SetDisplayLog(true);
106  AudacityProject *const project = &mpData->project;
107  ProjectHistory::Get( *project )
108  .PushState(XO("Set time track display to logarithmic"), XO("Set Display"));
109 
110  using namespace RefreshCode;
112 }
113 
114 void TimeTrackMenuTable::OnTimeTrackLogInt(wxCommandEvent & /*event*/)
115 {
116  TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
117  AudacityProject *const project = &mpData->project;
118  if (pTrack->GetInterpolateLog()) {
119  pTrack->SetInterpolateLog(false);
120  ProjectHistory::Get( *project )
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"),
140  []( PopupMenuHandler &handler, wxMenu &menu, int id ){
141  menu.Check( id, !findTrack(handler)->GetDisplayLog() );
142  } );
143  AppendRadioItem( "Log", OnTimeTrackLogID, XXO("L&ogarithmic scale"),
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..."),
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/TrackView.h"
175 
178  return [](TimeTrack &) {
179  return 100;
180  };
181 }
OnTimeTrackLinID
@ OnTimeTrackLinID
Definition: TimeTrackControls.cpp:35
TimeTrack::GetRangeLower
double GetRangeLower() const
Definition: TimeTrack.cpp:117
TimeTrackMenuTable::OnSetTimeTrackRange
void OnSetTimeTrackRange(wxCommandEvent &)
Definition: TimeTrackControls.cpp:52
TimeTrackMenuTable::mpData
CommonTrackControls::InitMenuData * mpData
Definition: TimeTrackControls.h:54
TimeTrackMenuTable::InitUserData
void InitUserData(void *pUserData) override
Called before the menu items are appended.
Definition: TimeTrackControls.cpp:47
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
TimeTrackControls::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Definition: TimeTrackControls.cpp:27
Project.h
PopupMenuTable
Definition: PopupMenuTable.h:115
TimeTrack::GetRangeUpper
double GetRangeUpper() const
Definition: TimeTrack.cpp:122
Format
Abstract base class used in importing a file.
PopupMenuTable::EndSection
void EndSection()
Definition: PopupMenuTable.cpp:184
TimeTrackControls
Definition: TimeTrackControls.h:17
XO
#define XO(s)
Definition: Internat.h:31
OnTimeTrackLogID
@ OnTimeTrackLogID
Definition: TimeTrackControls.cpp:36
CommonTrackControls::InitMenuData::result
unsigned result
Definition: CommonTrackControls.h:39
PopupMenuTable::AppendRadioItem
void AppendRadioItem(const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
Definition: PopupMenuTable.h:208
findTrack
static const auto findTrack
Definition: TimeTrackControls.cpp:132
PopupMenuTable::BeginSection
void BeginSection(const Identifier &name)
Definition: PopupMenuTable.cpp:176
CommonTrackControls::InitMenuData::project
AudacityProject & project
Definition: CommonTrackControls.h:36
DEFINE_ATTACHED_VIRTUAL_OVERRIDE
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(DoGetTimeTrackControls)
Definition: TimeTrackControls.cpp:168
TimeTrackMenuTable::OnTimeTrackLin
void OnTimeTrackLin(wxCommandEvent &)
Definition: TimeTrackControls.cpp:90
TimeTrack::GetInterpolateLog
bool GetInterpolateLog() const
Definition: TimeTrack.cpp:217
TimeTrack::SetDisplayLog
void SetDisplayLog(bool displayLog)
Definition: TimeTrack.h:89
XXO
#define XXO(s)
Definition: Internat.h:44
TimeTrackMenuTable
Definition: TimeTrackControls.h:40
CommonTrackControls::HitTest
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
Definition: CommonTrackControls.cpp:36
PopupMenuTable::AppendItem
void AppendItem(const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
Definition: PopupMenuTable.h:202
PopupMenuTable::AppendCheckItem
void AppendCheckItem(const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
Definition: PopupMenuTable.h:214
TimeTrackControls::kRangeMax
static const int kRangeMax
Definition: TimeTrackControls.h:34
RefreshCode::UpdateVRuler
@ UpdateVRuler
Definition: RefreshCode.h:30
OnSetTimeTrackRangeID
@ OnSetTimeTrackRangeID
Definition: TimeTrackControls.cpp:38
CommonTrackControls::InitMenuData
Definition: CommonTrackControls.h:34
TimeTrackControls::~TimeTrackControls
~TimeTrackControls()
Definition: TimeTrackControls.cpp:22
POPUP_MENU_FN
#define POPUP_MENU_FN(memFn)
Definition: PopupMenuTable.h:324
BEGIN_POPUP_MENU
#define BEGIN_POPUP_MENU(HandlerClass)
Definition: PopupMenuTable.h:316
ProjectHistory::PushState
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
Definition: ProjectHistory.cpp:90
OnTimeTrackLogIntID
@ OnTimeTrackLogIntID
Definition: TimeTrackControls.cpp:37
TimeTrackMenuTable::OnTimeTrackLog
void OnTimeTrackLog(wxCommandEvent &)
Definition: TimeTrackControls.cpp:102
TimeTrackControls.h
PopupMenuHandler
Definition: PopupMenuTable.h:85
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
_
#define _(s)
Definition: Internat.h:75
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
TimeTrackMenuTable::OnTimeTrackLogInt
void OnTimeTrackLogInt(wxCommandEvent &)
Definition: TimeTrackControls.cpp:114
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
TimeTrack::SetInterpolateLog
void SetInterpolateLog(bool interpolateLog)
Definition: TimeTrack.cpp:222
AttachedVirtualFunction::Override
For defining overrides of the method.
Definition: AttachedVirtualFunction.h:184
TimeTrackMenuTable::Instance
static TimeTrackMenuTable & Instance()
Definition: TimeTrackControls.cpp:41
TimeTrack::SetRangeLower
void SetRangeLower(double lower)
Definition: TimeTrack.cpp:127
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
CommonTrackControls::InitMenuData::pTrack
Track * pTrack
Definition: CommonTrackControls.h:37
TimeTrack::SetRangeUpper
void SetRangeUpper(double upper)
Definition: TimeTrack.cpp:132
TimeTrack
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:24
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
TimeTrackControls::kRangeMin
static const int kRangeMin
Definition: TimeTrackControls.h:33
END_POPUP_MENU
#define END_POPUP_MENU()
Definition: PopupMenuTable.h:331