Audacity 3.2.0
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 void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

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}
std::weak_ptr< WaveTrack > mpTrack

◆ ~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 auto &cache = WaveformScale::Get(*pTrack);
138 cache.GetDisplayBounds(min, max);
139 auto &waveSettings = WaveformSettings::Get(*pTrack);
140 const bool linear = waveSettings.isLinear();
141 if( !linear ){
142 top = (LINEAR_TO_DB(2.0) + waveSettings.dBRange) / waveSettings.dBRange;
143 half = (LINEAR_TO_DB(0.5) + waveSettings.dBRange) / waveSettings.dBRange;
144 }
145 }
146
147
148 // Compute min and max.
149 switch(ZoomKind)
150 {
151 default:
152 // If we have covered all the cases, this won't happen.
153 // In release builds Audacity will ignore the zoom.
154 wxFAIL_MSG("Zooming Case not implemented by Audacity");
155 break;
156 case kZoomReset:
157 case kZoom1to1:
158 {
159 // Zoom out full
160 min = -1.0;
161 max = 1.0;
162 }
163 break;
164 case kZoomDiv2:
165 {
166 // Zoom out even more than full :-)
167 // -2.0..+2.0 (or logarithmic equivalent)
168 min = -top;
169 max = top;
170 }
171 break;
172 case kZoomTimes2:
173 {
174 // Zoom in to -0.5..+0.5
175 min = -half;
176 max = half;
177 }
178 break;
179 case kZoomHalfWave:
180 {
181 // Zoom to show fractionally more than the top half of the wave.
182 min = -0.01f;
183 max = 1.0;
184 }
185 break;
186 case kZoomInByDrag:
187 {
188 const float tmin = min, tmax = max;
189 const float p1 = (zoomStart - ypos) / (float)height;
190 const float p2 = (zoomEnd - ypos) / (float)height;
191 max = (tmax * (1.0 - p1) + tmin * p1);
192 min = (tmax * (1.0 - p2) + tmin * p2);
193
194 // Waveform view - allow zooming down to a range of ZOOMLIMIT
195 if (max - min < ZOOMLIMIT) { // if user attempts to go smaller...
196 float c = (min + max) / 2; // ...set centre of view to centre of dragged area and top/bottom to ZOOMLIMIT/2 above/below
197 min = c - ZOOMLIMIT / 2.0;
198 max = c + ZOOMLIMIT / 2.0;
199 }
200 }
201 break;
202 case kZoomIn:
203 {
204 // Enforce maximum vertical zoom
205 const float oldRange = max - min;
206 const float l = std::max(ZOOMLIMIT, 0.5f * oldRange);
207 const float ratio = l / (max - min);
208
209 const float p1 = (zoomStart - ypos) / (float)height;
210 float c = (max * (1.0 - p1) + min * p1);
211 if (fixedMousePoint)
212 min = c - ratio * (1.0f - p1) * oldRange,
213 max = c + ratio * p1 * oldRange;
214 else
215 min = c - 0.5 * l,
216 max = c + 0.5 * l;
217 }
218 break;
219 case kZoomOut:
220 {
221 // Zoom out
222 if (min <= -1.0 && max >= 1.0) {
223 min = -top;
224 max = top;
225 }
226 else {
227 // limit to +/- 1 range unless already outside that range...
228 float minRange = (min < -1) ? -top : -1.0;
229 float maxRange = (max > 1) ? top : 1.0;
230 // and enforce vertical zoom limits.
231 const float p1 = (zoomStart - ypos) / (float)height;
232 if (fixedMousePoint) {
233 const float oldRange = max - min;
234 const float c = (max * (1.0 - p1) + min * p1);
235 min = std::min(maxRange - ZOOMLIMIT,
236 std::max(minRange, c - 2 * (1.0f - p1) * oldRange));
237 max = std::max(minRange + ZOOMLIMIT,
238 std::min(maxRange, c + 2 * p1 * oldRange));
239 }
240 else {
241 const float c = p1 * min + (1 - p1) * max;
242 const float l = (max - min);
243 min = std::min(maxRange - ZOOMLIMIT,
244 std::max(minRange, c - l));
245 max = std::max(minRange + ZOOMLIMIT,
246 std::min(maxRange, c + l));
247 }
248 }
249 }
250 break;
251 }
252
253 // Now actually apply the zoom.
255
256 zoomEnd = zoomStart = 0;
257 if( pProject )
258 ProjectHistory::Get( *pProject ).ModifyState(true);
259}
int min(int a, int b)
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:561
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
double GetRate() const override
Definition: WaveTrack.cpp:421
void SetDisplayBounds(float min, float max)
static WaveformScale & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static WaveformSettings & Get(const WaveTrack &track)
AUDACITY_DLL_API bool IsDragZooming(int zoomStart, int zoomEnd)
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:752

References ProjectHistory::Get(), WaveformSettings::Get(), WaveformScale::Get(), WaveTrack::GetRate(), WaveTrackVZoomHandle::IsDragZooming(), WaveTrackViewConstants::kZoom1to1, WaveTrackViewConstants::kZoomDiv2, WaveTrackViewConstants::kZoomHalfWave, WaveTrackViewConstants::kZoomIn, WaveTrackViewConstants::kZoomInByDrag, WaveTrackViewConstants::kZoomOut, WaveTrackViewConstants::kZoomReset, WaveTrackViewConstants::kZoomTimes2, LINEAR_TO_DB, min(), ProjectHistory::ModifyState(), WaveformScale::SetDisplayBounds(), 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}
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1485
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
AUDACITY_DLL_API Result DoDrag(const TrackPanelMouseEvent &event, AudacityProject *pProject, int zoomStart, int &zoomEnd)

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}
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd)

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}
AUDACITY_DLL_API wxRect DoDrawingArea(const wxRect &rect, const wxRect &panelRect, unsigned iPass)

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}
Result mChangeHighlight
Definition: UIHandle.h:139

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}
AUDACITY_DLL_API HitTestPreview HitPreview(const wxMouseState &state)

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}
static PopupMenuTable & Instance()
static void DoZoom(AudacityProject *pProject, WaveTrack *pTrack, WaveTrackViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
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)

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: