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< const ChannelFindChannel () const override
 
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)
 
virtual std::shared_ptr< const ChannelFindChannel () const =0
 
virtual bool IsDragging () const
 
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, WaveChannelViewConstants::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 83 of file WaveformVZoomHandle.cpp.

84{
85 // Cancel is implemented! And there is no initial state to restore,
86 // so just return a code.
88}

References RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 50 of file WaveformVZoomHandle.cpp.

52{
54}

References RefreshCode::RefreshNone.

◆ DoZoom()

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

Definition at line 110 of file WaveformVZoomHandle.cpp.

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

References ProjectHistory::Get(), WaveformSettings::Get(), WaveformScale::Get(), WaveTrack::GetRate(), WaveChannelVZoomHandle::IsDragZooming(), WaveChannelViewConstants::kZoom1to1, WaveChannelViewConstants::kZoomDiv2, WaveChannelViewConstants::kZoomHalfWave, WaveChannelViewConstants::kZoomIn, WaveChannelViewConstants::kZoomInByDrag, WaveChannelViewConstants::kZoomOut, WaveChannelViewConstants::kZoomReset, WaveChannelViewConstants::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 56 of file WaveformVZoomHandle.cpp.

58{
59 using namespace RefreshCode;
60 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
61 if (!pTrack)
62 return Cancelled;
64}
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1228
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
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 Cancelled, WaveChannelVZoomHandle::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 90 of file WaveformVZoomHandle.cpp.

93{
94 if (!mpTrack.lock()) //? TrackList::Lock()
95 return;
97 context, rect, iPass, mZoomStart, mZoomEnd);
98}
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd)

References WaveChannelVZoomHandle::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 100 of file WaveformVZoomHandle.cpp.

103{
104 return WaveChannelVZoomHandle::DoDrawingArea(rect, panelRect, iPass);
105}
AUDACITY_DLL_API wxRect DoDrawingArea(const wxRect &rect, const wxRect &panelRect, unsigned iPass)

References WaveChannelVZoomHandle::DoDrawingArea().

Here is the call graph for this function:

◆ Enter()

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

Reimplemented from UIHandle.

Definition at line 38 of file WaveformVZoomHandle.cpp.

39{
40#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
42#endif
43}
Result mChangeHighlight
Definition: UIHandle.h:147

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

◆ FindChannel()

std::shared_ptr< const Channel > WaveformVZoomHandle::FindChannel ( ) const
overridevirtual
Returns
pointer to associated channel, if any

Implements UIHandle.

Definition at line 33 of file WaveformVZoomHandle.cpp.

34{
35 return std::dynamic_pointer_cast<const Channel>(mpTrack.lock());
36}

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 45 of file WaveformVZoomHandle.cpp.

46{
47 return true;
48}

◆ operator=()

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

◆ Preview()

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

Implements UIHandle.

Definition at line 66 of file WaveformVZoomHandle.cpp.

68{
70}
AUDACITY_DLL_API HitTestPreview HitPreview(const wxMouseState &state)

References WaveChannelVZoomHandle::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 72 of file WaveformVZoomHandle.cpp.

75{
76 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
78 evt, pProject, pParent, pTrack.get(), mRect,
81}
static PopupMenuTable & Instance()
static void DoZoom(AudacityProject *pProject, WaveTrack *pTrack, WaveChannelViewConstants::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 WaveChannelVZoomHandle::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(), FindChannel(), 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: