Audacity  2.2.2
CommonTrackPanelCell.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 CommonTrackPanelCell.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../Audacity.h"
12 #include "CommonTrackPanelCell.h"
13 #include "Scrubbing.h"
14 
15 #include "../../Experimental.h"
16 #include "../../HitTestResult.h"
17 #include "../../Project.h"
18 #include "../../RefreshCode.h"
19 #include "../../Track.h"
20 #include "../../TrackPanel.h"
21 #include "../../TrackPanelMouseEvent.h"
22 
24 {
25 }
26 
28 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
29 {
30  using namespace RefreshCode;
31 
32  if (pProject->GetTracks()->empty())
33  // Scrolling and Zoom in and out commands are disabled when there are no tracks.
34  // This should be disabled too for consistency. Otherwise
35  // you do see changes in the time ruler.
36  return Cancelled;
37 
38  unsigned result = RefreshAll;
39  const wxMouseEvent &event = evt.event;
40  ViewInfo &viewInfo = pProject->GetViewInfo();
41  Scrubber &scrubber = pProject->GetScrubber();
42  const auto steps = evt.steps;
43 
44  if (event.ShiftDown()
45  // Don't pan during smooth scrolling. That would conflict with keeping
46  // the play indicator centered.
47  && !scrubber.IsScrollScrubbing()
48  )
49  {
50  // MM: Scroll left/right when used with Shift key down
51  pProject->TP_ScrollWindow(
52  viewInfo.OffsetTimeByPixels(
53  viewInfo.PositionToTime(0), 50.0 * -steps));
54  }
55  else if (event.CmdDown())
56  {
57 #if 0
58  // JKC: Alternative scroll wheel zooming code
59  // using AudacityProject zooming, which is smarter,
60  // it keeps selections on screen and centred if it can,
61  // also this ensures mousewheel and zoom buttons give same result.
62  double ZoomFactor = pow(2.0, steps);
63  AudacityProject *p = GetProject();
64  if( steps > 0 )
65  p->ZoomInByFactor( ZoomFactor );
66  else
67  p->ZoomOutByFactor( ZoomFactor );
68 #endif
69  // MM: Zoom in/out when used with Control key down
70  // We're converting pixel positions to times,
71  // counting pixels from the left edge of the track.
72  int trackLeftEdge = pProject->GetTrackPanel()->GetLeftOffset();
73 
74  // Time corresponding to mouse position
75  wxCoord xx;
76  double center_h;
77  double mouse_h = viewInfo.PositionToTime(event.m_x, trackLeftEdge);
78 
79  // Scrubbing? Expand or contract about the center, ignoring mouse position
80  if (scrubber.IsScrollScrubbing())
81  center_h = viewInfo.h + (pProject->GetScreenEndTime() - viewInfo.h) / 2.0;
82  // Zooming out? Focus on mouse.
83  else if( steps <= 0 )
84  center_h = mouse_h;
85  // No Selection? Focus on mouse.
86  else if((viewInfo.selectedRegion.t1() - viewInfo.selectedRegion.t0() ) < 0.00001 )
87  center_h = mouse_h;
88  // Before Selection? Focus on left
89  else if( mouse_h < viewInfo.selectedRegion.t0() )
90  center_h = viewInfo.selectedRegion.t0();
91  // After Selection? Focus on right
92  else if( mouse_h > viewInfo.selectedRegion.t1() )
93  center_h = viewInfo.selectedRegion.t1();
94  // Inside Selection? Focus on mouse
95  else
96  center_h = mouse_h;
97 
98  xx = viewInfo.TimeToPosition(center_h, trackLeftEdge);
99 
100  // Time corresponding to last (most far right) audio.
101  double audioEndTime = pProject->GetTracks()->GetEndTime();
102 
103 // Disabled this code to fix Bug 1923 (tricky to wheel-zoom right of waveform).
104 #if 0
105  // When zooming in in empty space, it's easy to 'lose' the waveform.
106  // This prevents it.
107  // IF zooming in
108  if (steps > 0)
109  {
110  // IF mouse is to right of audio
111  if (center_h > audioEndTime)
112  // Zooming brings far right of audio to mouse.
113  center_h = audioEndTime;
114  }
115 #endif
116 
117  wxCoord xTrackEnd = viewInfo.TimeToPosition( audioEndTime );
118  viewInfo.ZoomBy(pow(2.0, steps));
119 
120  double new_center_h = viewInfo.PositionToTime(xx, trackLeftEdge);
121  viewInfo.h += (center_h - new_center_h);
122 
123  // If wave has gone off screen, bring it back.
124  // This means that the end of the track stays where it was.
125  if( viewInfo.h > audioEndTime )
126  viewInfo.h += audioEndTime - viewInfo.PositionToTime( xTrackEnd );
127 
128 
129  result |= FixScrollbars;
130  }
131  else
132  {
133 #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
134  if (scrubber.IsScrubbing()) {
135  scrubber.HandleScrollWheel(steps);
136  evt.event.Skip(false);
137  }
138  else
139 #endif
140  {
141  // MM: Scroll up/down when used without modifier keys
142  double lines = steps * 4 + mVertScrollRemainder;
143  mVertScrollRemainder = lines - floor(lines);
144  lines = floor(lines);
145  auto didSomething = pProject->TP_ScrollUpDown((int)-lines);
146  if (!didSomething)
147  result |= Cancelled;
148  }
149  }
150 
151  return result;
152 }
unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
Scrubber & GetScrubber()
Definition: Project.h:801
void ZoomOutByFactor(double ZoomFactor)
Definition: Menus.cpp:6808
double GetEndTime() const
Definition: Track.cpp:1418
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
void TP_ScrollWindow(double scrollto) override
Definition: Project.cpp:1849
double GetScreenEndTime() const
Definition: Menus.cpp:6724
TrackPanel * GetTrackPanel()
Definition: Project.h:307
int GetLeftOffset() const
Definition: TrackPanel.h:287
void ZoomInByFactor(double ZoomFactor)
Definition: Menus.cpp:6729
TrackList * GetTracks()
Definition: Project.h:192
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
bool TP_ScrollUpDown(int delta) override
Definition: Project.cpp:1863
bool empty() const
Definition: Track.cpp:1229