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< 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

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

Implements UIHandle.

Definition at line 45 of file SpectrumVZoomHandle.cpp.

47{
49}

References RefreshCode::RefreshNone.

◆ DoZoom()

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

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

Reimplemented from TrackPanelDrawable.

Definition at line 85 of file SpectrumVZoomHandle.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 SpectrumVZoomHandle::DrawingArea ( TrackPanelDrawingContext ,
const wxRect &  rect,
const wxRect &  panelRect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

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

Reimplemented from UIHandle.

Definition at line 33 of file SpectrumVZoomHandle.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 > SpectrumVZoomHandle::GetTrack ( ) const
inline

Definition at line 37 of file SpectrumVZoomHandle.h.

37{ return mpTrack.lock(); }

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 40 of file SpectrumVZoomHandle.cpp.

41{
42 return true;
43}

◆ operator=()

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

◆ Preview()

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

Implements UIHandle.

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

Implements UIHandle.

Definition at line 67 of file SpectrumVZoomHandle.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(), 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(), GetTrack(), 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: