From 425f936336e669555a0806b321cb90ea569e18c3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 16 Apr 2021 01:10:36 +0200 Subject: Only snap the crosshair to visible plots. --- src/wx/audio_plot.cc | 37 ++++++++++++++++++++----------------- src/wx/audio_plot.h | 3 ++- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index 7c9dae6a5..4e4b6d6a0 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -439,21 +439,6 @@ AudioPlot::colour (int n) const } -void -AudioPlot::search (map const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const -{ - for (auto const& i: search) { - for (auto const& j: i.second) { - double const dist = pow(ev.GetX() - j.draw.x, 2) + pow(ev.GetY() - j.draw.y, 2); - if (dist < min_dist) { - min_dist = dist; - min_point = j; - } - } - } -} - - void AudioPlot::left_down () { @@ -471,8 +456,26 @@ AudioPlot::mouse_moved (wxMouseEvent& ev) double min_dist = DBL_MAX; Point min_point; - search (_rms, ev, min_dist, min_point); - search (_peak, ev, min_dist, min_point); + auto search = [this](map const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) { + for (auto const& i: search) { + if (_channel_visible[i.first]) { + for (auto const& j: i.second) { + double const dist = pow(ev.GetX() - j.draw.x, 2) + pow(ev.GetY() - j.draw.y, 2); + if (dist < min_dist) { + min_dist = dist; + min_point = j; + } + } + } + } + }; + + if (_type_visible[AudioPoint::RMS]) { + search (_rms, ev, min_dist, min_point); + } + if (_type_visible[AudioPoint::PEAK]) { + search (_peak, ev, min_dist, min_point); + } _cursor = {}; diff --git a/src/wx/audio_plot.h b/src/wx/audio_plot.h index 27d76b6db..9edabf8ec 100644 --- a/src/wx/audio_plot.h +++ b/src/wx/audio_plot.h @@ -76,7 +76,6 @@ private: void left_down (); void mouse_moved (wxMouseEvent& ev); void mouse_leave (wxMouseEvent& ev); - void search (std::map const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const; std::weak_ptr _viewer; std::shared_ptr _analysis; @@ -87,7 +86,9 @@ private: wxString _message; float _gain_correction; + /** peak values keyed by channel */ mutable std::map _peak; + /** RMS values keyed by channel */ mutable std::map _rms; boost::optional _cursor; -- cgit v1.2.3