Only snap the crosshair to visible plots.
authorCarl Hetherington <cth@carlh.net>
Thu, 15 Apr 2021 23:10:36 +0000 (01:10 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 20 Apr 2021 22:52:07 +0000 (00:52 +0200)
src/wx/audio_plot.cc
src/wx/audio_plot.h

index 7c9dae6a557c9061ea7fa1006af3a088b6679aaa..4e4b6d6a003810d59f353969d2048214917a6284 100644 (file)
@@ -439,21 +439,6 @@ AudioPlot::colour (int n) const
 }
 
 
-void
-AudioPlot::search (map<int, PointList> 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<int, PointList> 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 = {};
 
index 27d76b6db3ce1fb235a5df7b1253e41b5d7583e3..9edabf8ec70b5cc605bfd932c07fb2b1e9083db0 100644 (file)
@@ -76,7 +76,6 @@ private:
        void left_down ();
        void mouse_moved (wxMouseEvent& ev);
        void mouse_leave (wxMouseEvent& ev);
-       void search (std::map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const;
 
        std::weak_ptr<FilmViewer> _viewer;
        std::shared_ptr<AudioAnalysis> _analysis;
@@ -87,7 +86,9 @@ private:
        wxString _message;
        float _gain_correction;
 
+       /** peak values keyed by channel */
        mutable std::map<int, PointList> _peak;
+       /** RMS values keyed by channel */
        mutable std::map<int, PointList> _rms;
 
        boost::optional<Point> _cursor;