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
23// private helper classes and functions
24namespace {
25
27{
28 auto &viewInfo = ViewInfo::Get( project );
29 auto &viewport = Viewport::Get(project);
30
31 const double lowerBound =
32 std::max(viewInfo.selectedRegion.t0(),
33 viewport.ScrollingLowerBoundTime());
34 const double denom =
35 viewInfo.selectedRegion.t1() - lowerBound;
36 if (denom <= 0.0)
37 return viewInfo.GetZoom();
38
39 // LL: The "-1" is just a hack to get around an issue where zooming to
40 // selection doesn't actually get the entire selected region within the
41 // visible area. This causes a problem with scrolling at end of playback
42 // where the selected region may be scrolled off the left of the screen.
43 // I know this isn't right, but until the real rounding or 1-off issue is
44 // found, this will have to work.
45 // PRL: Did I fix this? I am not sure, so I leave the hack in place.
46 // Fixes might have resulted from commits
47 // 1b8f44d0537d987c59653b11ed75a842b48896ea and
48 // e7c7bb84a966c3b3cc4b3a9717d5f247f25e7296
49 auto width = viewInfo.GetTracksUsableWidth();
50 return (width - 1) / denom;
51}
52
54{
55
56 // Sets a limit on how far we will zoom out as a factor over zoom to fit.
57 const double maxZoomOutFactor = 4.0;
58 // Sets how many pixels we allow for one uint, such as seconds.
59 const double pixelsPerUnit = 5.0;
60
61 double result = 1.0;
62 auto &viewport = Viewport::Get(project);
63 double zoomToFit = viewport.GetZoomOfToFit();
64 using namespace WaveChannelViewConstants;
65 switch(preset) {
66 default:
67 case kZoomDefault:
68 result = ZoomInfo::GetDefaultZoom();
69 break;
70 case kZoomToFit:
71 result = zoomToFit;
72 break;
74 result = GetZoomOfSelection( project );
75 break;
76 case kZoomMinutes:
77 result = pixelsPerUnit * 1.0/60;
78 break;
79 case kZoomSeconds:
80 result = pixelsPerUnit * 1.0;
81 break;
82 case kZoom5ths:
83 result = pixelsPerUnit * 5.0;
84 break;
85 case kZoom10ths:
86 result = pixelsPerUnit * 10.0;
87 break;
88 case kZoom20ths:
89 result = pixelsPerUnit * 20.0;
90 break;
91 case kZoom50ths:
92 result = pixelsPerUnit * 50.0;
93 break;
94 case kZoom100ths:
95 result = pixelsPerUnit * 100.0;
96 break;
97 case kZoom500ths:
98 result = pixelsPerUnit * 500.0;
99 break;
101 result = pixelsPerUnit * 1000.0;
102 break;
103 case kZoomSamples:
104 result = 44100.0;
105 break;
106 case kZoom4To1:
107 result = 44100.0 * 4;
108 break;
109 case kMaxZoom:
110 result = ZoomInfo::GetMaxZoom();
111 break;
112 };
113 if( result < (zoomToFit/maxZoomOutFactor) )
114 result = zoomToFit / maxZoomOutFactor;
115 return result;
116}
117
118}
119
120namespace {
121
122// Menu handler functions
123
124void OnZoomIn(const CommandContext &context)
125{
126 auto &project = context.project;
127 auto &trackPanel = TrackPanel::Get( project );
128 auto &viewport = Viewport::Get(project);
129
130 auto gAudioIO = AudioIO::Get();
131 // LLL: Handling positioning differently when audio is
132 // actively playing. Don't do this if paused.
133 if (gAudioIO->IsStreamActive(
135 !gAudioIO->IsPaused()){
136 viewport.ZoomBy(2.0);
137 viewport.ScrollIntoView(gAudioIO->GetStreamTime());
138 }
139 else
140 viewport.ZoomAboutSelection(2.0);
141
142 trackPanel.Refresh(false);
143}
144
145void OnZoomNormal(const CommandContext &context)
146{
147 auto &project = context.project;
148 auto &trackPanel = TrackPanel::Get( project );
149 auto &viewport = Viewport::Get(project);
150 viewport.Zoom(ZoomInfo::GetDefaultZoom());
151 trackPanel.Refresh(false);
152}
153
154void OnZoomOut(const CommandContext &context)
155{
156 auto &project = context.project;
157 auto &viewport = Viewport::Get(project);
158 viewport.ZoomAboutCenter(0.5);
159}
160
161void OnZoomSel(const CommandContext &context)
162{
163 auto &project = context.project;
164 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
165 auto &viewport = Viewport::Get(project);
166 viewport.Zoom(GetZoomOfSelection(project));
167 viewport.SetHorizontalThumb(selectedRegion.t0());
168}
169
170void OnZoomToggle(const CommandContext &context)
171{
172 auto &project = context.project;
173 auto &viewInfo = ViewInfo::Get( project );
174 auto &trackPanel = TrackPanel::Get( project );
175 auto &viewport = Viewport::Get(project);
176
177// const double origLeft = viewInfo.h;
178// const double origWidth = viewInfo.GetScreenEndTime() - origLeft;
179
180 // Choose the zoom that is most different to the current zoom.
183 double Z = viewInfo.GetZoom();// Current Zoom.
184 double ChosenZoom =
185 fabs(log(Zoom1 / Z)) > fabs(log( Z / Zoom2)) ? Zoom1:Zoom2;
186
187 viewport.Zoom(ChosenZoom);
188 trackPanel.Refresh(false);
189// const double newWidth = GetScreenEndTime() - viewInfo.h;
190// const double newh = origLeft + (origWidth - newWidth) / 2;
191// SetHorizontalThumb(newh);
192}
193
194void OnZoomFit(const CommandContext &context)
195{
196 auto &project = context.project;
197 auto &viewport = Viewport::Get(project);
198 viewport.ZoomFitHorizontally();
199}
200
201void OnZoomFitV(const CommandContext &context)
202{
203 auto &project = context.project;
204 auto &viewport = Viewport::Get(project);
205 viewport.ZoomFitVertically();
207}
208
210{
211 auto &project = context.project;
214}
215
217{
218 auto &project = context.project;
221}
222
223void OnGoSelStart(const CommandContext &context)
224{
225 auto &project = context.project;
226 auto &viewInfo = ViewInfo::Get( project );
227 auto &selectedRegion = viewInfo.selectedRegion;
228 auto &viewport = Viewport::Get(project);
229
230 if (selectedRegion.isPoint())
231 return;
232
233 viewport.SetHorizontalThumb(
234 selectedRegion.t0() - ((viewInfo.GetScreenEndTime() - viewInfo.hpos) / 2));
235}
236
237void OnGoSelEnd(const CommandContext &context)
238{
239 auto &project = context.project;
240 auto &viewInfo = ViewInfo::Get( project );
241 auto &selectedRegion = viewInfo.selectedRegion;
242 auto &viewport = Viewport::Get(project);
243
244 if (selectedRegion.isPoint())
245 return;
246
247 viewport.SetHorizontalThumb(
248 selectedRegion.t1() - ((viewInfo.GetScreenEndTime() - viewInfo.hpos) / 2));
249}
250
252{
253 auto &project = context.project;
254 auto &commandManager = CommandManager::Get( project );
255
256 bool checked = !gPrefs->Read(wxT("/GUI/ShowExtraMenus"), 0L);
257 gPrefs->Write(wxT("/GUI/ShowExtraMenus"), checked);
258 gPrefs->Flush();
259 commandManager.Check(wxT("ShowExtraMenus"), checked);
261}
262
263void OnShowClipping(const CommandContext &context)
264{
265 auto &project = context.project;
266 auto &commandManager = CommandManager::Get( project );
267 auto &trackPanel = TrackPanel::Get( project );
268
269 bool checked = !gPrefs->Read(wxT("/GUI/ShowClipping"), 0L);
270 gPrefs->Write(wxT("/GUI/ShowClipping"), checked);
271 gPrefs->Flush();
272 commandManager.Check(wxT("ShowClipping"), checked);
273
275
276 trackPanel.Refresh(false);
277}
278
280{
281 auto &project = context.project;
282 auto &commandManager = CommandManager::Get( project );
283 auto &trackPanel = TrackPanel::Get( project );
284
285 bool checked = !gPrefs->Read(wxT("/GUI/ShowTrackNameInWaveform"), 0L);
286 gPrefs->Write(wxT("/GUI/ShowTrackNameInWaveform"), checked);
287 gPrefs->Flush();
288 commandManager.Check(wxT("ShowTrackNameInWaveform"), checked);
289
291
292 trackPanel.Refresh(false);
293}
294
295} // namespace
296
297// Menu definitions
298
299// Under /MenuBar
300namespace {
301using namespace MenuRegistry;
303{
304 static auto menu = std::shared_ptr{
305 Menu( wxT("View"), XXO("&View"),
306 Section( "Basic",
307 Menu( wxT("Zoom"), XXO("&Zoom"),
308 Command( wxT("ZoomIn"), XXO("Zoom &In"), OnZoomIn,
309 ZoomInAvailableFlag(), wxT("Ctrl+1") ),
310 Command( wxT("ZoomNormal"), XXO("Zoom &Normal"), OnZoomNormal,
311 TracksExistFlag(), wxT("Ctrl+2") ),
312 Command( wxT("ZoomOut"), XXO("Zoom &Out"), OnZoomOut,
313 ZoomOutAvailableFlag(), wxT("Ctrl+3") ),
314 Command( wxT("ZoomSel"), XXO("&Zoom to Selection"), OnZoomSel,
315 TimeSelectedFlag(), wxT("Ctrl+E") ),
316 Command( wxT("ZoomToggle"), XXO("Zoom &Toggle"), OnZoomToggle,
317 TracksExistFlag(), wxT("Shift+Z") )
318 ),
319
320 Menu( wxT("TrackSize"), XXO("T&rack Size"),
321 Command( wxT("FitInWindow"), XXO("&Fit to Width"), OnZoomFit,
322 TracksExistFlag(), wxT("Ctrl+F") ),
323 Command( wxT("FitV"), XXO("Fit to &Height"), OnZoomFitV,
324 TracksExistFlag(), wxT("Ctrl+Shift+F") ),
325 Command( wxT("CollapseAllTracks"), XXO("&Collapse All Tracks"),
326 OnCollapseAllTracks, TracksExistFlag(), wxT("Ctrl+Shift+C") ),
327 Command( wxT("ExpandAllTracks"), XXO("E&xpand Collapsed Tracks"),
328 OnExpandAllTracks, TracksExistFlag(), wxT("Ctrl+Shift+X") )
329 ),
330
331 Menu( wxT("SkipTo"), XXO("Sk&ip to"),
332 Command( wxT("SkipSelStart"), XXO("Selection Sta&rt"),
334 Options{ wxT("Ctrl+["), XO("Skip to Selection Start") } ),
335 Command( wxT("SkipSelEnd"), XXO("Selection En&d"), OnGoSelEnd,
337 Options{ wxT("Ctrl+]"), XO("Skip to Selection End") } )
338 )
339 ),
340
341 Section( "Windows" ),
342
343 Section( "Other",
344 Command( wxT("ShowExtraMenus"), XXO("Enable E&xtra Menus"),
346 Options{}.CheckTest( wxT("/GUI/ShowExtraMenus"), false ) ),
347 Command( wxT("ShowTrackNameInWaveform"), XXO("Show Track &Name as overlay"),
349 Options{}.CheckTest( wxT("/GUI/ShowTrackNameInWaveform"), false ) ),
350 Command( wxT("ShowClipping"), XXO("&Show Clipping in Waveform"),
352 Options{}.CheckTest( wxT("/GUI/ShowClipping"), false ) )
353 )
354 ) };
355 return menu;
356}
357
359}
360
361#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")
int ShowTrackNameInWaveformPrefsID()
Definition: GUIPrefs.cpp:234
int ShowClippingPrefsID()
Definition: GUIPrefs.cpp:228
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
EffectReverbSettings preset
Definition: Reverb.cpp:44
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
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
static CommandManager & Get(AudacityProject &project)
static void RebuildAllMenuBars()
static void Broadcast(int id=0)
Call this static function to notify all PrefsListener objects.
Definition: Prefs.cpp:128
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 TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
static WaveChannelViewConstants::ZoomPresets Zoom1Choice()
static WaveChannelViewConstants::ZoomPresets Zoom2Choice()
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void CollapseAllTracks()
Definition: Viewport.cpp:739
void ExpandAllTracks()
Definition: Viewport.cpp:729
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:263
void OnCollapseAllTracks(const CommandContext &context)
Definition: ViewMenus.cpp:209
double GetZoomOfPreset(const AudacityProject &project, int preset)
Definition: ViewMenus.cpp:53
void OnZoomFit(const CommandContext &context)
Definition: ViewMenus.cpp:194
void OnShowNameOverlay(const CommandContext &context)
Definition: ViewMenus.cpp:279
void OnShowExtraMenus(const CommandContext &context)
Definition: ViewMenus.cpp:251
void OnZoomFitV(const CommandContext &context)
Definition: ViewMenus.cpp:201
void OnZoomToggle(const CommandContext &context)
Definition: ViewMenus.cpp:170
void OnZoomIn(const CommandContext &context)
Definition: ViewMenus.cpp:124
void OnZoomNormal(const CommandContext &context)
Definition: ViewMenus.cpp:145
void OnZoomSel(const CommandContext &context)
Definition: ViewMenus.cpp:161
void OnGoSelEnd(const CommandContext &context)
Definition: ViewMenus.cpp:237
void OnZoomOut(const CommandContext &context)
Definition: ViewMenus.cpp:154
double GetZoomOfSelection(const AudacityProject &project)
Definition: ViewMenus.cpp:26
void OnGoSelStart(const CommandContext &context)
Definition: ViewMenus.cpp:223
void OnExpandAllTracks(const CommandContext &context)
Definition: ViewMenus.cpp:216
Options && CheckTest(const CheckFn &fn) &&
Definition: MenuRegistry.h:74