Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Viewport Class Referencefinal

#include <Viewport.h>

Inheritance diagram for Viewport:
[legend]
Collaboration diagram for Viewport:
[legend]

Public Member Functions

 Viewport (AudacityProject &project)
 
void SetCallbacks (std::unique_ptr< ViewportCallbacks > pCallbacks)
 
double ScrollingLowerBoundTime () const
 
void DoScroll ()
 Cause refresh of viewport contents after setting scrolling or zooming. More...
 
void ScrollToStart (bool extend)
 
void ScrollToEnd (bool extend)
 
void ScrollToTop ()
 
void ScrollToBottom ()
 
void ScrollIntoView (double pos)
 Center view horizontally at the given time, if it was not in bounds. More...
 
void ScrollIntoView (int x)
 
void OnScrollLeft ()
 
void OnScrollRight ()
 
void OnScrollLeftButton ()
 
void OnScrollRightButton ()
 
void OnScroll ()
 
bool ScrollUpDown (int delta)
 
void SetHorizontalThumb (double scrollto, bool doScroll=true)
 
void Zoom (double pixelsPerSecond)
 Set timeline magnification; unchanged left edge time. More...
 
void ZoomBy (double multiplier)
 Multiply the magnification; unchanged left edge time. More...
 
void ZoomAboutSelection (double multiplier)
 
void ZoomAboutCenter (double multiplier)
 Multiply timeline magnification, conserving the midpoint time if possible. More...
 
void ZoomFitHorizontallyAndShowTrack (Track *pTrack)
 
void ShowTrack (const Track &track)
 
double GetZoomOfToFit () const
 Find pixels-per-second that would fit all tracks on the timeline. More...
 
void ZoomFitHorizontally ()
 
void ZoomFitVertically ()
 
void ExpandAllTracks ()
 
void CollapseAllTracks ()
 
void UpdateScrollbarsForTracks ()
 
void HandleResize ()
 
void ReinitScrollbars ()
 
void Redraw ()
 
void SetToDefaultSize ()
 Send a message to the main window PARENT of the viewport, to resize. More...
 
- Public Member Functions inherited from Observer::Publisher< ViewportMessage >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Public Member Functions

static ViewportGet (AudacityProject &project)
 
static const ViewportGet (const AudacityProject &project)
 

Private Member Functions

double PixelWidthBeforeTime (double scrollto) const
 
void FinishAutoScroll ()
 
void OnUndoPushedModified ()
 
void OnUndoRedo ()
 
void OnUndoReset ()
 

Private Attributes

AudacityProjectmProject
 
std::unique_ptr< ViewportCallbacksmpCallbacks {}
 
const Observer::Subscription mSnappingChangedSubscription
 
const Observer::Subscription mUndoSubscription
 
double total { 1.0 }
 
wxInt64 sbarH { 0 }
 
wxInt64 sbarScreen { 1 }
 
wxInt64 sbarTotal { 1 }
 
double sbarScale { 1.0 }
 
int scrollStep { 16 }
 
bool mAutoScrolling { false }
 
bool mbInitializingScrollbar { false }
 

Additional Inherited Members

- Public Types inherited from Observer::Publisher< ViewportMessage >
using message_type = ViewportMessage
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const ViewportMessage &) >
 Type of functions that can be connected to the Publisher. More...
 
- Static Public Attributes inherited from Observer::Publisher< ViewportMessage >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from Observer::Publisher< ViewportMessage >
CallbackReturn Publish (const ViewportMessage &message)
 Send a message to connected callbacks. More...
 

Detailed Description

Definition at line 61 of file Viewport.h.

Constructor & Destructor Documentation

◆ Viewport()

Viewport::Viewport ( AudacityProject project)
explicit

Definition at line 43 of file Viewport.cpp.

44 : mProject{ project }
46 ProjectSnap::Get(project).Subscribe([this](auto&){ Redraw(); }) }
49 switch (message.type) {
50 case UndoRedoMessage::Pushed:
51 case UndoRedoMessage::Modified:
52 return OnUndoPushedModified();
53 case UndoRedoMessage::UndoOrRedo:
54 return OnUndoRedo();
55 case UndoRedoMessage::Reset:
56 return OnUndoReset();
57 default:
58 return;
59 }
60 }) }
61{
62}
const auto project
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71
AudacityProject & mProject
Definition: Viewport.h:190
void Redraw()
Definition: Viewport.cpp:753
const Observer::Subscription mUndoSubscription
Definition: Viewport.h:196
const Observer::Subscription mSnappingChangedSubscription
Definition: Viewport.h:195
Type of message published by UndoManager.
Definition: UndoManager.h:55
enum UndoRedoMessage::Type type

References Redraw().

Here is the call graph for this function:

Member Function Documentation

◆ CollapseAllTracks()

void Viewport::CollapseAllTracks ( )

Definition at line 743 of file Viewport.cpp.

744{
745 if (!mpCallbacks)
746 return;
747 auto &project = mProject;
749 for (auto t : tracks)
750 mpCallbacks->SetMinimized(*t, true);
751}
const auto tracks
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
std::unique_ptr< ViewportCallbacks > mpCallbacks
Definition: Viewport.h:191

References TrackList::Get(), mpCallbacks, mProject, project, and tracks.

Referenced by anonymous_namespace{ViewMenus.cpp}::OnCollapseAllTracks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoScroll()

void Viewport::DoScroll ( )

Cause refresh of viewport contents after setting scrolling or zooming.

Definition at line 421 of file Viewport.cpp.

422{
423 auto &project = mProject;
424 auto &viewInfo = ViewInfo::Get( project );
425 const double lowerBound = ScrollingLowerBoundTime();
426
427 auto width = viewInfo.GetTracksUsableWidth();
428 const auto zoom = viewInfo.GetZoom();
429 viewInfo.hpos = std::clamp(sbarH / zoom, lowerBound, std::max(lowerBound, total - width / zoom));
430
431 const auto pos = mpCallbacks ? mpCallbacks->GetVerticalThumbPosition() : 0;
432 viewInfo.vpos = pos * scrollStep;
433
434 //mchinen: do not always set this project to be the active one.
435 //a project may autoscroll while playing in the background
436 //I think this is okay since OnMouseEvent has one of these.
437 //SetActiveProject(this);
438
439 if (!mAutoScrolling)
440 Publish({ true, false, false });
441}
CallbackReturn Publish(const ViewportMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
int scrollStep
Definition: Viewport.h:212
bool mAutoScrolling
Definition: Viewport.h:214
double ScrollingLowerBoundTime() const
Definition: Viewport.cpp:184
wxInt64 sbarH
Definition: Viewport.h:201
double total
Definition: Viewport.h:198

References ViewInfo::Get(), mAutoScrolling, mpCallbacks, mProject, project, Observer::Publisher< ViewportMessage >::Publish(), sbarH, ScrollingLowerBoundTime(), scrollStep, and total.

Referenced by FinishAutoScroll(), OnScroll(), OnScrollLeftButton(), OnScrollRightButton(), ScrollUpDown(), and SetHorizontalThumb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExpandAllTracks()

void Viewport::ExpandAllTracks ( )

Definition at line 733 of file Viewport.cpp.

734{
735 if (!mpCallbacks)
736 return;
737 auto &project = mProject;
739 for (auto t : tracks)
740 mpCallbacks->SetMinimized(*t, false);
741}

References TrackList::Get(), mpCallbacks, mProject, project, and tracks.

Referenced by anonymous_namespace{ViewMenus.cpp}::OnExpandAllTracks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FinishAutoScroll()

void Viewport::FinishAutoScroll ( )
private

Definition at line 69 of file Viewport.cpp.

70{
71 // Set a flag so we don't have to generate two update events
72 mAutoScrolling = true;
73
74 // Call our Scroll method which updates our ViewInfo variables
75 // to reflect the positions of the scrollbars
76 DoScroll();
77
78 mAutoScrolling = false;
79}
void DoScroll()
Cause refresh of viewport contents after setting scrolling or zooming.
Definition: Viewport.cpp:421

References DoScroll(), and mAutoScrolling.

Referenced by OnScrollLeft(), and OnScrollRight().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [1/2]

Viewport & Viewport::Get ( AudacityProject project)
static

Definition at line 33 of file Viewport.cpp.

34{
35 return project.AttachedObjects::Get<Viewport>(sKey);
36}
static const AudacityProject::AttachedObjects::RegisteredFactory sKey
Definition: Viewport.cpp:26

References project, and sKey.

Referenced by anonymous_namespace{LabelMenus.cpp}::DoAddLabel(), anonymous_namespace{TrackMenus.cpp}::DoAlign(), CommandDispatch::DoAudacityCommand(), anonymous_namespace{SelectMenus.cpp}::DoBoundaryMove(), anonymous_namespace{ClipMenus.cpp}::DoClipLeftOrRight(), anonymous_namespace{ClipMenus.cpp}::DoCursorClipBoundary(), LOFImportFileHandle::doDurationAndScrollOffset(), EffectUI::DoEffect(), anonymous_namespace{FileMenus.cpp}::DoImport(), anonymous_namespace{ImportMIDI.cpp}::DoImportMIDI(), LabelTrackView::DoKeyDown(), anonymous_namespace{TrackMenus.cpp}::DoMixAndRender(), anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel(), anonymous_namespace{NavigationMenus.cpp}::DoNextTrack(), anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected(), anonymous_namespace{EditMenus.cpp}::DoPasteText(), anonymous_namespace{NavigationMenus.cpp}::DoPrevTrack(), TrackUtilities::DoRemoveTracks(), anonymous_namespace{ClipMenus.cpp}::DoSelectClip(), Get(), anonymous_namespace{ViewMenus.cpp}::GetZoomOfPreset(), anonymous_namespace{ViewMenus.cpp}::GetZoomOfSelection(), TrackPanel::HandlePageDownKey(), TrackPanel::HandlePageUpKey(), anonymous_namespace{TracksPrefs.cpp}::Handler::Handler(), InitProjectWindow(), LabelTrackView::KeyDown(), TrackPanel::MakeParentRedrawScrollbars(), anonymous_namespace{SelectMenus.cpp}::MoveWhenAudioInactive(), ApplyMacroDialog::OnApplyToFiles(), MixerTrackCluster::OnButton_Mute(), MixerTrackCluster::OnButton_Solo(), ProjectManager::OnCloseWindow(), anonymous_namespace{ViewMenus.cpp}::OnCollapseAllTracks(), SelectActions::Handler::OnCursorSelEnd(), SelectActions::Handler::OnCursorSelStart(), SelectActions::Handler::OnCursorTrackEnd(), SelectActions::Handler::OnCursorTrackStart(), AudacityApp::OnExceptionInMainLoop(), anonymous_namespace{ViewMenus.cpp}::OnExpandAllTracks(), ControlToolBar::OnFF(), NavigationActions::Handler::OnFirstTrack(), anonymous_namespace{ViewMenus.cpp}::OnGoSelEnd(), anonymous_namespace{ViewMenus.cpp}::OnGoSelStart(), anonymous_namespace{FileMenus.cpp}::OnImportLabels(), NavigationActions::Handler::OnLastTrack(), TrackPanel::OnMouseEvent(), anonymous_namespace{LabelMenus.cpp}::OnNewLabelTrack(), anonymous_namespace{WaveTrackMenuItems.cpp}::OnNewStereoTrack(), anonymous_namespace{TimeTrackMenuItems.cpp}::OnNewTimeTrack(), anonymous_namespace{WaveTrackMenuItems.cpp}::OnNewWaveTrack(), anonymous_namespace{EditMenus.cpp}::OnPaste(), anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel(), CommandHandler::OnReceiveCommand(), anonymous_namespace{EditMenus.cpp}::OnRedo(), anonymous_namespace{TrackMenus.cpp}::OnResample(), anonymous_namespace{PluginMenus.cpp}::OnResetConfig(), ControlToolBar::OnRewind(), ProjectWindow::OnScroll(), ProjectWindow::OnScrollLeftButton(), ProjectWindow::OnScrollRightButton(), LabelDialog::OnSelectCell(), SelectActions::Handler::OnSelectionRestore(), SelectActions::Handler::OnSelToEnd(), SelectActions::Handler::OnSelToStart(), ProjectWindow::OnSize(), PlayIndicatorOverlay::OnTimer(), SelectHandle::TimerHandler::OnTimer(), TrackPanel::OnTimer(), NavigationActions::Handler::OnToggle(), ProjectWindow::OnToolBarUpdate(), ToolsToolBar::OnToolChanged(), anonymous_namespace{EditMenus.cpp}::OnUndo(), anonymous_namespace{ViewMenus.cpp}::OnZoomFit(), anonymous_namespace{ViewMenus.cpp}::OnZoomFitV(), anonymous_namespace{ViewMenus.cpp}::OnZoomIn(), anonymous_namespace{ViewMenus.cpp}::OnZoomNormal(), anonymous_namespace{ViewMenus.cpp}::OnZoomOut(), anonymous_namespace{ViewMenus.cpp}::OnZoomSel(), anonymous_namespace{ViewMenus.cpp}::OnZoomToggle(), ProjectFileManager::OpenFile(), ProjectManager::OpenProject(), ProjectFileManager::OpenProjectFile(), TrackPanel::ProcessUIHandleResult(), ProjectWindow::ProjectWindow(), anonymous_namespace{SelectMenus.cpp}::SeekWhenAudioInactive(), TrackPanel::TrackPanel(), and TrackPanel::UpdateViewIfNoTracks().

◆ Get() [2/2]

const Viewport & Viewport::Get ( const AudacityProject project)
static

Definition at line 38 of file Viewport.cpp.

39{
40 return Get(const_cast<AudacityProject &>(project));
41}
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 Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33

References Get(), and project.

Here is the call graph for this function:

◆ GetZoomOfToFit()

double Viewport::GetZoomOfToFit ( ) const

Find pixels-per-second that would fit all tracks on the timeline.

Definition at line 669 of file Viewport.cpp.

670{
671 auto &project = mProject;
673 auto &viewInfo = ViewInfo::Get(project);
674
675 const double end = tracks.GetEndTime();
676 const double start = 0;
677 const double len = end - start;
678
679 if (len <= 0.0)
680 return viewInfo.GetZoom();
681
682 auto w = viewInfo.GetTracksUsableWidth();
683 w -= 10;
684 return w/len;
685}
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References details::end(), ViewInfo::Get(), TrackList::Get(), mProject, project, and tracks.

Referenced by ZoomFitHorizontally().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleResize()

void Viewport::HandleResize ( )

Definition at line 393 of file Viewport.cpp.

394{
395 BasicUI::CallAfter( [wthis = weak_from_this()]{
396 if (auto This = wthis.lock()) {
397 This->UpdateScrollbarsForTracks();
398 This->Publish({ false, false, true });
399 }
400 });
401}
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214

References BasicUI::CallAfter().

Referenced by ProjectWindow::OnSize(), ProjectWindow::OnToolBarUpdate(), OnUndoRedo(), OnUndoReset(), TrackPanel::ProcessUIHandleResult(), and TrackPanel::UpdateViewIfNoTracks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnScroll()

void Viewport::OnScroll ( )

Definition at line 403 of file Viewport.cpp.

404{
405 auto &project = mProject;
406 auto &viewInfo = ViewInfo::Get( project );
407 const wxInt64 offset = PixelWidthBeforeTime(0.0);
408 const auto pos = mpCallbacks ? mpCallbacks->GetHorizontalThumbPosition() : 0;
409 sbarH = static_cast<wxInt64>(pos / sbarScale) - offset;
410 DoScroll();
411
412#ifndef __WXMAC__
413 // Bug2179
414 // This keeps the time ruler in sync with horizontal scrolling, without
415 // making an undesirable compilation dependency of this source file on
416 // the ruler
418#endif
419}
double sbarScale
Definition: Viewport.h:209
double PixelWidthBeforeTime(double scrollto) const
Definition: Viewport.cpp:191
void Yield()
Dispatch waiting events, including actions enqueued by CallAfter.
Definition: BasicUI.cpp:225

References DoScroll(), ViewInfo::Get(), mpCallbacks, mProject, PixelWidthBeforeTime(), project, sbarH, sbarScale, and BasicUI::Yield().

Referenced by ProjectWindow::OnScroll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnScrollLeft()

void Viewport::OnScrollLeft ( )

This method handles general left-scrolling, either for drag-scrolling or when the scrollbar is clicked to the left of the thumb

Definition at line 104 of file Viewport.cpp.

105{
106 auto &project = mProject;
107 wxInt64 pos = mpCallbacks ? mpCallbacks->GetHorizontalThumbPosition() : 0;
108 const auto prevPos = pos;
109 // move at least one scroll increment
110 pos -= std::max<wxInt64>((sbarHjump * sbarScale), 1);
111 pos = std::max<wxInt64>(pos, 0);
112 sbarH -= sbarHjump;
113 sbarH = std::max<wxInt64>(sbarH, -PixelWidthBeforeTime(0.0));
114
115 if (mpCallbacks && pos != prevPos) {
116 mpCallbacks->SetHorizontalThumbPosition(static_cast<int>(pos));
118 }
119}
const int sbarHjump
Definition: Viewport.cpp:81
void FinishAutoScroll()
Definition: Viewport.cpp:69

References FinishAutoScroll(), mpCallbacks, mProject, PixelWidthBeforeTime(), project, sbarH, sbarHjump, and sbarScale.

Here is the call graph for this function:

◆ OnScrollLeftButton()

void Viewport::OnScrollLeftButton ( )

This handles the event when the left direction button on the scrollbar is depressed

Definition at line 144 of file Viewport.cpp.

145{
146 auto &project = mProject;
147 wxInt64 pos = mpCallbacks ? mpCallbacks->GetHorizontalThumbPosition() : 0;
148 const auto prevPos = pos;
149 // move at least one scroll increment
150 pos -= std::max<wxInt64>((sbarHjump * sbarScale), 1);
151 pos = std::max<wxInt64>(pos, 0);
152 sbarH -= sbarHjump;
153 sbarH = std::max<wxInt64>(sbarH, -PixelWidthBeforeTime(0.0));
154
155 if (mpCallbacks && pos != prevPos) {
156 mpCallbacks->SetHorizontalThumbPosition(static_cast<int>(pos));
157 DoScroll();
158 }
159}

References DoScroll(), mpCallbacks, mProject, PixelWidthBeforeTime(), project, sbarH, sbarHjump, and sbarScale.

Referenced by ProjectWindow::OnScrollLeftButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnScrollRight()

void Viewport::OnScrollRight ( )

This method handles general right-scrolling, either for drag-scrolling or when the scrollbar is clicked to the right of the thumb

Definition at line 121 of file Viewport.cpp.

122{
123 auto &project = mProject;
124 wxInt64 pos = mpCallbacks ? mpCallbacks->GetHorizontalThumbPosition() : 0;
125 const auto prevPos = pos;
126 // move at least one scroll increment
127 // use wxInt64 for calculation to prevent temporary overflow
128 pos += std::max<wxInt64>((sbarHjump * sbarScale), 1);
129 wxInt64 max = mpCallbacks
130 ? mpCallbacks->GetHorizontalRange()
131 - mpCallbacks->GetHorizontalThumbSize()
132 : 0;
133 pos = std::min(pos, max);
134 sbarH += sbarHjump;
135 sbarH = std::min<wxInt64>(sbarH,
137
138 if (mpCallbacks && pos != prevPos) {
139 mpCallbacks->SetHorizontalThumbPosition(static_cast<int>(pos));
141 }
142}
int min(int a, int b)
wxInt64 sbarTotal
Definition: Viewport.h:203
wxInt64 sbarScreen
Definition: Viewport.h:202

References FinishAutoScroll(), min(), mpCallbacks, mProject, PixelWidthBeforeTime(), project, sbarH, sbarHjump, sbarScale, sbarScreen, and sbarTotal.

Here is the call graph for this function:

◆ OnScrollRightButton()

void Viewport::OnScrollRightButton ( )

This handles the event when the right direction button on the scrollbar is depressed

Definition at line 161 of file Viewport.cpp.

162{
163 auto &project = mProject;
164 wxInt64 pos = mpCallbacks ? mpCallbacks->GetHorizontalThumbPosition() : 0;
165 const auto prevPos = pos;
166 // move at least one scroll increment
167 // use wxInt64 for calculation to prevent temporary overflow
168 pos += std::max<wxInt64>((sbarHjump * sbarScale), 1);
169 wxInt64 max = mpCallbacks
170 ? mpCallbacks->GetHorizontalRange()
171 - mpCallbacks->GetHorizontalThumbSize()
172 : 0;
173 pos = std::min(pos, max);
174 sbarH += sbarHjump;
175 sbarH = std::min<wxInt64>(sbarH,
177
178 if (mpCallbacks && pos != prevPos) {
179 mpCallbacks->SetHorizontalThumbPosition(static_cast<int>(pos));
180 DoScroll();
181 }
182}

References DoScroll(), min(), mpCallbacks, mProject, PixelWidthBeforeTime(), project, sbarH, sbarHjump, sbarScale, sbarScreen, and sbarTotal.

Referenced by ProjectWindow::OnScrollRightButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnUndoPushedModified()

void Viewport::OnUndoPushedModified ( )
private

Definition at line 771 of file Viewport.cpp.

772{
773 Redraw();
774}

References Redraw().

Here is the call graph for this function:

◆ OnUndoRedo()

void Viewport::OnUndoRedo ( )
private

Definition at line 776 of file Viewport.cpp.

777{
778 HandleResize();
779 Redraw();
780}
void HandleResize()
Definition: Viewport.cpp:393

References HandleResize(), and Redraw().

Here is the call graph for this function:

◆ OnUndoReset()

void Viewport::OnUndoReset ( )
private

Definition at line 782 of file Viewport.cpp.

783{
784 HandleResize();
785 // Redraw(); // Should we do this here too?
786}

References HandleResize().

Here is the call graph for this function:

◆ PixelWidthBeforeTime()

double Viewport::PixelWidthBeforeTime ( double  scrollto) const
private

Definition at line 191 of file Viewport.cpp.

192{
193 auto &project = mProject;
194 auto &viewInfo = ViewInfo::Get( project );
195 const double lowerBound = ScrollingLowerBoundTime();
196 return
197 // Ignoring fisheye is correct here
198 viewInfo.TimeRangeToPixelWidth(scrollto - lowerBound);
199}

References ViewInfo::Get(), mProject, project, and ScrollingLowerBoundTime().

Referenced by OnScroll(), OnScrollLeft(), OnScrollLeftButton(), OnScrollRight(), OnScrollRightButton(), SetHorizontalThumb(), and UpdateScrollbarsForTracks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Redraw()

void Viewport::Redraw ( )

Definition at line 753 of file Viewport.cpp.

754{
755 // Delay it until after channel views update their Y coordinates in response
756 // to TrackList mesages
757 BasicUI::CallAfter([wthis = weak_from_this()]{
758 if (auto This = wthis.lock()) {
759 This->UpdateScrollbarsForTracks();
760 This->Publish({ true, false, false });
761 }
762 });
763}

References BasicUI::CallAfter().

Referenced by CommandDispatch::DoAudacityCommand(), MixerTrackCluster::OnButton_Mute(), MixerTrackCluster::OnButton_Solo(), AudacityApp::OnExceptionInMainLoop(), CommandHandler::OnReceiveCommand(), LabelDialog::OnSelectCell(), ToolsToolBar::OnToolChanged(), OnUndoPushedModified(), OnUndoRedo(), and Viewport().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReinitScrollbars()

void Viewport::ReinitScrollbars ( )
inline

Definition at line 172 of file Viewport.h.

172{ mbInitializingScrollbar = true; }
bool mbInitializingScrollbar
Definition: Viewport.h:215

Referenced by ProjectFileManager::OpenProjectFile().

Here is the caller graph for this function:

◆ ScrollingLowerBoundTime()

double Viewport::ScrollingLowerBoundTime ( ) const

Definition at line 184 of file Viewport.cpp.

185{
186 return 0;
187}

Referenced by DoScroll(), PixelWidthBeforeTime(), and UpdateScrollbarsForTracks().

Here is the caller graph for this function:

◆ ScrollIntoView() [1/2]

void Viewport::ScrollIntoView ( double  pos)

Center view horizontally at the given time, if it was not in bounds.

Definition at line 84 of file Viewport.cpp.

85{
86 auto &project = mProject;
87 auto &viewInfo = ViewInfo::Get( project );
88 auto w = viewInfo.GetTracksUsableWidth();
89
90 int pixel = viewInfo.TimeToPosition(pos);
91 if (pixel < 0 || pixel >= w) {
92 SetHorizontalThumb(viewInfo.OffsetTimeByPixels(pos, -(w / 2)));
93 Publish({ true, false, false });
94 }
95}
void SetHorizontalThumb(double scrollto, bool doScroll=true)
Definition: Viewport.cpp:201

References ViewInfo::Get(), mProject, project, Observer::Publisher< ViewportMessage >::Publish(), and SetHorizontalThumb().

Referenced by LabelTrackView::DoKeyDown(), LabelTrackView::KeyDown(), ScrollIntoView(), and ScrollToEnd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScrollIntoView() [2/2]

void Viewport::ScrollIntoView ( int  x)

Center the view horizontally at the given pixel position relative to the left edge, if it was not in bounds

Definition at line 97 of file Viewport.cpp.

98{
99 auto &project = mProject;
100 auto &viewInfo = ViewInfo::Get( project );
101 ScrollIntoView(viewInfo.PositionToTime(x, viewInfo.GetLeftOffset()));
102}
void ScrollIntoView(double pos)
Center view horizontally at the given time, if it was not in bounds.
Definition: Viewport.cpp:84

References ViewInfo::Get(), mProject, project, and ScrollIntoView().

Here is the call graph for this function:

◆ ScrollToBottom()

void Viewport::ScrollToBottom ( )

Definition at line 556 of file Viewport.cpp.

557{
558 auto &project = mProject;
560 auto &viewInfo = ViewInfo::Get(project);
561
562 auto range = tracks.Any();
563 int trackHeight = 0;
564 const auto getHeight = [this](auto pTrack){
565 return mpCallbacks ? mpCallbacks->GetTrackHeight(*pTrack) : 0;
566 };
567 if (!range.empty()) {
568 trackHeight = getHeight(*range.rbegin());
569 --range.second;
570 }
571 int trackTop =
572 range.sum(getHeight);
573 const auto size =
574 mpCallbacks ? mpCallbacks->ViewportSize() : std::pair{ 1, 1 };
575 const auto [width, height] = size;
576 const auto step = scrollStep;
577 const int delta = ((trackTop + trackHeight - height) - viewInfo.vpos
578 + step) / step;
579 ScrollUpDown(delta);
580 Publish({ true, false, false });
581}
bool ScrollUpDown(int delta)
Definition: Viewport.cpp:221

References ViewInfo::Get(), TrackList::Get(), mpCallbacks, mProject, project, Observer::Publisher< ViewportMessage >::Publish(), scrollStep, ScrollUpDown(), size, and tracks.

Here is the call graph for this function:

◆ ScrollToEnd()

void Viewport::ScrollToEnd ( bool  extend)

This method 'fast-forwards' the track, by setting the cursor to the end of the samples on the selected track and scrolling the window to fit the end on its right side (maintaining current zoom). If extend is true, it will extend the right edge of the selection to the end (holding left edge constant), otherwise it will move both left and right edge of selection to the end

Definition at line 541 of file Viewport.cpp.

542{
543 auto &project = mProject;
545 auto &viewInfo = ViewInfo::Get(project);
546 double len = tracks.GetEndTime();
547
548 viewInfo.selectedRegion.setT1(len, false);
549 if (!extend)
550 viewInfo.selectedRegion.setT0(len);
551
552 // Make sure the end of the track is visible
553 ScrollIntoView(len);
554}

References ViewInfo::Get(), TrackList::Get(), mProject, project, ScrollIntoView(), and tracks.

Referenced by ControlToolBar::OnFF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScrollToStart()

void Viewport::ScrollToStart ( bool  extend)

This method 'rewinds' the track, by setting the cursor to 0 and scrolling the window to fit 0 on the left side of it (maintaining current zoom). If extend is true, it will extend the left edge of the selection to 0 (holding right edge constant), otherwise it will move both left and right edge of selection to 0

Definition at line 523 of file Viewport.cpp.

524{
525 auto &project = mProject;
526 auto &viewInfo = ViewInfo::Get( project );
527 viewInfo.selectedRegion.setT0(0, false);
528 if (!extend)
529 viewInfo.selectedRegion.setT1(0);
530
532}

References ViewInfo::Get(), mProject, project, and SetHorizontalThumb().

Referenced by ControlToolBar::OnRewind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScrollToTop()

void Viewport::ScrollToTop ( )

Definition at line 534 of file Viewport.cpp.

535{
536 if (mpCallbacks)
537 mpCallbacks->SetVerticalThumbPosition(0);
538}

References mpCallbacks.

Referenced by ZoomFitVertically().

Here is the caller graph for this function:

◆ ScrollUpDown()

bool Viewport::ScrollUpDown ( int  delta)

Definition at line 221 of file Viewport.cpp.

222{
223 int oldPos = mpCallbacks ? mpCallbacks->GetVerticalThumbPosition() : 0;
224 int pos = oldPos + delta;
225 int max = mpCallbacks
226 ? mpCallbacks->GetVerticalRange() - mpCallbacks->GetVerticalThumbSize()
227 : 0;
228
229 // Can be negative in case of only one track
230 if (max < 0)
231 max = 0;
232
233 if (pos > max)
234 pos = max;
235 else if (pos < 0)
236 pos = 0;
237
238 if (pos != oldPos)
239 {
240 if (mpCallbacks)
241 mpCallbacks->SetVerticalThumbPosition(pos);
242
243 DoScroll();
244 return true;
245 }
246 else
247 return false;
248}

References DoScroll(), and mpCallbacks.

Referenced by ScrollToBottom(), and ShowTrack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCallbacks()

void Viewport::SetCallbacks ( std::unique_ptr< ViewportCallbacks pCallbacks)

Definition at line 64 of file Viewport.cpp.

65{
66 mpCallbacks = move(pCallbacks);
67}

References mpCallbacks.

Referenced by ProjectWindow::ProjectWindow().

Here is the caller graph for this function:

◆ SetHorizontalThumb()

void Viewport::SetHorizontalThumb ( double  scrollto,
bool  doScroll = true 
)

Definition at line 201 of file Viewport.cpp.

202{
203 if (!mpCallbacks)
204 return;
205 auto &project = mProject;
206 const auto unscaled = PixelWidthBeforeTime(scrollto);
207 const int max = std::max(
208 0, mpCallbacks->GetHorizontalRange() -
209 mpCallbacks->GetHorizontalThumbSize());
210 const int pos = std::clamp<int>(floor(0.5 + unscaled * sbarScale), 0, max);
211 mpCallbacks->SetHorizontalThumbPosition(pos);
212 sbarH = floor(0.5 + unscaled - PixelWidthBeforeTime(0.0));
213 sbarH = std::clamp<wxInt64>(
215 std::max(sbarTotal - PixelWidthBeforeTime(0.0) - sbarScreen, 0.));
216
217 if (doScroll)
218 DoScroll();
219}

References DoScroll(), mpCallbacks, mProject, PixelWidthBeforeTime(), project, sbarH, sbarScale, sbarScreen, and sbarTotal.

Referenced by LOFImportFileHandle::doDurationAndScrollOffset(), TrackPanel::HandlePageDownKey(), TrackPanel::HandlePageUpKey(), ScrollIntoView(), ScrollToStart(), Zoom(), ZoomAboutCenter(), ZoomAboutSelection(), and ZoomFitHorizontally().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetToDefaultSize()

void Viewport::SetToDefaultSize ( )

Send a message to the main window PARENT of the viewport, to resize.

Definition at line 765 of file Viewport.cpp.

766{
767 if (mpCallbacks)
768 mpCallbacks->SetToDefaultSize();
769}

References mpCallbacks.

Referenced by anonymous_namespace{PluginMenus.cpp}::OnResetConfig().

Here is the caller graph for this function:

◆ ShowTrack()

void Viewport::ShowTrack ( const Track track)

Definition at line 460 of file Viewport.cpp.

461{
462 auto &viewInfo = ViewInfo::Get(mProject);
463
464 int trackTop = 0;
465 int trackHeight = 0;
466 for (auto it : TrackList::Get(mProject)) {
467 trackTop += trackHeight;
468 trackHeight = mpCallbacks ? mpCallbacks->GetTrackHeight(*it) : 0;
469
470 if (it == &track) {
471 //We have found the track we want to ensure is visible.
472
473 //Get the size of the trackpanel.
474 const auto size =
475 mpCallbacks ? mpCallbacks->ViewportSize() : std::pair{ 1, 1 };
476 auto [width, height] = size;
477
478 if (trackTop < viewInfo.vpos) {
479 height = viewInfo.vpos - trackTop + scrollStep;
480 height /= scrollStep;
481 ScrollUpDown(-height);
482 }
483 else if (trackTop + trackHeight > viewInfo.vpos + height) {
484 height = (trackTop + trackHeight) - (viewInfo.vpos + height);
485 height = (height + scrollStep + 1) / scrollStep;
486 ScrollUpDown(height);
487 }
488
489 break;
490 }
491 }
492
493 Publish({ true, false, false });
494}

References ViewInfo::Get(), TrackList::Get(), mpCallbacks, mProject, Observer::Publisher< ViewportMessage >::Publish(), scrollStep, ScrollUpDown(), and size.

Referenced by anonymous_namespace{LabelMenus.cpp}::DoAddLabel(), EffectUI::DoEffect(), anonymous_namespace{TrackMenus.cpp}::DoMixAndRender(), anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected(), TrackUtilities::DoRemoveTracks(), TrackPanel::OnMouseEvent(), anonymous_namespace{LabelMenus.cpp}::OnNewLabelTrack(), anonymous_namespace{WaveTrackMenuItems.cpp}::OnNewStereoTrack(), anonymous_namespace{TimeTrackMenuItems.cpp}::OnNewTimeTrack(), anonymous_namespace{WaveTrackMenuItems.cpp}::OnNewWaveTrack(), anonymous_namespace{EditMenus.cpp}::OnPaste(), anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel(), anonymous_namespace{EditMenus.cpp}::OnRedo(), anonymous_namespace{EditMenus.cpp}::OnUndo(), TrackPanel::ProcessUIHandleResult(), and ZoomFitHorizontallyAndShowTrack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateScrollbarsForTracks()

void Viewport::UpdateScrollbarsForTracks ( )

Change scrollbar bounds in response to changes in the TrackList, and sometimes rescroll to the top or left and repaint the whole view

Definition at line 250 of file Viewport.cpp.

251{
252 auto &project = mProject;
253 auto &tracks = TrackList::Get( project );
254 auto &viewInfo = ViewInfo::Get( project );
255
256 // To decide whether to repaint the view
257 bool refresh = false;
258 bool rescroll = false;
259
260 // Gather inputs
261 const int totalHeight =
262 (mpCallbacks ? mpCallbacks->GetTotalHeight(tracks) : 0) + 32;
263
264 // (From Debian...at least I think this is the change corresponding
265 // to this comment)
266 //
267 // (2.) GTK critical warning "IA__gtk_range_set_range: assertion
268 // 'min < max' failed" because of negative numbers as result of window
269 // size checking. Added a sanity check that straightens up the numbers
270 // in edge cases.
271 const auto panelWidth = std::max(0, viewInfo.GetTracksUsableWidth());
272 const auto panelHeight = std::max(0, viewInfo.GetHeight());
273
274 // Whether scrollbars are visible now
275 const bool oldhstate = (viewInfo.GetScreenEndTime() - viewInfo.hpos) < total;
276 const bool oldvstate = panelHeight < totalHeight;
277
278 auto &pendingTracks = PendingTracks::Get(mProject);
279 const auto LastTime = std::accumulate(tracks.begin(), tracks.end(),
280 viewInfo.selectedRegion.t1(),
281 [&pendingTracks](double acc, const Track *track){
282 // Iterate over pending changed tracks if present.
283 track = &pendingTracks.SubstitutePendingChangedTrack(*track);
284 return std::max(acc, track->GetEndTime());
285 });
286
287 const double screen = viewInfo.GetScreenEndTime() - viewInfo.hpos;
288 const double halfScreen = screen / 2.0;
289
290 const double lowerBound = ScrollingLowerBoundTime();
291 const double additional = screen / 4.0;
292
293 total = LastTime + additional;
294
295 // Don't remove time from total that's still on the screen
296 total = std::max(total, viewInfo.hpos + screen);
297
298 // Scroll the view later if needed to respect the lower bound
299 if (viewInfo.hpos < lowerBound) {
300 viewInfo.hpos = lowerBound;
301 rescroll = true;
302 }
303
304 // To compute new horizontal scrollbar settings
305 sbarTotal = static_cast<wxInt64>(total * viewInfo.GetZoom());
306 sbarScreen = static_cast<wxInt64>(panelWidth);
307 sbarH = static_cast<wxInt64>(viewInfo.GetBeforeScreenWidth());
308
309 // PRL: Can someone else find a more elegant solution to bug 812, than
310 // introducing this boolean member variable?
311 // Setting mVSbar earlier, in HandlXMLTag, didn't succeed in restoring
312 // the vertical scrollbar to its saved position. So defer that till now.
313 // mbInitializingScrollbar should be true only at the start of the life
314 // of an AudacityProject reopened from disk.
316 viewInfo.vpos =
317 (mpCallbacks ? mpCallbacks->GetVerticalThumbPosition() : 0)
318 * scrollStep;
320
321 // Constrain new top of visible area
322 viewInfo.vpos = std::clamp(viewInfo.vpos, 0, totalHeight - 1);
323
324 // Decide whether the tracks are large enough to scroll for the zoom level
325 // and heights
326 bool newhstate =
327 (viewInfo.GetScreenEndTime() - viewInfo.hpos) < total;
328 bool newvstate = panelHeight < totalHeight;
329
330 /* Leo: This has been broken forever (2.0.0/Win11)
331 and causes the bars to not show on Lin since 3.2. #2937 */
332 // Hide scrollbar thumbs and buttons if not scrollable
333 // if (mpCallbacks) {
334 // mpCallbacks->ShowHorizontalScrollbar(newhstate);
335 // mpCallbacks->ShowVerticalScrollbar(newvstate);
336 // }
337
338 // When not scrollable in either axis, align viewport to top or left and
339 // repaint it later
340 if (!newvstate && viewInfo.vpos != 0) {
341 viewInfo.vpos = 0;
342
343 refresh = true;
344 rescroll = false;
345 }
346 if (!newhstate && sbarH != 0) {
347 sbarH = 0;
348
349 refresh = true;
350 rescroll = false;
351 }
352
353 // wxScrollbar only supports int values but we need a greater range, so
354 // we scale the scrollbar coordinates on demand. We only do this if we
355 // would exceed the int range, so we can always use the maximum resolution
356 // available.
357
358 // Don't use the full 2^31 max int range but a bit less, so rounding
359 // errors in calculations do not overflow max int
360 wxInt64 maxScrollbarRange = (wxInt64)(2147483647 * 0.999);
361 if (sbarTotal > maxScrollbarRange)
362 sbarScale = (static_cast<double>(maxScrollbarRange)) / sbarTotal;
363 else
364 sbarScale = 1.0; // use maximum resolution
365
366 {
367 auto scaledSbarH = static_cast<int>(sbarH * sbarScale);
368 auto scaledSbarScreen = static_cast<int>(sbarScreen * sbarScale);
369 auto scaledSbarTotal = static_cast<int>(sbarTotal * sbarScale);
370 const auto offset =
371 static_cast<int>(floor(0.5 + sbarScale * PixelWidthBeforeTime(0.0)));
372
373 if (mpCallbacks)
374 mpCallbacks->SetHorizontalScrollbar(
375 scaledSbarH + offset, scaledSbarScreen, scaledSbarTotal,
376 scaledSbarScreen, true);
377 }
378
379 if (mpCallbacks)
380 mpCallbacks->SetVerticalScrollbar(viewInfo.vpos / scrollStep,
381 panelHeight / scrollStep,
382 totalHeight / scrollStep,
383 panelHeight / scrollStep, true);
384
385 //Leo: this needs to be rescroll = rescroll && (...
386 //if scrollbar hiding is to be reimplemented.
387 //Or maybe not. It's all broken anyway. #2937
388 rescroll = (viewInfo.GetScreenEndTime() - viewInfo.hpos) < total;
389 Publish({ (refresh || rescroll),
390 (oldhstate != newhstate || oldvstate != newvstate), false });
391}
static PendingTracks & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110

References ViewInfo::Get(), PendingTracks::Get(), TrackList::Get(), mbInitializingScrollbar, mpCallbacks, mProject, PixelWidthBeforeTime(), project, Observer::Publisher< ViewportMessage >::Publish(), sbarH, sbarScale, sbarScreen, sbarTotal, ScrollingLowerBoundTime(), scrollStep, total, and tracks.

Referenced by TrackPanel::MakeParentRedrawScrollbars(), Zoom(), and ZoomBy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Zoom()

void Viewport::Zoom ( double  pixelsPerSecond)

Set timeline magnification; unchanged left edge time.

Definition at line 497 of file Viewport.cpp.

498{
499 auto &project = mProject;
500 auto &viewInfo = ViewInfo::Get( project );
501 viewInfo.SetZoom(pixelsPerSecond);
503 // See if we can center the selection on screen, and have it actually fit.
504 // tOnLeft is the amount of time we would need before the selection left edge to center it.
505 float t0 = viewInfo.selectedRegion.t0();
506 float t1 = viewInfo.selectedRegion.t1();
507 float tAvailable = viewInfo.GetScreenEndTime() - viewInfo.hpos;
508 float tOnLeft = (tAvailable - t0 + t1)/2.0;
509 // Bug 1292 (Enh) is effectively a request to do this scrolling of the selection into view.
510 // If tOnLeft is positive, then we have room for the selection, so scroll to it.
511 if (tOnLeft >= 0)
512 SetHorizontalThumb(t0 - tOnLeft);
513}
void UpdateScrollbarsForTracks()
Definition: Viewport.cpp:250

References ViewInfo::Get(), mProject, project, SetHorizontalThumb(), and UpdateScrollbarsForTracks().

Referenced by ZoomFitHorizontally().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZoomAboutCenter()

void Viewport::ZoomAboutCenter ( double  multiplier)

Multiply timeline magnification, conserving the midpoint time if possible.

Definition at line 652 of file Viewport.cpp.

653{
654 auto &project = mProject;
655 auto &viewInfo = ViewInfo::Get( project );
656
657 //Zoom() may change these, so record original values:
658 const double origLeft = viewInfo.hpos;
659 const double origWidth = viewInfo.GetScreenEndTime() - origLeft;
660
661 ZoomBy(multiplier);
662 const double newWidth = viewInfo.GetScreenEndTime() - viewInfo.hpos;
663
664 const double newh = origLeft + (origWidth - newWidth) / 2;
665 // newh = (newh > 0) ? newh : 0;
666 SetHorizontalThumb(newh);
667}
void ZoomBy(double multiplier)
Multiply the magnification; unchanged left edge time.
Definition: Viewport.cpp:515

References ViewInfo::Get(), mProject, project, SetHorizontalThumb(), and ZoomBy().

Here is the call graph for this function:

◆ ZoomAboutSelection()

void Viewport::ZoomAboutSelection ( double  multiplier)

Multiply timeline magnification, conserving a selected portion that incompletely fills the width, if possible; else like ZoomAboutCenter

Definition at line 583 of file Viewport.cpp.

584{
585 auto &project = mProject;
586 auto &viewInfo = ViewInfo::Get( project );
587
588 // DMM: Here's my attempt to get logical zooming behavior
589 // when there's a selection that's currently at least
590 // partially on-screen
591
592 const double endTime = viewInfo.GetScreenEndTime();
593 const double duration = endTime - viewInfo.hpos;
594
595 bool selectionIsOnscreen =
596 (viewInfo.selectedRegion.t0() < endTime) &&
597 (viewInfo.selectedRegion.t1() >= viewInfo.hpos);
598
599 bool selectionFillsScreen =
600 (viewInfo.selectedRegion.t0() < viewInfo.hpos) &&
601 (viewInfo.selectedRegion.t1() > endTime);
602
603 if (selectionIsOnscreen && !selectionFillsScreen) {
604 // Start with the center of the selection
605 double selCenter = (viewInfo.selectedRegion.t0() +
606 viewInfo.selectedRegion.t1()) / 2;
607
608 // If the selection center is off-screen, pick the
609 // center of the part that is on-screen.
610 if (selCenter < viewInfo.hpos)
611 selCenter = viewInfo.hpos +
612 (viewInfo.selectedRegion.t1() - viewInfo.hpos) / 2;
613 if (selCenter > endTime)
614 selCenter = endTime -
615 (endTime - viewInfo.selectedRegion.t0()) / 2;
616
617 // Zoom in
618 ZoomBy(multiplier);
619 const double newDuration =
620 viewInfo.GetScreenEndTime() - viewInfo.hpos;
621
622 // Recenter on selCenter
623 SetHorizontalThumb(selCenter - newDuration / 2);
624 return;
625 }
626
627
628 double origLeft = viewInfo.hpos;
629 double origWidth = duration;
630 ZoomBy(multiplier);
631
632 const double newDuration =
633 viewInfo.GetScreenEndTime() - viewInfo.hpos;
634 double newh = origLeft + (origWidth - newDuration) / 2;
635
636 // MM: Commented this out because it was confusing users
637 /*
638 // make sure that the *right-hand* end of the selection is
639 // no further *left* than 1/3 of the way across the screen
640 if (viewInfo.selectedRegion.t1() < newh + viewInfo.screen / 3)
641 newh = viewInfo.selectedRegion.t1() - viewInfo.screen / 3;
642
643 // make sure that the *left-hand* end of the selection is
644 // no further *right* than 2/3 of the way across the screen
645 if (viewInfo.selectedRegion.t0() > newh + viewInfo.screen * 2 / 3)
646 newh = viewInfo.selectedRegion.t0() - viewInfo.screen * 2 / 3;
647 */
648
649 SetHorizontalThumb(newh);
650}

References ViewInfo::Get(), mProject, project, SetHorizontalThumb(), and ZoomBy().

Here is the call graph for this function:

◆ ZoomBy()

void Viewport::ZoomBy ( double  multiplier)

Multiply the magnification; unchanged left edge time.

Definition at line 515 of file Viewport.cpp.

516{
517 auto &project = mProject;
518 auto &viewInfo = ViewInfo::Get( project );
519 viewInfo.ZoomBy(multiplier);
521}

References ViewInfo::Get(), mProject, project, and UpdateScrollbarsForTracks().

Referenced by LOFImportFileHandle::doDurationAndScrollOffset(), ZoomAboutCenter(), and ZoomAboutSelection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZoomFitHorizontally()

void Viewport::ZoomFitHorizontally ( )

Set horizontal zoom according to the extents of the tracks, and scroll to the start

Definition at line 687 of file Viewport.cpp.

688{
689 auto &project = mProject;
690 auto &viewInfo = ViewInfo::Get(project);
692
693 const double start = 0;
694
696 SetHorizontalThumb(start);
697}
void Zoom(double pixelsPerSecond)
Set timeline magnification; unchanged left edge time.
Definition: Viewport.cpp:497
double GetZoomOfToFit() const
Find pixels-per-second that would fit all tracks on the timeline.
Definition: Viewport.cpp:669

References ViewInfo::Get(), TrackList::Get(), GetZoomOfToFit(), mProject, project, SetHorizontalThumb(), tracks, and Zoom().

Referenced by ZoomFitHorizontallyAndShowTrack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZoomFitHorizontallyAndShowTrack()

void Viewport::ZoomFitHorizontallyAndShowTrack ( Track pTrack)

Fit horizontally; scroll vertically so that the given track (or if that's null, the first selected track, or if none such, the first track) is visible

Definition at line 443 of file Viewport.cpp.

444{
445 auto &project = mProject;
446 auto &tracks = TrackList::Get( project );
447
449
450 if (!pTrack)
451 pTrack = *tracks.Selected().begin();
452 if (!pTrack)
453 pTrack = *tracks.begin();
454 if (pTrack) {
455 TrackFocus::Get(project).Set(pTrack, true);
456 ShowTrack(*pTrack);
457 }
458}
Track * Get()
Definition: TrackFocus.cpp:156
void ShowTrack(const Track &track)
Definition: Viewport.cpp:460
void ZoomFitHorizontally()
Definition: Viewport.cpp:687

References TrackFocus::Get(), TrackList::Get(), mProject, project, ShowTrack(), tracks, and ZoomFitHorizontally().

Referenced by anonymous_namespace{ImportMIDI.cpp}::DoImportMIDI(), ApplyMacroDialog::OnApplyToFiles(), and ProjectFileManager::OpenFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZoomFitVertically()

void Viewport::ZoomFitVertically ( )

Give uncollapsed audio tracks equal height, fitting into the view if possible, and scroll to the top

Definition at line 699 of file Viewport.cpp.

700{
701 if (!mpCallbacks)
702 return;
703 auto &project = mProject;
704 auto &viewInfo = ViewInfo::Get(project);
706
707 // Only nonminimized audio tracks will be resized
708 // Assume all channels of the track have the same minimization state
709 auto range = tracks.Any<AudioTrack>()
710 - [this](const Track *pTrack){
711 return mpCallbacks->IsTrackMinimized(*pTrack); };
712 auto count = static_cast<int>(range.sum(&Track::NChannels));
713 if (count == 0)
714 return;
715
716 // Find total height to apportion
717 auto height = viewInfo.GetHeight();
718 height -= 28;
719
720 // The height of minimized and non-audio tracks cannot be apportioned
721 const auto fn = [this](const Track *pTrack){
722 return mpCallbacks->GetTrackHeight(*pTrack);
723 };
724 height -= tracks.Any().sum(fn) - range.sum(fn);
725 height /= count;
726 height = std::max<int>(mpCallbacks->MinimumTrackHeight(), height);
727 for (auto t : range)
728 mpCallbacks->SetChannelHeights(*t, height);
729
730 ScrollToTop();
731}
static const auto fn
Track subclass holding data representing sound (as notes, or samples, or ...)
Definition: PlayableTrack.h:21
virtual size_t NChannels() const =0
Report the number of channels.
void ScrollToTop()
Definition: Viewport.cpp:534

References fn, ViewInfo::Get(), TrackList::Get(), mpCallbacks, mProject, ChannelGroup::NChannels(), project, ScrollToTop(), and tracks.

Referenced by anonymous_namespace{TracksPrefs.cpp}::Handler::Handler().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAutoScrolling

bool Viewport::mAutoScrolling { false }
private

Definition at line 214 of file Viewport.h.

Referenced by DoScroll(), and FinishAutoScroll().

◆ mbInitializingScrollbar

bool Viewport::mbInitializingScrollbar { false }
private

Definition at line 215 of file Viewport.h.

Referenced by UpdateScrollbarsForTracks().

◆ mpCallbacks

std::unique_ptr<ViewportCallbacks> Viewport::mpCallbacks {}
private

◆ mProject

AudacityProject& Viewport::mProject
private

◆ mSnappingChangedSubscription

const Observer::Subscription Viewport::mSnappingChangedSubscription
private

Definition at line 194 of file Viewport.h.

◆ mUndoSubscription

const Observer::Subscription Viewport::mUndoSubscription
private

Definition at line 195 of file Viewport.h.

◆ sbarH

wxInt64 Viewport::sbarH { 0 }
private

◆ sbarScale

double Viewport::sbarScale { 1.0 }
private

◆ sbarScreen

wxInt64 Viewport::sbarScreen { 1 }
private

◆ sbarTotal

wxInt64 Viewport::sbarTotal { 1 }
private

◆ scrollStep

int Viewport::scrollStep { 16 }
private

Definition at line 212 of file Viewport.h.

Referenced by DoScroll(), ScrollToBottom(), ShowTrack(), and UpdateScrollbarsForTracks().

◆ total

double Viewport::total { 1.0 }
private

Definition at line 198 of file Viewport.h.

Referenced by DoScroll(), and UpdateScrollbarsForTracks().


The documentation for this class was generated from the following files: