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

27 : mpChannel{ pChannel } , mZoomStart(y), mZoomEnd(y), mRect(rect)
28{
29}
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 85 of file WaveformVZoomHandle.cpp.

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

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,
WaveChannel wc,
WaveChannelViewConstants::ZoomActions  ZoomKind,
const wxRect &  rect,
int  zoomStart,
int  zoomEnd,
bool  fixedMousePoint 
)
static

Definition at line 113 of file WaveformVZoomHandle.cpp.

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

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

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

95{
96 const auto pChannel = mpChannel.lock();
97 if (!pChannel)
98 return;
100 context, rect, iPass, mZoomStart, mZoomEnd, false);
101}
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 103 of file WaveformVZoomHandle.cpp.

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

34{
35 return TrackFromChannel(mpChannel.lock());
36}
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 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 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 72 of file WaveformVZoomHandle.cpp.

75{
76 const auto pChannel = mpChannel.lock();
77 if (!pChannel)
80 evt, pProject, pParent, *pChannel, mRect,
83}
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: