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< WaveChannel > &pChannel, const wxRect &rect, int y)
 
SpectrumVZoomHandleoperator= (const SpectrumVZoomHandle &)=default
 
 ~SpectrumVZoomHandle () override
 
std::shared_ptr< const TrackFindTrack () const override
 
std::shared_ptr< WaveChannelFindWaveChannel ()
 
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

 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< 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 SpectrumVZoomHandle.h.

Constructor & Destructor Documentation

◆ SpectrumVZoomHandle() [1/2]

SpectrumVZoomHandle::SpectrumVZoomHandle ( const SpectrumVZoomHandle )
private

◆ SpectrumVZoomHandle() [2/2]

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

Definition at line 25 of file SpectrumVZoomHandle.cpp.

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

◆ ~SpectrumVZoomHandle()

SpectrumVZoomHandle::~SpectrumVZoomHandle ( )
overridedefault

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 89 of file SpectrumVZoomHandle.cpp.

90{
91 // Cancel is implemented! And there is no initial state to restore,
92 // so just return a code.
94}

References RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 55 of file SpectrumVZoomHandle.cpp.

57{
59}

References RefreshCode::RefreshNone.

◆ DoZoom()

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

Definition at line 117 of file SpectrumVZoomHandle.cpp.

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

References ProjectHistory::Get(), SpectrogramSettings::Get(), SpectrogramBounds::Get(), WaveChannel::GetRate(), WaveChannelVZoomHandle::IsDragZooming(), WaveChannelViewConstants::kZoom1to1, WaveChannelViewConstants::kZoomHalfWave, WaveChannelViewConstants::kZoomIn, WaveChannelViewConstants::kZoomInByDrag, WaveChannelViewConstants::kZoomOut, WaveChannelViewConstants::kZoomReset, min(), ProjectHistory::ModifyState(), NumberScale::PositionToValue(), Setting< T >::Read(), 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 61 of file SpectrumVZoomHandle.cpp.

63{
64 using namespace RefreshCode;
65 if (!FindTrack())
66 return Cancelled;
67 return WaveChannelVZoomHandle::DoDrag(evt, pProject, mZoomStart, mZoomEnd, true);
68}
std::shared_ptr< const Track > FindTrack() const override
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(), FindTrack(), 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 96 of file SpectrumVZoomHandle.cpp.

99{
100 const auto pChannel = FindTrack();
101 if (!pChannel)
102 return;
104 context, rect, iPass, mZoomStart, mZoomEnd, true );
105}
AUDACITY_DLL_API void DoDraw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass, int zoomStart, int zoomEnd, bool hasDragZoom)

References WaveChannelVZoomHandle::DoDraw(), FindTrack(), 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 107 of file SpectrumVZoomHandle.cpp.

110{
111 return WaveChannelVZoomHandle::DoDrawingArea(rect, panelRect, iPass);
112}
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 43 of file SpectrumVZoomHandle.cpp.

44{
45#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
47#endif
48}
Result mChangeHighlight
Definition: UIHandle.h:152

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

◆ FindTrack()

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

Implements UIHandle.

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

Referenced by Drag(), and Draw().

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

◆ FindWaveChannel()

std::shared_ptr< WaveChannel > SpectrumVZoomHandle::FindWaveChannel ( )

Definition at line 38 of file SpectrumVZoomHandle.cpp.

39{
40 return mpChannel.lock();
41}

References mpChannel.

Referenced by Release().

Here is the caller graph for this function:

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

51{
52 return true;
53}

◆ operator=()

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

◆ Preview()

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

Implements UIHandle.

Definition at line 70 of file SpectrumVZoomHandle.cpp.

72{
74}
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 76 of file SpectrumVZoomHandle.cpp.

79{
80 const auto pChannel = FindWaveChannel();
81 if (!pChannel)
84 evt, pProject, pParent, *pChannel, mRect,
87}
static PopupMenuTable & Instance()
static void DoZoom(AudacityProject *pProject, WaveChannel &wc, WaveChannelViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
std::shared_ptr< WaveChannel > FindWaveChannel()
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(), FindWaveChannel(), SpectrumVRulerMenuTable::Instance(), mRect, mZoomEnd, and mZoomStart.

Here is the call graph for this function:

Member Data Documentation

◆ mpChannel

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

Definition at line 72 of file SpectrumVZoomHandle.h.

Referenced by FindTrack(), and FindWaveChannel().

◆ mRect

wxRect SpectrumVZoomHandle::mRect {}
private

Definition at line 75 of file SpectrumVZoomHandle.h.

Referenced by Release().

◆ mZoomEnd

int SpectrumVZoomHandle::mZoomEnd {}
private

Definition at line 74 of file SpectrumVZoomHandle.h.

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

◆ mZoomStart

int SpectrumVZoomHandle::mZoomStart {}
private

Definition at line 74 of file SpectrumVZoomHandle.h.

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


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