Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
SpectrumVZoomHandle Class Referencefinal

#include <SpectrumVZoomHandle.h>

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

Public Member Functions

 SpectrumVZoomHandle (const std::shared_ptr< WaveTrack > &pTrack, const wxRect &rect, int y)
 
SpectrumVZoomHandleoperator= (const SpectrumVZoomHandle &)=default
 
 ~SpectrumVZoomHandle () 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

 SpectrumVZoomHandle (const SpectrumVZoomHandle &)
 
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 SpectrumVZoomHandle.h.

Constructor & Destructor Documentation

◆ SpectrumVZoomHandle() [1/2]

SpectrumVZoomHandle::SpectrumVZoomHandle ( const SpectrumVZoomHandle )
private

◆ SpectrumVZoomHandle() [2/2]

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

Definition at line 25 of file SpectrumVZoomHandle.cpp.

27 : mpTrack{ pTrack } , mZoomStart(y), mZoomEnd(y), mRect(rect)
28{
29}
std::weak_ptr< WaveTrack > mpTrack

◆ ~SpectrumVZoomHandle()

SpectrumVZoomHandle::~SpectrumVZoomHandle ( )
overridedefault

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 83 of file SpectrumVZoomHandle.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 SpectrumVZoomHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 50 of file SpectrumVZoomHandle.cpp.

52{
54}

References RefreshCode::RefreshNone.

◆ DoZoom()

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

Definition at line 110 of file SpectrumVZoomHandle.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 const auto &specSettings = SpectrogramSettings::Get(*pTrack);
132 NumberScale scale;
133 const bool spectrumLinear =
135
136 bool bDragZoom = WaveChannelVZoomHandle::IsDragZooming(zoomStart, zoomEnd, true);
137 // Add 100 if spectral to separate the kinds of zoom.
138 const int kSpectral = 100;
139
140 // Possibly override the zoom kind.
141 if( bDragZoom )
142 ZoomKind = kZoomInByDrag;
143
144 float top=2.0;
145 float half=0.5;
146
147 {
148 SpectrogramBounds::Get(*pTrack).GetBounds(*pTrack, min, max);
149 scale = (specSettings.GetScale(min, max));
150 const auto fftLength = specSettings.GetFFTLength();
151 const float binSize = rate / fftLength;
152 maxFreq = SpectrumMaxFreq.Read();
153 // JKC: Following discussions of Bug 1208 I'm allowing zooming in
154 // down to one bin.
155 // const int minBins =
156 // std::min(10, fftLength / 2); //minimum 10 freq bins, unless there are less
157 const int minBins = 1;
158 minBand = minBins * binSize;
159 }
160
161 // Compute min and max.
162 switch(ZoomKind)
163 {
164 default:
165 // If we have covered all the cases, this won't happen.
166 // In release builds Audacity will ignore the zoom.
167 wxFAIL_MSG("Zooming Case not implemented by Audacity");
168 break;
169
170 // VZooming on spectral we don't implement the other zoom presets.
171 // They are also not in the menu.
172 case kZoomReset:
173 {
174 // Zoom out to normal level.
175 min = spectrumLinear ? 0.0f : 1.0f;
176 max = maxFreq;
177 }
178 break;
179 case kZoom1to1:
180 case kZoomHalfWave:
181 {
182 // Zoom out full
183 min = spectrumLinear ? 0.0f : 1.0f;
184 max = halfrate;
185 }
186 break;
187 case kZoomInByDrag:
188 {
189 double xmin = 1 - (zoomEnd - ypos) / (float)height;
190 double xmax = 1 - (zoomStart - ypos) / (float)height;
191 const float middle = (xmin + xmax) / 2;
192 const float middleValue = scale.PositionToValue(middle);
193
194 min = std::max(spectrumLinear ? 0.0f : 1.0f,
195 std::min(middleValue - minBand / 2,
196 scale.PositionToValue(xmin)
197 ));
198 max = std::min(halfrate,
199 std::max(middleValue + minBand / 2,
200 scale.PositionToValue(xmax)
201 ));
202 }
203 break;
204 case kZoomIn:
205 {
206 // Center the zoom-in at the click
207 const float p1 = (zoomStart - ypos) / (float)height;
208 const float middle = 1.0f - p1;
209 const float middleValue = scale.PositionToValue(middle);
210
211 if (fixedMousePoint) {
212 min = std::max(spectrumLinear ? 0.0f : 1.0f,
213 std::min(middleValue - minBand * middle,
214 scale.PositionToValue(0.5f * middle)
215 ));
216 max = std::min(halfrate,
217 std::max(middleValue + minBand * p1,
218 scale.PositionToValue(middle + 0.5f * p1)
219 ));
220 }
221 else {
222 min = std::max(spectrumLinear ? 0.0f : 1.0f,
223 std::min(middleValue - minBand / 2,
224 scale.PositionToValue(middle - 0.25f)
225 ));
226 max = std::min(halfrate,
227 std::max(middleValue + minBand / 2,
228 scale.PositionToValue(middle + 0.25f)
229 ));
230 }
231 }
232 break;
233 case kZoomOut:
234 {
235 // Zoom out
236 const float p1 = (zoomStart - ypos) / (float)height;
237 // (Used to zoom out centered at midline, ignoring the click, if linear view.
238 // I think it is better to be consistent. PRL)
239 // Center zoom-out at the midline
240 const float middle = // spectrumLinear ? 0.5f :
241 1.0f - p1;
242
243 if (fixedMousePoint) {
244 min = std::max(spectrumLinear ? 0.0f : 1.0f, scale.PositionToValue(-middle));
245 max = std::min(halfrate, scale.PositionToValue(1.0f + p1));
246 }
247 else {
248 min = std::max(spectrumLinear ? 0.0f : 1.0f, scale.PositionToValue(middle - 1.0f));
249 max = std::min(halfrate, scale.PositionToValue(middle + 1.0f));
250 }
251 }
252 break;
253 }
254
255 // Now actually apply the zoom.
256 SpectrogramBounds::Get(*pTrack).SetBounds(min, max);
257
258 zoomEnd = zoomStart = 0;
259 if( pProject )
260 ProjectHistory::Get( *pProject ).ModifyState(true);
261}
int min(int a, int b)
IntSetting SpectrumMaxFreq
float PositionToValue(float pp) const
Definition: NumberScale.h:155
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:205
void GetBounds(const WaveTrack &wt, float &min, float &max) const
void SetBounds(float min, float max)
static SpectrogramBounds & Get(WaveTrack &track)
Get either the global default settings, or the track's own if previously created.
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
double GetRate() const override
Definition: WaveTrack.cpp:1102
AUDACITY_DLL_API bool IsDragZooming(int zoomStart, int zoomEnd, bool hasDragZoom)
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:645

References ProjectHistory::Get(), SpectrogramSettings::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), WaveTrack::GetRate(), WaveChannelVZoomHandle::IsDragZooming(), WaveChannelViewConstants::kZoom1to1, WaveChannelViewConstants::kZoomHalfWave, WaveChannelViewConstants::kZoomIn, WaveChannelViewConstants::kZoomInByDrag, WaveChannelViewConstants::kZoomOut, WaveChannelViewConstants::kZoomReset, min(), ProjectHistory::ModifyState(), NumberScale::PositionToValue(), Setting< T >::Read(), SpectrogramSettings::scaleType, SpectrogramBounds::SetBounds(), SpectrumMaxFreq, SpectrogramSettings::stLinear, and anonymous_namespace{NoteTrack.cpp}::swap().

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

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

◆ Drag()

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

Implements UIHandle.

Definition at line 56 of file SpectrumVZoomHandle.cpp.

58{
59 using namespace RefreshCode;
60 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
61 if (!pTrack)
62 return Cancelled;
63 return WaveChannelVZoomHandle::DoDrag(evt, pProject, mZoomStart, mZoomEnd, true);
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, bool hasDragZoom)

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

Here is the call graph for this function:

◆ Draw()

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

Reimplemented from TrackPanelDrawable.

Definition at line 90 of file SpectrumVZoomHandle.cpp.

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

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

Here is the call graph for this function:

◆ DrawingArea()

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

Reimplemented from TrackPanelDrawable.

Definition at line 100 of file SpectrumVZoomHandle.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 SpectrumVZoomHandle::Enter ( bool  forward,
AudacityProject  
)
overridevirtual

Reimplemented from UIHandle.

Definition at line 38 of file SpectrumVZoomHandle.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 > SpectrumVZoomHandle::FindChannel ( ) const
overridevirtual
Returns
pointer to associated channel, if any

Implements UIHandle.

Definition at line 33 of file SpectrumVZoomHandle.cpp.

34{
35 return mpTrack.lock();
36}

References mpTrack.

◆ HandlesRightClick()

bool SpectrumVZoomHandle::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 SpectrumVZoomHandle.cpp.

46{
47 return true;
48}

◆ operator=()

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

◆ Preview()

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

Implements UIHandle.

Definition at line 66 of file SpectrumVZoomHandle.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 SpectrumVZoomHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 72 of file SpectrumVZoomHandle.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(), SpectrumVRulerMenuTable::Instance(), TrackList::Lock(), mpTrack, mRect, mZoomEnd, and mZoomStart.

Here is the call graph for this function:

Member Data Documentation

◆ mpTrack

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

Definition at line 70 of file SpectrumVZoomHandle.h.

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

◆ mRect

wxRect SpectrumVZoomHandle::mRect {}
private

Definition at line 73 of file SpectrumVZoomHandle.h.

Referenced by Release().

◆ mZoomEnd

int SpectrumVZoomHandle::mZoomEnd {}
private

Definition at line 72 of file SpectrumVZoomHandle.h.

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

◆ mZoomStart

int SpectrumVZoomHandle::mZoomStart {}
private

Definition at line 72 of file SpectrumVZoomHandle.h.

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


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