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
 
std::shared_ptr< WaveChannelFindWaveChannel ()
 
- 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 CommonChannelCell
 CommonChannelCell (const std::shared_ptr< Channel > &pChannel)
 Construct from a channel. More...
 
 ~CommonChannelCell ()
 
std::shared_ptr< TrackDoFindTrack () override
 
void Reparent (const std::shared_ptr< Track > &parent, size_t iChannel) override
 Object may be shared among tracks but hold a special back-pointer to one of them; reassign it. More...
 
template<typename Subtype = Channel>
auto FindChannel () -> std::shared_ptr< Subtype >
 May return null. More...
 
template<typename Subtype = const Channel>
auto FindChannel () const -> std::enable_if_t< std::is_const_v< Subtype >, std::shared_ptr< Subtype > >
 May return null. More...
 
- 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)
 
- Public Member Functions inherited from ChannelAttachment
virtual ~ChannelAttachment ()
 
virtual void CopyTo (Track &track, size_t iChannel) const
 Copy state, for undo/redo purposes. More...
 
virtual void Reparent (const std::shared_ptr< Track > &parent, size_t iChannel)
 Object may be shared among tracks but hold a special back-pointer to one of them; reassign it. More...
 
virtual void WriteXMLAttributes (XMLWriter &writer, size_t iChannel) const
 Serialize persistent attributes. More...
 
virtual bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView, size_t iChannel)
 Deserialize an attribute, returning true if recognized. More...
 

Static Public Member Functions

static unsigned DoHandleWheelRotation (const TrackPanelMouseEvent &evt, AudacityProject *pProject, WaveChannel &wc)
 
- 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 WaveChannel &wc)
 

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,
WaveChannel wc 
)
static

Definition at line 67 of file SpectrumVRulerControls.cpp.

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

Definition at line 141 of file SpectrumVRulerControls.cpp.

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

128{
129 ChannelVRulerControls::Draw(context, rect_, iPass);
130 WaveChannelVRulerControls::DoDraw(*this, context, rect_, iPass);
131}
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:

◆ FindWaveChannel()

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

Definition at line 62 of file SpectrumVRulerControls.cpp.

63{
64 return FindChannel<WaveChannel>();
65}

Referenced by HandleWheelRotation(), HitTest(), and UpdateRuler().

Here is the caller graph for this function:

◆ HandleWheelRotation()

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

Reimplemented from TrackPanelCell.

Definition at line 52 of file SpectrumVRulerControls.cpp.

54{
55 using namespace RefreshCode;
56 const auto pChannel = FindWaveChannel();
57 if (!pChannel)
58 return RefreshNone;
59 return DoHandleWheelRotation(evt, pProject, *pChannel);
60}
static unsigned DoHandleWheelRotation(const TrackPanelMouseEvent &evt, AudacityProject *pProject, WaveChannel &wc)
std::shared_ptr< WaveChannel > FindWaveChannel()

References DoHandleWheelRotation(), FindWaveChannel(), 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 if (const auto pChannel = FindWaveChannel()) {
39 auto result = std::make_shared<SpectrumVZoomHandle>(
40 pChannel, st.rect, st.state.m_y);
41 result = AssignUIHandlePtr(mVZoomHandle, result);
42 results.push_back(result);
43 }
44 }
45
46 auto more = ChannelVRulerControls::HitTest(st, pProject);
47 std::copy(more.begin(), more.end(), std::back_inserter(results));
48
49 return results;
50}
const int kGuard
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
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(), FindWaveChannel(), 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 133 of file SpectrumVRulerControls.cpp.

134{
135 const auto pChannel = FindWaveChannel();
136 if (!pChannel)
137 return;
138 DoUpdateVRuler(rect, *pChannel);
139}
static void DoUpdateVRuler(const wxRect &rect, const WaveChannel &wc)

References DoUpdateVRuler(), and FindWaveChannel().

Here is the call graph for this function:

Member Data Documentation

◆ mVZoomHandle

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

Definition at line 54 of file SpectrumVRulerControls.h.

Referenced by HitTest().


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