Audacity  3.0.3
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
WaveformVZoomHandle Class Referencefinal

#include <WaveformVZoomHandle.h>

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

Public Member Functions

 WaveformVZoomHandle (const std::shared_ptr< WaveTrack > &pTrack, const wxRect &rect, int y)
 
WaveformVZoomHandleoperator= (const WaveformVZoomHandle &)=default
 
 ~WaveformVZoomHandle () override
 
std::shared_ptr< WaveTrackGetTrack () const
 
void Enter (bool forward, AudacityProject *) override
 
bool HandlesRightClick () override
 Whether the handle has any special right-button handling. More...
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 

Static Public Member Functions

static void DoZoom (AudacityProject *pProject, WaveTrack *pTrack, WaveTrackViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Private Member Functions

 WaveformVZoomHandle (const WaveformVZoomHandle &)
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 

Private Attributes

std::weak_ptr< WaveTrackmpTrack
 
int mZoomStart {}
 
int mZoomEnd {}
 
wxRect mRect {}
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 19 of file WaveformVZoomHandle.h.

Constructor & Destructor Documentation

◆ WaveformVZoomHandle() [1/2]

WaveformVZoomHandle::WaveformVZoomHandle ( const WaveformVZoomHandle )
private

◆ WaveformVZoomHandle() [2/2]

WaveformVZoomHandle::WaveformVZoomHandle ( const std::shared_ptr< WaveTrack > &  pTrack,
const wxRect &  rect,
int  y 
)
explicit

Definition at line 25 of file WaveformVZoomHandle.cpp.

27  : mpTrack{ pTrack } , mZoomStart(y), mZoomEnd(y), mRect(rect)
28 {
29 }

◆ ~WaveformVZoomHandle()

WaveformVZoomHandle::~WaveformVZoomHandle ( )
overridedefault

Member Function Documentation

◆ Cancel()

UIHandle::Result WaveformVZoomHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 78 of file WaveformVZoomHandle.cpp.

79 {
80  // Cancel is implemented! And there is no initial state to restore,
81  // so just return a code.
83 }

References RefreshCode::RefreshAll.

◆ Click()

UIHandle::Result WaveformVZoomHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 45 of file WaveformVZoomHandle.cpp.

47 {
49 }

References RefreshCode::RefreshNone.

◆ DoZoom()

void WaveformVZoomHandle::DoZoom ( AudacityProject pProject,
WaveTrack pTrack,
WaveTrackViewConstants::ZoomActions  ZoomKind,
const wxRect &  rect,
int  zoomStart,
int  zoomEnd,
bool  fixedMousePoint 
)
static

Definition at line 105 of file WaveformVZoomHandle.cpp.

111 {
112  using namespace WaveTrackViewConstants;
113  static const float ZOOMLIMIT = 0.001f;
114 
115  int height = rect.height;
116  int ypos = rect.y;
117 
118  // Ensure start and end are in order (swap if not).
119  if (zoomEnd < zoomStart)
120  std::swap( zoomStart, zoomEnd );
121 
122  float min, max, minBand = 0;
123  const double rate = pTrack->GetRate();
124  const float halfrate = rate / 2;
125  float maxFreq = 8000.0;
126 
127  bool bDragZoom = WaveTrackVZoomHandle::IsDragZooming(zoomStart, zoomEnd);
128 
129  // Possibly override the zoom kind.
130  if( bDragZoom )
131  ZoomKind = kZoomInByDrag;
132 
133  float top=2.0;
134  float half=0.5;
135 
136  {
137  pTrack->GetDisplayBounds(&min, &max);
138  const WaveformSettings &waveSettings = pTrack->GetWaveformSettings();
139  const bool linear = waveSettings.isLinear();
140  if( !linear ){
141  top = (LINEAR_TO_DB(2.0) + waveSettings.dBRange) / waveSettings.dBRange;
142  half = (LINEAR_TO_DB(0.5) + waveSettings.dBRange) / waveSettings.dBRange;
143  }
144  }
145 
146 
147  // Compute min and max.
148  switch(ZoomKind)
149  {
150  default:
151  // If we have covered all the cases, this won't happen.
152  // In release builds Audacity will ignore the zoom.
153  wxFAIL_MSG("Zooming Case not implemented by Audacity");
154  break;
155  case kZoomReset:
156  case kZoom1to1:
157  {
158  // Zoom out full
159  min = -1.0;
160  max = 1.0;
161  }
162  break;
163  case kZoomDiv2:
164  {
165  // Zoom out even more than full :-)
166  // -2.0..+2.0 (or logarithmic equivalent)
167  min = -top;
168  max = top;
169  }
170  break;
171  case kZoomTimes2:
172  {
173  // Zoom in to -0.5..+0.5
174  min = -half;
175  max = half;
176  }
177  break;
178  case kZoomHalfWave:
179  {
180  // Zoom to show fractionally more than the top half of the wave.
181  min = -0.01f;
182  max = 1.0;
183  }
184  break;
185  case kZoomInByDrag:
186  {
187  const float tmin = min, tmax = max;
188  const float p1 = (zoomStart - ypos) / (float)height;
189  const float p2 = (zoomEnd - ypos) / (float)height;
190  max = (tmax * (1.0 - p1) + tmin * p1);
191  min = (tmax * (1.0 - p2) + tmin * p2);
192 
193  // Waveform view - allow zooming down to a range of ZOOMLIMIT
194  if (max - min < ZOOMLIMIT) { // if user attempts to go smaller...
195  float c = (min + max) / 2; // ...set centre of view to centre of dragged area and top/bottom to ZOOMLIMIT/2 above/below
196  min = c - ZOOMLIMIT / 2.0;
197  max = c + ZOOMLIMIT / 2.0;
198  }
199  }
200  break;
201  case kZoomIn:
202  {
203  // Enforce maximum vertical zoom
204  const float oldRange = max - min;
205  const float l = std::max(ZOOMLIMIT, 0.5f * oldRange);
206  const float ratio = l / (max - min);
207 
208  const float p1 = (zoomStart - ypos) / (float)height;
209  float c = (max * (1.0 - p1) + min * p1);
210  if (fixedMousePoint)
211  min = c - ratio * (1.0f - p1) * oldRange,
212  max = c + ratio * p1 * oldRange;
213  else
214  min = c - 0.5 * l,
215  max = c + 0.5 * l;
216  }
217  break;
218  case kZoomOut:
219  {
220  // Zoom out
221  if (min <= -1.0 && max >= 1.0) {
222  min = -top;
223  max = top;
224  }
225  else {
226  // limit to +/- 1 range unless already outside that range...
227  float minRange = (min < -1) ? -top : -1.0;
228  float maxRange = (max > 1) ? top : 1.0;
229  // and enforce vertical zoom limits.
230  const float p1 = (zoomStart - ypos) / (float)height;
231  if (fixedMousePoint) {
232  const float oldRange = max - min;
233  const float c = (max * (1.0 - p1) + min * p1);
234  min = std::min(maxRange - ZOOMLIMIT,
235  std::max(minRange, c - 2 * (1.0f - p1) * oldRange));
236  max = std::max(minRange + ZOOMLIMIT,
237  std::min(maxRange, c + 2 * p1 * oldRange));
238  }
239  else {
240  const float c = p1 * min + (1 - p1) * max;
241  const float l = (max - min);
242  min = std::min(maxRange - ZOOMLIMIT,
243  std::max(minRange, c - l));
244  max = std::max(minRange + ZOOMLIMIT,
245  std::min(maxRange, c + l));
246  }
247  }
248  }
249  break;
250  }
251 
252  // Now actually apply the zoom.
253  for (auto channel : TrackList::Channels(pTrack))
254  channel->SetDisplayBounds(min, max);
255 
256  zoomEnd = zoomStart = 0;
257  if( pProject )
258  ProjectHistory::Get( *pProject ).ModifyState(true);
259 }

References TrackList::Channels(), WaveformSettings::dBRange, ProjectHistory::Get(), WaveTrack::GetDisplayBounds(), WaveTrack::GetRate(), WaveTrack::GetWaveformSettings(), WaveTrackVZoomHandle::IsDragZooming(), WaveformSettings::isLinear(), WaveTrackViewConstants::kZoom1to1, WaveTrackViewConstants::kZoomDiv2, WaveTrackViewConstants::kZoomHalfWave, WaveTrackViewConstants::kZoomIn, WaveTrackViewConstants::kZoomInByDrag, WaveTrackViewConstants::kZoomOut, WaveTrackViewConstants::kZoomReset, WaveTrackViewConstants::kZoomTimes2, LINEAR_TO_DB, min(), ProjectHistory::ModifyState(), and anonymous_namespace{NoteTrack.cpp}::swap().

Referenced by WaveformVRulerControls::DoHandleWheelRotation(), and Release().

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

◆ Drag()

UIHandle::Result WaveformVZoomHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 51 of file WaveformVZoomHandle.cpp.

53 {
54  using namespace RefreshCode;
55  auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
56  if (!pTrack)
57  return Cancelled;
58  return WaveTrackVZoomHandle::DoDrag( evt, pProject, mZoomStart, mZoomEnd );
59 }

References RefreshCode::Cancelled, WaveTrackVZoomHandle::DoDrag(), TrackList::Get(), TrackList::Lock(), mpTrack, mZoomEnd, and mZoomStart.

Here is the call graph for this function:

◆ Draw()

void WaveformVZoomHandle::Draw ( TrackPanelDrawingContext context,
const wxRect &  rect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 85 of file WaveformVZoomHandle.cpp.

88 {
89  if (!mpTrack.lock()) //? TrackList::Lock()
90  return;
92  context, rect, iPass, mZoomStart, mZoomEnd );
93 }

References WaveTrackVZoomHandle::DoDraw(), mpTrack, mZoomEnd, and mZoomStart.

Here is the call graph for this function:

◆ DrawingArea()

wxRect WaveformVZoomHandle::DrawingArea ( TrackPanelDrawingContext ,
const wxRect &  rect,
const wxRect &  panelRect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 95 of file WaveformVZoomHandle.cpp.

98 {
99  return WaveTrackVZoomHandle::DoDrawingArea( rect, panelRect, iPass );
100 }

References WaveTrackVZoomHandle::DoDrawingArea().

Here is the call graph for this function:

◆ Enter()

void WaveformVZoomHandle::Enter ( bool  forward,
AudacityProject  
)
overridevirtual

Reimplemented from UIHandle.

Definition at line 33 of file WaveformVZoomHandle.cpp.

34 {
35 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
37 #endif
38 }

References UIHandle::mChangeHighlight, and RefreshCode::RefreshCell.

◆ GetTrack()

std::shared_ptr<WaveTrack> WaveformVZoomHandle::GetTrack ( ) const
inline

Definition at line 37 of file WaveformVZoomHandle.h.

37 { return mpTrack.lock(); }

References mpTrack.

◆ HandlesRightClick()

bool WaveformVZoomHandle::HandlesRightClick ( )
overridevirtual

Whether the handle has any special right-button handling.

If not, then Click() will not be called for right click. Default is always false

Reimplemented from UIHandle.

Definition at line 40 of file WaveformVZoomHandle.cpp.

41 {
42  return true;
43 }

◆ operator=()

WaveformVZoomHandle& WaveformVZoomHandle::operator= ( const WaveformVZoomHandle )
default

◆ Preview()

HitTestPreview WaveformVZoomHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 61 of file WaveformVZoomHandle.cpp.

63 {
64  return WaveTrackVZoomHandle::HitPreview(st.state);
65 }

References WaveTrackVZoomHandle::HitPreview(), and TrackPanelMouseState::state.

Here is the call graph for this function:

◆ Release()

UIHandle::Result WaveformVZoomHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 67 of file WaveformVZoomHandle.cpp.

70 {
71  auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
73  evt, pProject, pParent, pTrack.get(), mRect,
76 }

References WaveTrackVZoomHandle::DoRelease(), DoZoom(), TrackList::Get(), WaveformVRulerMenuTable::Instance(), TrackList::Lock(), mpTrack, mRect, mZoomEnd, and mZoomStart.

Here is the call graph for this function:

Member Data Documentation

◆ mpTrack

std::weak_ptr<WaveTrack> WaveformVZoomHandle::mpTrack
private

Definition at line 70 of file WaveformVZoomHandle.h.

Referenced by Drag(), Draw(), GetTrack(), and Release().

◆ mRect

wxRect WaveformVZoomHandle::mRect {}
private

Definition at line 73 of file WaveformVZoomHandle.h.

Referenced by Release().

◆ mZoomEnd

int WaveformVZoomHandle::mZoomEnd {}
private

Definition at line 72 of file WaveformVZoomHandle.h.

Referenced by Drag(), Draw(), and Release().

◆ mZoomStart

int WaveformVZoomHandle::mZoomStart {}
private

Definition at line 72 of file WaveformVZoomHandle.h.

Referenced by Drag(), Draw(), and Release().


The documentation for this class was generated from the following files:
WaveformVZoomHandle::mZoomStart
int mZoomStart
Definition: WaveformVZoomHandle.h:72
WaveformSettings::isLinear
bool isLinear() const
Definition: WaveformSettings.h:71
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
WaveTrackViewConstants::kZoomTimes2
@ kZoomTimes2
Definition: WaveTrackViewConstants.h:73
TrackList::Lock
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1542
WaveformVZoomHandle::mRect
wxRect mRect
Definition: WaveformVZoomHandle.h:73
WaveTrackVZoomHandle::DoRelease
AUDACITY_DLL_API Result DoRelease(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent, WaveTrack *pTrack, const wxRect &mRect, DoZoomFunction doZoom, PopupMenuTable &table, int zoomStart, int zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:97
WaveTrackViewConstants
Definition: WaveTrackView.h:17
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
WaveTrackVZoomHandle::DoDrawingArea
AUDACITY_DLL_API wxRect DoDrawingArea(const wxRect &rect, const wxRect &panelRect, unsigned iPass)
Definition: WaveTrackVZoomHandle.cpp:161
WaveTrackViewConstants::kZoom1to1
@ kZoom1to1
Definition: WaveTrackViewConstants.h:72
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
WaveTrackVZoomHandle::DoDrag
AUDACITY_DLL_API Result DoDrag(const TrackPanelMouseEvent &event, AudacityProject *pProject, int zoomStart, int &zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:82
WaveTrackVZoomHandle::DoDraw
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:150
WaveTrackViewConstants::kZoomDiv2
@ kZoomDiv2
Definition: WaveTrackViewConstants.h:74
WaveTrackVZoomHandle::HitPreview
AUDACITY_DLL_API HitTestPreview HitPreview(const wxMouseState &state)
Definition: WaveTrackVZoomHandle.cpp:61
WaveTrackVZoomHandle::IsDragZooming
AUDACITY_DLL_API bool IsDragZooming(int zoomStart, int zoomEnd)
Definition: WaveTrackVZoomHandle.cpp:24
WaveformVRulerMenuTable::Instance
static PopupMenuTable & Instance()
Definition: WaveformVZoomHandle.cpp:264
UIHandle::mChangeHighlight
Result mChangeHighlight
Definition: UIHandle.h:139
WaveformVZoomHandle::DoZoom
static void DoZoom(AudacityProject *pProject, WaveTrack *pTrack, WaveTrackViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
Definition: WaveformVZoomHandle.cpp:105
WaveformVZoomHandle::mpTrack
std::weak_ptr< WaveTrack > mpTrack
Definition: WaveformVZoomHandle.h:70
WaveTrackViewConstants::kZoomIn
@ kZoomIn
Definition: WaveTrackViewConstants.h:77
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:735
WaveTrack::GetWaveformSettings
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:811
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
WaveTrackViewConstants::kZoomInByDrag
@ kZoomInByDrag
Definition: WaveTrackViewConstants.h:76
WaveTrackViewConstants::kZoomReset
@ kZoomReset
Definition: WaveTrackViewConstants.h:79
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
WaveformSettings::dBRange
int dBRange
Definition: WaveformSettings.h:68
WaveformSettings
Waveform settings, either for one track or as defaults.
Definition: WaveformSettings.h:19
WaveTrackViewConstants::kZoomOut
@ kZoomOut
Definition: WaveTrackViewConstants.h:78
LINEAR_TO_DB
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:631
WaveTrack::GetDisplayBounds
void GetDisplayBounds(float *min, float *max) const
Definition: WaveTrack.cpp:320
WaveformVZoomHandle::mZoomEnd
int mZoomEnd
Definition: WaveformVZoomHandle.h:72
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
WaveTrackViewConstants::kZoomHalfWave
@ kZoomHalfWave
Definition: WaveTrackViewConstants.h:75
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
WaveTrack::GetRate
double GetRate() const
Definition: WaveTrack.cpp:457