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< WaveChannel > &pChannel, const wxRect &rect, int y)
 
WaveformVZoomHandleoperator= (const WaveformVZoomHandle &)=default
 
 ~WaveformVZoomHandle () override
 
std::shared_ptr< const TrackFindTrack () 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 TrackFindTrack () 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, WaveChannel &wc, 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 std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- 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< WaveChannelmpChannel
 
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 20 of file WaveformVZoomHandle.h.

Constructor & Destructor Documentation

◆ WaveformVZoomHandle() [1/2]

WaveformVZoomHandle::WaveformVZoomHandle ( const WaveformVZoomHandle )
private

◆ WaveformVZoomHandle() [2/2]

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

Definition at line 26 of file WaveformVZoomHandle.cpp.

28 : mpChannel{ pChannel } , mZoomStart(y), mZoomEnd(y), mRect(rect)
29{
30}
std::weak_ptr< WaveChannel > mpChannel

◆ ~WaveformVZoomHandle()

WaveformVZoomHandle::~WaveformVZoomHandle ( )
overridedefault

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 86 of file WaveformVZoomHandle.cpp.

87{
88 // Cancel is implemented! And there is no initial state to restore,
89 // so just return a code.
91}

References RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 51 of file WaveformVZoomHandle.cpp.

53{
55}

References RefreshCode::RefreshNone.

◆ DoZoom()

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

Definition at line 114 of file WaveformVZoomHandle.cpp.

120{
121 using namespace WaveChannelViewConstants;
122 static const float ZOOMLIMIT = 0.001f;
123
124 int height = rect.height;
125 int ypos = rect.y;
126
127 // Ensure start and end are in order (swap if not).
128 if (zoomEnd < zoomStart)
129 std::swap( zoomStart, zoomEnd );
130
131 float min, max, minBand = 0;
132 const double rate = wc.GetRate();
133 const float halfrate = rate / 2;
134 float maxFreq = 8000.0;
135
136
137 float top=2.0;
138 float half=0.5;
139 auto &cache = WaveformScale::Get(wc);
140
141 {
142 cache.GetDisplayBounds(min, max);
143 auto &waveSettings = WaveformSettings::Get(wc);
144 const bool linear = waveSettings.isLinear();
145 if( !linear ){
146 top = (LINEAR_TO_DB(2.0) + waveSettings.dBRange) / waveSettings.dBRange;
147 half = (LINEAR_TO_DB(0.5) + waveSettings.dBRange) / waveSettings.dBRange;
148 }
149 }
150
151
152 // Compute min and max.
153 switch(ZoomKind)
154 {
155 default:
156 // If we have covered all the cases, this won't happen.
157 // In release builds Audacity will ignore the zoom.
158 wxFAIL_MSG("Zooming Case not implemented by Audacity");
159 break;
160 case kZoomReset:
161 case kZoom1to1:
162 {
163 // Zoom out full
164 min = -1.0;
165 max = 1.0;
166 }
167 break;
168 case kZoomHalfWave:
169 {
170 // Zoom to show fractionally more than the top half of the wave.
171 min = -0.01f;
172 max = 1.0;
173 }
174 break;
175 case kZoomInByDrag:
176 {
177 const float tmin = min, tmax = max;
178 const float p1 = (zoomStart - ypos) / (float)height;
179 const float p2 = (zoomEnd - ypos) / (float)height;
180 max = (tmax * (1.0 - p1) + tmin * p1);
181 min = (tmax * (1.0 - p2) + tmin * p2);
182
183 // Waveform view - allow zooming down to a range of ZOOMLIMIT
184 if (max - min < ZOOMLIMIT) { // if user attempts to go smaller...
185 float c = (min + max) / 2; // ...set centre of view to centre of dragged area and top/bottom to ZOOMLIMIT/2 above/below
186 min = c - ZOOMLIMIT / 2.0;
187 max = c + ZOOMLIMIT / 2.0;
188 }
189 }
190 break;
191 case kZoomIn:
192 {
193 const float zoomFactor = 0.5f;
194 const float currentRange = max - min;
195 const float nextRange = std::max(zoomFactor * currentRange, ZOOMLIMIT);
196
197 const float center = min + (currentRange / 2.0);
198 min = center - (nextRange / 2.0);
199 max = center + (nextRange / 2.0);
200 }
201 break;
202 case kZoomOut:
203 {
204 const float zoomFactor = 2.0f;
205 const float currentRange = max - min;
206 const float nextRange = zoomFactor * currentRange;
207
208 const float center = min + (currentRange / 2.0);
209 min = std::max(-top, center - (0.5f * nextRange));
210 max = std::min(top, center + (0.5f * nextRange));
211 }
212 break;
213 }
214
215 // Now actually apply the zoom.
216 cache.SetDisplayBounds(min, max);
217
218 zoomEnd = zoomStart = 0;
219 if( pProject )
220 ProjectHistory::Get( *pProject ).ModifyState(true);
221}
int min(int a, int b)
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:339
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
double GetRate() const override
Definition: WaveTrack.cpp:816
static WaveformScale & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static WaveformSettings & Get(const WaveTrack &track)
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

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

59{
60 using namespace RefreshCode;
61 const auto pChannel = mpChannel.lock();
62 if (!pChannel)
63 return Cancelled;
64 return WaveChannelVZoomHandle::DoDrag(evt, pProject, mZoomStart, mZoomEnd, false);
65}
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, bool hasDragZoom)

References Cancelled, WaveChannelVZoomHandle::DoDrag(), mpChannel, 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 93 of file WaveformVZoomHandle.cpp.

96{
97 const auto pChannel = mpChannel.lock();
98 if (!pChannel)
99 return;
101 context, rect, iPass, mZoomStart, mZoomEnd, false);
102}
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd, bool hasDragZoom)

References WaveChannelVZoomHandle::DoDraw(), mpChannel, 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 104 of file WaveformVZoomHandle.cpp.

107{
108 return WaveChannelVZoomHandle::DoDrawingArea(rect, panelRect, iPass);
109}
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 39 of file WaveformVZoomHandle.cpp.

40{
41#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
43#endif
44}
Result mChangeHighlight
Definition: UIHandle.h:152

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

◆ FindTrack()

std::shared_ptr< const Track > WaveformVZoomHandle::FindTrack ( ) const
overridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 34 of file WaveformVZoomHandle.cpp.

35{
36 return TrackFromChannel(mpChannel.lock());
37}
static std::shared_ptr< const Track > TrackFromChannel(const std::shared_ptr< const Channel > &pChannel)
A frequent convenience in the definition of UIHandles.
Definition: UIHandle.cpp:63

References mpChannel, and UIHandle::TrackFromChannel().

Here is the call graph for this function:

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

47{
48 return true;
49}

◆ operator=()

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

◆ Preview()

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

Implements UIHandle.

Definition at line 67 of file WaveformVZoomHandle.cpp.

69{
71}
AUDACITY_DLL_API HitTestPreview HitPreview(const bool bVZoom)

References WaveChannelVZoomHandle::HitPreview().

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

76{
77 const auto pChannel = mpChannel.lock();
78 if (!pChannel)
81 evt, pProject, pParent, *pChannel, mRect,
84}
static PopupMenuTable & Instance()
static void DoZoom(AudacityProject *pProject, WaveChannel &wc, WaveChannelViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
AUDACITY_DLL_API Result DoRelease(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent, WaveChannel &wc, const wxRect &mRect, DoZoomFunction doZoom, PopupMenuTable &table, int zoomStart, int zoomEnd)

References RefreshCode::Cancelled, WaveChannelVZoomHandle::DoRelease(), DoZoom(), WaveformVRulerMenuTable::Instance(), mpChannel, mRect, mZoomEnd, and mZoomStart.

Here is the call graph for this function:

Member Data Documentation

◆ mpChannel

std::weak_ptr<WaveChannel> WaveformVZoomHandle::mpChannel
private

Definition at line 71 of file WaveformVZoomHandle.h.

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

◆ mRect

wxRect WaveformVZoomHandle::mRect {}
private

Definition at line 74 of file WaveformVZoomHandle.h.

Referenced by Release().

◆ mZoomEnd

int WaveformVZoomHandle::mZoomEnd {}
private

Definition at line 73 of file WaveformVZoomHandle.h.

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

◆ mZoomStart

int WaveformVZoomHandle::mZoomStart {}
private

Definition at line 73 of file WaveformVZoomHandle.h.

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


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