Audacity  3.0.3
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< TrackView > &pTrackView)
 
 ~SpectrumVRulerControls () override
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *) override
 
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
- Public Member Functions inherited from TrackVRulerControls
 TrackVRulerControls (const std::shared_ptr< TrackView > &pTrackView)
 
virtual ~TrackVRulerControls ()=0
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject) override
 
- 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 &) PROHIBITED
 
TrackPanelCelloperator= (const TrackPanelCell &) PROHIBITED
 
virtual ~TrackPanelCell ()=0
 
virtual std::shared_ptr< TrackPanelCellContextMenuDelegate ()
 
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
 

Static Public Member Functions

static unsigned DoHandleWheelRotation (const TrackPanelMouseEvent &evt, AudacityProject *pProject, WaveTrack *wt)
 
- Static Public Member Functions inherited from TrackVRulerControls
static TrackVRulerControlsGet (TrackView &)
 
static const TrackVRulerControlsGet (const TrackView &)
 
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 CommonTrackPanelCell
static Hook InstallMouseWheelHook (const Hook &hook)
 
- 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

- Public Types inherited from CommonTrackPanelCell
using Hook = std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) >
 
- Protected Member Functions inherited from TrackVRulerControls
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
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 TrackVRulerControls
std::weak_ptr< TrackViewmwTrackView
 

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< TrackView > &  pTrackView)
inlineexplicit

Definition at line 26 of file SpectrumVRulerControls.h.

27  : TrackVRulerControls( pTrackView ) {}

◆ ~SpectrumVRulerControls()

SpectrumVRulerControls::~SpectrumVRulerControls ( )
overridedefault

Member Function Documentation

◆ DoHandleWheelRotation()

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

Definition at line 59 of file SpectrumVRulerControls.cpp.

61 {
62  using namespace RefreshCode;
63  const wxMouseEvent &event = evt.event;
64 
65  if (!(event.ShiftDown() || event.CmdDown()))
66  return RefreshNone;
67 
68  // Always stop propagation even if the ruler didn't change. The ruler
69  // is a narrow enough target.
70  evt.event.Skip(false);
71 
72  auto steps = evt.steps;
73 
74  using namespace WaveTrackViewConstants;
75  if (event.CmdDown() && !event.ShiftDown()) {
76  const int yy = event.m_y;
78  pProject, wt,
79  (steps < 0)
80  ? kZoomOut
81  : kZoomIn,
82  evt.rect, yy, yy, true);
83  }
84  else if (!event.CmdDown() && event.ShiftDown()) {
85  // Scroll some fixed number of pixels, independent of zoom level or track height:
86  static const float movement = 10.0f;
87  const int height = evt.rect.GetHeight();
88  {
89  const float delta = steps * movement / height;
91  const bool isLinear = settings.scaleType == SpectrogramSettings::stLinear;
92  float bottom, top;
93  wt->GetSpectrumBounds(&bottom, &top);
94  const double rate = wt->GetRate();
95  const float bound = rate / 2;
96  const NumberScale numberScale(settings.GetScale(bottom, top));
97  float newTop =
98  std::min(bound, numberScale.PositionToValue(1.0f + delta));
99  const float newBottom =
100  std::max((isLinear ? 0.0f : 1.0f),
101  numberScale.PositionToValue(numberScale.ValueToPosition(newTop) - 1.0f));
102  newTop =
103  std::min(bound,
104  numberScale.PositionToValue(numberScale.ValueToPosition(newBottom) + 1.0f));
105 
106  for (auto channel : TrackList::Channels(wt))
107  channel->SetSpectrumBounds(newBottom, newTop);
108  }
109  }
110  else
111  return RefreshNone;
112 
113  ProjectHistory::Get( *pProject ).ModifyState(true);
114 
115  return RefreshCell | UpdateVRuler;
116 }

References TrackList::Channels(), SpectrumVZoomHandle::DoZoom(), TrackPanelMouseEvent::event, ProjectHistory::Get(), WaveTrack::GetIndependentSpectrogramSettings(), WaveTrack::GetRate(), WaveTrack::GetSpectrumBounds(), WaveTrackViewConstants::kZoomIn, WaveTrackViewConstants::kZoomOut, min(), ProjectHistory::ModifyState(), NumberScale::PositionToValue(), TrackPanelMouseEvent::rect, RefreshCode::RefreshCell, RefreshCode::RefreshNone, 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 134 of file SpectrumVRulerControls.cpp.

136 {
137  auto vruler = &WaveTrackVRulerControls::ScratchRuler();
139  float minFreq, maxFreq;
140  wt->GetSpectrumBounds(&minFreq, &maxFreq);
141  vruler->SetDbMirrorValue( 0.0 );
142 
143  switch (settings.scaleType) {
144  default:
145  wxASSERT(false);
147  {
148  // Spectrum
149 
150  /*
151  draw the ruler
152  we will use Hz if maxFreq is < 2000, otherwise we represent kHz,
153  and append to the numbers a "k"
154  */
155  vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
156  vruler->SetOrientation(wxVERTICAL);
157  vruler->SetFormat(Ruler::RealFormat);
158  vruler->SetLabelEdges(true);
159  // use kHz in scale, if appropriate
160  if (maxFreq >= 2000) {
161  vruler->SetRange((maxFreq / 1000.), (minFreq / 1000.));
162  /* i18n-hint k abbreviating kilo meaning thousands */
163  vruler->SetUnits(XO("k"));
164  }
165  else {
166  // use Hz
167  vruler->SetRange((int)(maxFreq), (int)(minFreq));
168  vruler->SetUnits({});
169  }
170  vruler->SetLog(false);
171  }
172  break;
178  {
179  // SpectrumLog
180 
181  /*
182  draw the ruler
183  we will use Hz if maxFreq is < 2000, otherwise we represent kHz,
184  and append to the numbers a "k"
185  */
186  vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
187  vruler->SetOrientation(wxVERTICAL);
188  vruler->SetFormat(Ruler::IntFormat);
189  vruler->SetLabelEdges(true);
190  vruler->SetRange(maxFreq, minFreq);
191  vruler->SetUnits({});
192  vruler->SetLog(true);
193  NumberScale scale(
194  wt->GetSpectrogramSettings().GetScale( minFreq, maxFreq )
195  .Reversal() );
196  vruler->SetNumberScale(scale);
197  }
198  break;
199  }
200  vruler->GetMaxSize( &wt->vrulerSize.x, &wt->vrulerSize.y );
201 }

References SpectrogramSettings::GetScale(), WaveTrack::GetSpectrogramSettings(), WaveTrack::GetSpectrumBounds(), Ruler::IntFormat, Ruler::RealFormat, NumberScale::Reversal(), WaveTrackVRulerControls::ScratchRuler(), settings(), SpectrogramSettings::stBark, SpectrogramSettings::stErb, SpectrogramSettings::stLinear, SpectrogramSettings::stLogarithmic, SpectrogramSettings::stMel, SpectrogramSettings::stPeriod, Track::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 118 of file SpectrumVRulerControls.cpp.

121 {
122  TrackVRulerControls::Draw( context, rect_, iPass );
123  WaveTrackVRulerControls::DoDraw( *this, context, rect_, iPass );
124 }

References WaveTrackVRulerControls::DoDraw(), and TrackVRulerControls::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 48 of file SpectrumVRulerControls.cpp.

50 {
51  using namespace RefreshCode;
52  const auto pTrack = FindTrack();
53  if (!pTrack)
54  return RefreshNone;
55  const auto wt = static_cast<WaveTrack*>(pTrack.get());
56  return DoHandleWheelRotation( evt, pProject, wt );
57 }

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 26 of file SpectrumVRulerControls.cpp.

29 {
30  std::vector<UIHandlePtr> results;
31 
32  if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
33  auto pTrack = FindTrack()->SharedPointer<WaveTrack>( );
34  if (pTrack) {
35  auto result = std::make_shared<SpectrumVZoomHandle>(
36  pTrack, st.rect, st.state.m_y );
37  result = AssignUIHandlePtr(mVZoomHandle, result);
38  results.push_back(result);
39  }
40  }
41 
42  auto more = TrackVRulerControls::HitTest(st, pProject);
43  std::copy(more.begin(), more.end(), std::back_inserter(results));
44 
45  return results;
46 }

References AssignUIHandlePtr(), CommonTrackPanelCell::FindTrack(), TrackVRulerControls::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 TrackVRulerControls.

Definition at line 126 of file SpectrumVRulerControls.cpp.

127 {
128  const auto wt = std::static_pointer_cast< WaveTrack >( FindTrack() );
129  if (!wt)
130  return;
131  DoUpdateVRuler( rect, wt.get() );
132 }

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:
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
SpectrogramSettings
Spectrogram settings, either for one track or as defaults.
Definition: SpectrogramSettings.h:27
SpectrogramSettings::stErb
@ stErb
Definition: SpectrogramSettings.h:63
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
TrackPanelMouseEvent::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:59
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
TrackVRulerControls::TrackVRulerControls
TrackVRulerControls(const std::shared_ptr< TrackView > &pTrackView)
Definition: TrackVRulerControls.cpp:26
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
WaveTrackViewConstants
Definition: WaveTrackView.h:17
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
SpectrogramSettings::stMel
@ stMel
Definition: SpectrogramSettings.h:61
SpectrumVRulerControls::DoUpdateVRuler
static void DoUpdateVRuler(const wxRect &rect, const WaveTrack *wt)
Definition: SpectrumVRulerControls.cpp:134
SpectrumVRulerControls::DoHandleWheelRotation
static unsigned DoHandleWheelRotation(const TrackPanelMouseEvent &evt, AudacityProject *pProject, WaveTrack *wt)
Definition: SpectrumVRulerControls.cpp:59
XO
#define XO(s)
Definition: Internat.h:31
Ruler::RealFormat
@ RealFormat
Definition: Ruler.h:31
WaveTrack::GetSpectrogramSettings
const SpectrogramSettings & GetSpectrogramSettings() const
Definition: WaveTrack.cpp:763
SpectrogramSettings::stBark
@ stBark
Definition: SpectrogramSettings.h:62
SpectrogramSettings::GetScale
NumberScale GetScale(float minFreq, float maxFreq) const
Definition: SpectrogramSettings.cpp:622
WaveTrack::GetIndependentSpectrogramSettings
SpectrogramSettings & GetIndependentSpectrogramSettings()
Definition: WaveTrack.cpp:779
WaveTrackVRulerControls::DoDraw
AUDACITY_DLL_API void DoDraw(TrackVRulerControls &controls, TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
Definition: WaveTrackVRulerControls.cpp:32
WaveTrack::GetSpectrumBounds
void GetSpectrumBounds(float *min, float *max) const
Definition: WaveTrack.cpp:332
RefreshCode::UpdateVRuler
@ UpdateVRuler
Definition: RefreshCode.h:30
Ruler::IntFormat
@ IntFormat
Definition: Ruler.h:30
WaveTrackViewConstants::kZoomIn
@ kZoomIn
Definition: WaveTrackViewConstants.h:77
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
kGuard
const int kGuard
Definition: TrackVRulerControls.h:20
NumberScale::Reversal
NumberScale Reversal() const
Definition: NumberScale.h:83
TrackVRulerControls::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Definition: TrackVRulerControls.cpp:55
SpectrogramSettings::stLinear
@ stLinear
Definition: SpectrogramSettings.h:59
SpectrogramSettings::stLogarithmic
@ stLogarithmic
Definition: SpectrogramSettings.h:60
SpectrumVZoomHandle::DoZoom
static void DoZoom(AudacityProject *pProject, WaveTrack *pTrack, WaveTrackViewConstants::ZoomActions ZoomKind, const wxRect &rect, int zoomStart, int zoomEnd, bool fixedMousePoint)
Definition: SpectrumVZoomHandle.cpp:105
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
WaveTrackVRulerControls::ScratchRuler
AUDACITY_DLL_API Ruler & ScratchRuler()
Definition: WaveTrackVRulerControls.cpp:26
TrackVRulerControls::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: TrackVRulerControls.cpp:97
WaveTrackViewConstants::kZoomOut
@ kZoomOut
Definition: WaveTrackViewConstants.h:78
NumberScale
Definition: NumberScale.h:31
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
SpectrumVRulerControls::mVZoomHandle
std::weak_ptr< SpectrumVZoomHandle > mVZoomHandle
Definition: SpectrumVRulerControls.h:52
settings
static Settings & settings()
Definition: TrackInfo.cpp:86
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
SpectrogramSettings::stPeriod
@ stPeriod
Definition: SpectrogramSettings.h:64
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
TrackPanelMouseEvent::steps
double steps
Definition: TrackPanelMouseEvent.h:62
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
WaveTrack::GetRate
double GetRate() const
Definition: WaveTrack.cpp:457
Track::vrulerSize
wxSize vrulerSize
Definition: Track.h:354