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

#include <SpectrumVRulerControls.h>

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

Public Member Functions

 SpectrumVRulerControls (const std::shared_ptr< ChannelView > &pChannelView)
 
 ~SpectrumVRulerControls () override
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *) override
 
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
- Public Member Functions inherited from ChannelVRulerControls
 ChannelVRulerControls (const std::shared_ptr< ChannelView > &pChannelView)
 
virtual ~ChannelVRulerControls ()=0
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject) override
 
virtual void UpdateRuler (const wxRect &rect)=0
 
std::shared_ptr< const ChannelViewGetChannelView () const
 
- Public Member Functions inherited from CommonTrackPanelCell
 CommonTrackPanelCell ()
 
virtual ~CommonTrackPanelCell ()=0
 
HitTestPreview DefaultPreview (const TrackPanelMouseState &, const AudacityProject *) override
 
std::shared_ptr< TrackFindTrack ()
 
std::shared_ptr< const TrackFindTrack () const
 
virtual std::vector< MenuItemGetMenuItems (const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
 Return a list of items for DoContextMenu() (empties for separators) More...
 
- Public Member Functions inherited from TrackPanelCell
 TrackPanelCell ()=default
 
 TrackPanelCell (const TrackPanelCell &)=delete
 
TrackPanelCelloperator= (const TrackPanelCell &)=delete
 
virtual ~TrackPanelCell ()=0
 
virtual HitTestPreview DefaultPreview (const TrackPanelMouseState &state, const AudacityProject *pProject)
 
virtual std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject)=0
 
virtual unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject)
 
virtual std::shared_ptr< TrackPanelCellContextMenuDelegate ()
 
virtual unsigned DoContextMenu (const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject)
 
virtual unsigned CaptureKey (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned KeyDown (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned KeyUp (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned Char (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned LoseFocus (AudacityProject *project)
 
- Public Member Functions inherited from TrackPanelNode
 TrackPanelNode ()
 
virtual ~TrackPanelNode ()=0
 
- 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 unsigned DoHandleWheelRotation (const TrackPanelMouseEvent &evt, AudacityProject *pProject, WaveTrack *wt)
 
- Static Public Member Functions inherited from ChannelVRulerControls
static ChannelVRulerControlsGet (ChannelView &)
 
static const ChannelVRulerControlsGet (const ChannelView &)
 
static void DrawZooming (TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
 
static wxRect ZoomingArea (const wxRect &rect, const wxRect &panelRect)
 
- 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

 SpectrumVRulerControls (const SpectrumVRulerControls &)=delete
 
SpectrumVRulerControlsoperator= (const SpectrumVRulerControls &)=delete
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
void UpdateRuler (const wxRect &rect) override
 

Static Private Member Functions

static void DoUpdateVRuler (const wxRect &rect, const WaveTrack *wt)
 

Private Attributes

std::weak_ptr< SpectrumVZoomHandlemVZoomHandle
 

Additional Inherited Members

- Protected Member Functions inherited from ChannelVRulerControls
std::shared_ptr< TrackDoFindTrack () override
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 
TrackGetTrack () const
 
- Protected Member Functions inherited from CommonTrackPanelCell
virtual std::shared_ptr< TrackDoFindTrack ()=0
 
unsigned DoContextMenu (const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject) override
 
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
- Protected Attributes inherited from ChannelVRulerControls
std::weak_ptr< ChannelViewmwChannelView
 

Detailed Description

Definition at line 19 of file SpectrumVRulerControls.h.

Constructor & Destructor Documentation

◆ SpectrumVRulerControls() [1/2]

SpectrumVRulerControls::SpectrumVRulerControls ( const SpectrumVRulerControls )
privatedelete

◆ SpectrumVRulerControls() [2/2]

SpectrumVRulerControls::SpectrumVRulerControls ( const std::shared_ptr< ChannelView > &  pChannelView)
inlineexplicit

Definition at line 26 of file SpectrumVRulerControls.h.

◆ ~SpectrumVRulerControls()

SpectrumVRulerControls::~SpectrumVRulerControls ( )
overridedefault

Member Function Documentation

◆ DoHandleWheelRotation()

unsigned SpectrumVRulerControls::DoHandleWheelRotation ( const TrackPanelMouseEvent evt,
AudacityProject pProject,
WaveTrack wt 
)
static

Definition at line 64 of file SpectrumVRulerControls.cpp.

66{
67 using namespace RefreshCode;
68 const wxMouseEvent &event = evt.event;
69
70 if (!(event.ShiftDown() || event.CmdDown()))
71 return RefreshNone;
72
73 // Always stop propagation even if the ruler didn't change. The ruler
74 // is a narrow enough target.
75 evt.event.Skip(false);
76
77 auto steps = evt.steps;
78
79 using namespace WaveChannelViewConstants;
80 if (event.CmdDown() && !event.ShiftDown()) {
81 const int yy = event.m_y;
83 pProject, wt,
84 (steps < 0)
85 ? kZoomOut
86 : kZoomIn,
87 evt.rect, yy, yy, true);
88 }
89 else if (!event.CmdDown() && event.ShiftDown()) {
90 // Scroll some fixed number of pixels, independent of zoom level or track height:
91 static const float movement = 10.0f;
92 const int height = evt.rect.GetHeight();
93 {
94 const float delta = steps * movement / height;
96 const bool isLinear = settings.scaleType == SpectrogramSettings::stLinear;
97 float bottom, top;
98 SpectrogramBounds::Get(*wt).GetBounds(*wt, bottom, top);
99 const double rate = wt->GetRate();
100 const float bound = rate / 2;
101 const NumberScale numberScale(settings.GetScale(bottom, top));
102 float newTop =
103 std::min(bound, numberScale.PositionToValue(1.0f + delta));
104 const float newBottom =
105 std::max((isLinear ? 0.0f : 1.0f),
106 numberScale.PositionToValue(numberScale.ValueToPosition(newTop) - 1.0f));
107 newTop =
108 std::min(bound,
109 numberScale.PositionToValue(numberScale.ValueToPosition(newBottom) + 1.0f));
110
111 SpectrogramBounds::Get(*wt).SetBounds(newBottom, newTop);
112 }
113 }
114 else
115 return RefreshNone;
116
117 ProjectHistory::Get( *pProject ).ModifyState(true);
118
119 return RefreshCell | UpdateVRuler;
120}
int min(int a, int b)
static Settings & settings()
Definition: TrackInfo.cpp:69
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
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.
Spectrogram settings, either for one track or as defaults.
static SpectrogramSettings & Own(WaveTrack &track)
static void DoZoom(AudacityProject *pProject, WaveTrack *pTrack, WaveChannelViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
double GetRate() const override
Definition: WaveTrack.cpp:1128
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

References SpectrumVZoomHandle::DoZoom(), TrackPanelMouseEvent::event, ProjectHistory::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), WaveTrack::GetRate(), WaveChannelViewConstants::kZoomIn, WaveChannelViewConstants::kZoomOut, min(), ProjectHistory::ModifyState(), SpectrogramSettings::Own(), NumberScale::PositionToValue(), TrackPanelMouseEvent::rect, RefreshCode::RefreshCell, RefreshCode::RefreshNone, SpectrogramBounds::SetBounds(), settings(), TrackPanelMouseEvent::steps, SpectrogramSettings::stLinear, RefreshCode::UpdateVRuler, and NumberScale::ValueToPosition().

Referenced by HandleWheelRotation().

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

◆ DoUpdateVRuler()

void SpectrumVRulerControls::DoUpdateVRuler ( const wxRect &  rect,
const WaveTrack wt 
)
staticprivate

Definition at line 138 of file SpectrumVRulerControls.cpp.

140{
142 const auto &settings = SpectrogramSettings::Get(*wt);
143 float minFreq, maxFreq;
144 SpectrogramBounds::Get(*wt).GetBounds(*wt, minFreq, maxFreq);
145 vruler->SetDbMirrorValue(0.0);
146
147 switch (settings.scaleType) {
148 default:
149 wxASSERT(false);
151 {
152 // Spectrum
153
154 /*
155 draw the ruler
156 we will use Hz if maxFreq is < 2000, otherwise we represent kHz,
157 and append to the numbers a "k"
158 */
159 vruler->SetBounds(
160 rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
161 vruler->SetOrientation(wxVERTICAL);
162 vruler->SetFormat(&RealFormat::LinearInstance());
163 vruler->SetLabelEdges(true);
164 // use kHz in scale, if appropriate
165 if (maxFreq >= 2000) {
166 vruler->SetRange((maxFreq / 1000.), (minFreq / 1000.));
167 /* i18n-hint k abbreviating kilo meaning thousands */
168 vruler->SetUnits(XO("k"));
169 }
170 else {
171 // use Hz
172 vruler->SetRange((int)(maxFreq), (int)(minFreq));
173 vruler->SetUnits({});
174 }
175 vruler->SetUpdater(&LinearUpdater::Instance());
176 }
177 break;
183 {
184 // SpectrumLog
185
186 /*
187 draw the ruler
188 we will use Hz if maxFreq is < 2000, otherwise we represent kHz,
189 and append to the numbers a "k"
190 */
191 vruler->SetBounds(
192 rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
193 vruler->SetOrientation(wxVERTICAL);
194 vruler->SetFormat(&IntFormat::Instance());
195 vruler->SetLabelEdges(true);
196 vruler->SetRange(maxFreq, minFreq);
197 vruler->SetUnits({});
198 vruler->SetUpdater(&LogarithmicUpdater::Instance());
199 NumberScale scale(settings.GetScale(minFreq, maxFreq).Reversal());
200 vruler->SetNumberScale(scale);
201 }
202 break;
203 }
204 auto &size = ChannelView::Get(*wt).vrulerSize;
205 vruler->GetMaxSize(&size.first, &size.second);
206}
XO("Cut/Copy/Paste")
static ChannelView & Get(Channel &channel)
std::pair< int, int > vrulerSize
Definition: ChannelView.h:128
static const IntFormat & Instance()
Definition: IntFormat.cpp:14
static const LinearUpdater & Instance()
static const LogarithmicUpdater & Instance()
static const RealFormat & LinearInstance()
Definition: RealFormat.cpp:14
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
AUDACITY_DLL_API Ruler & ScratchRuler()

References ChannelView::Get(), SpectrogramSettings::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), IntFormat::Instance(), LinearUpdater::Instance(), LogarithmicUpdater::Instance(), RealFormat::LinearInstance(), WaveChannelVRulerControls::ScratchRuler(), settings(), size, SpectrogramSettings::stBark, SpectrogramSettings::stErb, SpectrogramSettings::stLinear, SpectrogramSettings::stLogarithmic, SpectrogramSettings::stMel, SpectrogramSettings::stPeriod, ChannelView::vrulerSize, and XO().

Referenced by UpdateRuler().

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

◆ Draw()

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

Reimplemented from TrackPanelDrawable.

Definition at line 122 of file SpectrumVRulerControls.cpp.

125{
126 ChannelVRulerControls::Draw(context, rect_, iPass);
127 WaveChannelVRulerControls::DoDraw(*this, context, rect_, iPass);
128}
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
AUDACITY_DLL_API void DoDraw(ChannelVRulerControls &controls, TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)

References WaveChannelVRulerControls::DoDraw(), and ChannelVRulerControls::Draw().

Here is the call graph for this function:

◆ HandleWheelRotation()

unsigned SpectrumVRulerControls::HandleWheelRotation ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Reimplemented from TrackPanelCell.

Definition at line 53 of file SpectrumVRulerControls.cpp.

55{
56 using namespace RefreshCode;
57 const auto pTrack = FindTrack();
58 if (!pTrack)
59 return RefreshNone;
60 const auto wt = static_cast<WaveTrack*>(pTrack.get());
61 return DoHandleWheelRotation( evt, pProject, wt );
62}
std::shared_ptr< Track > FindTrack()
static unsigned DoHandleWheelRotation(const TrackPanelMouseEvent &evt, AudacityProject *pProject, WaveTrack *wt)
A Track that contains audio waveform data.
Definition: WaveTrack.h:227

References DoHandleWheelRotation(), CommonTrackPanelCell::FindTrack(), and RefreshCode::RefreshNone.

Here is the call graph for this function:

◆ HitTest()

std::vector< UIHandlePtr > SpectrumVRulerControls::HitTest ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements TrackPanelCell.

Definition at line 31 of file SpectrumVRulerControls.cpp.

34{
35 std::vector<UIHandlePtr> results;
36
37 if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
38 auto pTrack = FindTrack()->SharedPointer<WaveTrack>( );
39 if (pTrack) {
40 auto result = std::make_shared<SpectrumVZoomHandle>(
41 pTrack, st.rect, st.state.m_y );
42 result = AssignUIHandlePtr(mVZoomHandle, result);
43 results.push_back(result);
44 }
45 }
46
47 auto more = ChannelVRulerControls::HitTest(st, pProject);
48 std::copy(more.begin(), more.end(), std::back_inserter(results));
49
50 return results;
51}
const int kGuard
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:159
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
std::weak_ptr< SpectrumVZoomHandle > mVZoomHandle
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References AssignUIHandlePtr(), staffpad::vo::copy(), CommonTrackPanelCell::FindTrack(), ChannelVRulerControls::HitTest(), kGuard, mVZoomHandle, TrackPanelMouseState::rect, and TrackPanelMouseState::state.

Here is the call graph for this function:

◆ operator=()

SpectrumVRulerControls & SpectrumVRulerControls::operator= ( const SpectrumVRulerControls )
privatedelete

◆ UpdateRuler()

void SpectrumVRulerControls::UpdateRuler ( const wxRect &  rect)
overrideprivatevirtual

Implements ChannelVRulerControls.

Definition at line 130 of file SpectrumVRulerControls.cpp.

131{
132 const auto wt = std::static_pointer_cast< WaveTrack >( FindTrack() );
133 if (!wt)
134 return;
135 DoUpdateVRuler( rect, wt.get() );
136}
static void DoUpdateVRuler(const wxRect &rect, const WaveTrack *wt)

References DoUpdateVRuler(), and CommonTrackPanelCell::FindTrack().

Here is the call graph for this function:

Member Data Documentation

◆ mVZoomHandle

std::weak_ptr<SpectrumVZoomHandle> SpectrumVRulerControls::mVZoomHandle
private

Definition at line 52 of file SpectrumVRulerControls.h.

Referenced by HitTest().


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