Audacity 3.2.0
ViewMenus.cpp
Go to the documentation of this file.
1#include "AudioIO.h"
2#include "../CommonCommandFlags.h"
3#include "../MenuCreator.h"
4#include "Prefs.h"
5#include "Project.h"
6#include "ProjectAudioIO.h"
7#include "ProjectHistory.h"
8#include "Track.h"
9#include "../TrackPanel.h"
10#include "UndoManager.h"
11#include "ViewInfo.h"
12#include "Viewport.h"
13#include "CommandContext.h"
14#include "CommandManager.h"
15#include "../prefs/GUIPrefs.h"
16#include "../prefs/TracksPrefs.h"
17
18#include <wx/app.h>
19#include <wx/scrolbar.h>
20
21#include <numeric>
22
24
25// private helper classes and functions
26namespace {
27
29{
30 auto &viewInfo = ViewInfo::Get( project );
31 auto &viewport = Viewport::Get(project);
32
33 const double lowerBound =
34 std::max(viewInfo.selectedRegion.t0(),
35 viewport.ScrollingLowerBoundTime());
36 const double denom =
37 viewInfo.selectedRegion.t1() - lowerBound;
38 if (denom <= 0.0)
39 return viewInfo.GetZoom();
40
41 // LL: The "-1" is just a hack to get around an issue where zooming to
42 // selection doesn't actually get the entire selected region within the
43 // visible area. This causes a problem with scrolling at end of playback
44 // where the selected region may be scrolled off the left of the screen.
45 // I know this isn't right, but until the real rounding or 1-off issue is
46 // found, this will have to work.
47 // PRL: Did I fix this? I am not sure, so I leave the hack in place.
48 // Fixes might have resulted from commits
49 // 1b8f44d0537d987c59653b11ed75a842b48896ea and
50 // e7c7bb84a966c3b3cc4b3a9717d5f247f25e7296
51 auto width = viewInfo.GetTracksUsableWidth();
52 return (width - 1) / denom;
53}
54
56{
57
58 // Sets a limit on how far we will zoom out as a factor over zoom to fit.
59 const double maxZoomOutFactor = 4.0;
60 // Sets how many pixels we allow for one uint, such as seconds.
61 const double pixelsPerUnit = 5.0;
62
63 double result = 1.0;
64 auto &viewport = Viewport::Get(project);
65 double zoomToFit = viewport.GetZoomOfToFit();
66 using namespace WaveChannelViewConstants;
67 switch(preset) {
68 default:
69 case kZoomDefault:
70 result = ZoomInfo::GetDefaultZoom();
71 break;
72 case kZoomToFit:
73 result = zoomToFit;
74 break;
76 result = GetZoomOfSelection( project );
77 break;
78 case kZoomMinutes:
79 result = pixelsPerUnit * 1.0/60;
80 break;
81 case kZoomSeconds:
82 result = pixelsPerUnit * 1.0;
83 break;
84 case kZoom5ths:
85 result = pixelsPerUnit * 5.0;
86 break;
87 case kZoom10ths:
88 result = pixelsPerUnit * 10.0;
89 break;
90 case kZoom20ths:
91 result = pixelsPerUnit * 20.0;
92 break;
93 case kZoom50ths:
94 result = pixelsPerUnit * 50.0;
95 break;
96 case kZoom100ths:
97 result = pixelsPerUnit * 100.0;
98 break;
99 case kZoom500ths:
100 result = pixelsPerUnit * 500.0;
101 break;
103 result = pixelsPerUnit * 1000.0;
104 break;
105 case kZoomSamples:
106 result = 44100.0;
107 break;
108 case kZoom4To1:
109 result = 44100.0 * 4;
110 break;
111 case kMaxZoom:
112 result = ZoomInfo::GetMaxZoom();
113 break;
114 };
115 if( result < (zoomToFit/maxZoomOutFactor) )
116 result = zoomToFit / maxZoomOutFactor;
117 return result;
118}
119
120}
121
122namespace {
123
124// Menu handler functions
125
126void OnZoomIn(const CommandContext &context)
127{
128 auto &project = context.project;
129 auto &trackPanel = TrackPanel::Get( project );
130 auto &viewport = Viewport::Get(project);
131
132 auto gAudioIO = AudioIO::Get();
133 // LLL: Handling positioning differently when audio is
134 // actively playing. Don't do this if paused.
135 if (gAudioIO->IsStreamActive(
137 !gAudioIO->IsPaused()){
138 viewport.ZoomBy(2.0);
139 viewport.ScrollIntoView(gAudioIO->GetStreamTime());
140 }
141 else
142 viewport.ZoomAboutSelection(2.0);
143
144 trackPanel.Refresh(false);
145}
146
147void OnZoomNormal(const CommandContext &context)
148{
149 auto &project = context.project;
150 auto &trackPanel = TrackPanel::Get( project );
151 auto &viewport = Viewport::Get(project);
152 viewport.Zoom(ZoomInfo::GetDefaultZoom());
153 trackPanel.Refresh(false);
154}
155
156void OnZoomOut(const CommandContext &context)
157{
158 auto &project = context.project;
159 auto &viewport = Viewport::Get(project);
160 viewport.ZoomAboutCenter(0.5);
161}
162
163void OnZoomSel(const CommandContext &context)
164{
165 auto &project = context.project;
166 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
167 auto &viewport = Viewport::Get(project);
168 viewport.Zoom(GetZoomOfSelection(project));
169 viewport.SetHorizontalThumb(selectedRegion.t0());
170}
171
172void OnZoomToggle(const CommandContext &context)
173{
174 auto &project = context.project;
175 auto &viewInfo = ViewInfo::Get( project );
176 auto &trackPanel = TrackPanel::Get( project );
177 auto &viewport = Viewport::Get(project);
178
179// const double origLeft = viewInfo.h;
180// const double origWidth = viewInfo.GetScreenEndTime() - origLeft;
181
182 // Choose the zoom that is most different to the current zoom.
185 double Z = viewInfo.GetZoom();// Current Zoom.
186 double ChosenZoom =
187 fabs(log(Zoom1 / Z)) > fabs(log( Z / Zoom2)) ? Zoom1:Zoom2;
188
189 viewport.Zoom(ChosenZoom);
190 trackPanel.Refresh(false);
191// const double newWidth = GetScreenEndTime() - viewInfo.h;
192// const double newh = origLeft + (origWidth - newWidth) / 2;
193// SetHorizontalThumb(newh);
194}
195
196void OnZoomFit(const CommandContext &context)
197{
198 auto &project = context.project;
199 auto &viewport = Viewport::Get(project);
200 viewport.ZoomFitHorizontally();
201}
202
203void OnZoomFitV(const CommandContext &context)
204{
205 auto &project = context.project;
206 auto &viewport = Viewport::Get(project);
207 viewport.ZoomFitVertically();
209}
210
212{
213 auto &project = context.project;
216}
217
219{
220 auto &project = context.project;
223}
224
225void OnGoSelStart(const CommandContext &context)
226{
227 auto &project = context.project;
228 auto &viewInfo = ViewInfo::Get( project );
229 auto &selectedRegion = viewInfo.selectedRegion;
230 auto &viewport = Viewport::Get(project);
231
232 if (selectedRegion.isPoint())
233 return;
234
235 viewport.SetHorizontalThumb(
236 selectedRegion.t0() - ((viewInfo.GetScreenEndTime() - viewInfo.hpos) / 2));
237}
238
239void OnGoSelEnd(const CommandContext &context)
240{
241 auto &project = context.project;
242 auto &viewInfo = ViewInfo::Get( project );
243 auto &selectedRegion = viewInfo.selectedRegion;
244 auto &viewport = Viewport::Get(project);
245
246 if (selectedRegion.isPoint())
247 return;
248
249 viewport.SetHorizontalThumb(
250 selectedRegion.t1() - ((viewInfo.GetScreenEndTime() - viewInfo.hpos) / 2));
251}
252
254{
255 auto &project = context.project;
256 auto &commandManager = CommandManager::Get( project );
257
258 bool checked = !gPrefs->Read(wxT("/GUI/ShowExtraMenus"), 0L);
259 gPrefs->Write(wxT("/GUI/ShowExtraMenus"), checked);
260 gPrefs->Flush();
261 commandManager.Check(wxT("ShowExtraMenus"), checked);
263}
264
265void OnShowClipping(const CommandContext &context)
266{
267 auto &project = context.project;
268 auto &commandManager = CommandManager::Get( project );
269 auto &trackPanel = TrackPanel::Get( project );
270
272 gPrefs->Flush();
273
274 trackPanel.Refresh(false);
275}
276
277void OnShowRMS(const CommandContext &context)
278{
279 auto &project = context.project;
280 auto &trackPanel = TrackPanel::Get( project );
281
283 gPrefs->Flush();
284
286
287 trackPanel.Refresh(false);
288}
289
290} // namespace
291
292// Menu definitions
293
294// Under /MenuBar
295namespace {
296using namespace MenuRegistry;
298{
299 static auto menu = std::shared_ptr{
300 Menu( wxT("View"), XXO("&View"),
301 Section( "Basic",
302 Menu( wxT("Zoom"), XXO("&Zoom"),
303 Command( wxT("ZoomIn"), XXO("Zoom &In"), OnZoomIn,
304 ZoomInAvailableFlag(), wxT("Ctrl+1") ),
305 Command( wxT("ZoomNormal"), XXO("Zoom &Normal"), OnZoomNormal,
306 TracksExistFlag(), wxT("Ctrl+2") ),
307 Command( wxT("ZoomOut"), XXO("Zoom &Out"), OnZoomOut,
308 ZoomOutAvailableFlag(), wxT("Ctrl+3") ),
309 Command( wxT("ZoomSel"), XXO("&Zoom to Selection"), OnZoomSel,
310 TimeSelectedFlag(), wxT("Ctrl+E") ),
311 Command( wxT("ZoomToggle"), XXO("Zoom &Toggle"), OnZoomToggle,
312 TracksExistFlag(), wxT("Shift+Z") )
313 ),
314
315 Menu( wxT("TrackSize"), XXO("T&rack Size"),
316 Command( wxT("FitInWindow"), XXO("&Fit to Width"), OnZoomFit,
317 TracksExistFlag(), wxT("Ctrl+F") ),
318 Command( wxT("FitV"), XXO("Fit to &Height"), OnZoomFitV,
319 TracksExistFlag(), wxT("Ctrl+Shift+F") ),
320 Command( wxT("CollapseAllTracks"), XXO("&Collapse All Tracks"),
321 OnCollapseAllTracks, TracksExistFlag(), wxT("Ctrl+Shift+C") ),
322 Command( wxT("ExpandAllTracks"), XXO("E&xpand Collapsed Tracks"),
323 OnExpandAllTracks, TracksExistFlag(), wxT("Ctrl+Shift+X") )
324 ),
325
326 Menu( wxT("SkipTo"), XXO("Sk&ip to"),
327 Command( wxT("SkipSelStart"), XXO("Selection Sta&rt"),
329 Options{ wxT("Ctrl+["), XO("Skip to Selection Start") } ),
330 Command( wxT("SkipSelEnd"), XXO("Selection En&d"), OnGoSelEnd,
332 Options{ wxT("Ctrl+]"), XO("Skip to Selection End") } )
333 )
334 ),
335
336 Section( "Windows" ),
337
338 Section( "Other",
339 Command( wxT("ShowExtraMenus"), XXO("E&xtra Menus"),
341 Options{}.CheckTest( wxT("/GUI/ShowExtraMenus"), false ) ),
342 Command( wxT("ShowClipping"), XXO("&Show Clipping in Waveform"),
345 Command( wxT("ShowRMS"), XXO("Sho&w RMS in Waveform"),
348 )
349 ) };
350 return menu;
351}
352
354}
355
356#undef FN
wxT("CloseDown"))
AttachedItem sAttachment1
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
const ReservedCommandFlag & ZoomInAvailableFlag()
const ReservedCommandFlag & ZoomOutAvailableFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & TracksExistFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
BoolSetting & ShowRMSPref()
Definition: GUIPrefs.cpp:190
BoolSetting & ShowClippingPref()
Definition: GUIPrefs.cpp:196
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
ReverbSettings preset
Definition: ReverbBase.cpp:25
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIO * Get()
Definition: AudioIO.cpp:126
bool Toggle()
Write the negation of the previous value, and return true if successful.
Definition: Prefs.cpp:555
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
static CommandManager & Get(AudacityProject &project)
static void RebuildAllMenuBars()
int GetAudioIOToken() const
static ProjectAudioIO & Get(AudacityProject &project)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
static void ModifyAllProjectToolbarMenus()
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
static WaveChannelViewConstants::ZoomPresets Zoom1Choice()
static WaveChannelViewConstants::ZoomPresets Zoom2Choice()
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void CollapseAllTracks()
Definition: Viewport.cpp:743
void ExpandAllTracks()
Definition: Viewport.cpp:733
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
static double GetDefaultZoom()
Definition: ZoomInfo.h:116
static double GetMaxZoom()
Definition: ZoomInfo.cpp:82
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
constexpr auto Section
Definition: MenuRegistry.h:436
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175
void OnShowClipping(const CommandContext &context)
Definition: ViewMenus.cpp:265
void OnCollapseAllTracks(const CommandContext &context)
Definition: ViewMenus.cpp:211
double GetZoomOfPreset(const AudacityProject &project, int preset)
Definition: ViewMenus.cpp:55
void OnZoomFit(const CommandContext &context)
Definition: ViewMenus.cpp:196
void OnShowExtraMenus(const CommandContext &context)
Definition: ViewMenus.cpp:253
void OnZoomFitV(const CommandContext &context)
Definition: ViewMenus.cpp:203
void OnZoomToggle(const CommandContext &context)
Definition: ViewMenus.cpp:172
void OnZoomIn(const CommandContext &context)
Definition: ViewMenus.cpp:126
void OnZoomNormal(const CommandContext &context)
Definition: ViewMenus.cpp:147
void OnShowRMS(const CommandContext &context)
Definition: ViewMenus.cpp:277
void OnZoomSel(const CommandContext &context)
Definition: ViewMenus.cpp:163
void OnGoSelEnd(const CommandContext &context)
Definition: ViewMenus.cpp:239
void OnZoomOut(const CommandContext &context)
Definition: ViewMenus.cpp:156
double GetZoomOfSelection(const AudacityProject &project)
Definition: ViewMenus.cpp:28
void OnGoSelStart(const CommandContext &context)
Definition: ViewMenus.cpp:225
void OnExpandAllTracks(const CommandContext &context)
Definition: ViewMenus.cpp:218
Options && CheckTest(const CheckFn &fn) &&
Definition: MenuRegistry.h:74